User Stories

Gas Natural Fenosa Predicts Energy Supply and Demand

View PDF

Union Fenosa User Story image
Portomouros hydroelectric dam.

“Because we need to rapidly respond to shifting production constraints and changing demands, we cannot depend on closed or proprietary solutions. With MathWorks tools we get more accurate results—and we have the flexibility to develop, update, and optimize our models in response to changing needs.”

Angel Caballero, Gas Natural Fenosa

Gas Natural Fenosa, the largest integrated gas and electricity company in Spain and Latin America, has an electric generation capacity totaling more than 13,000 megawatts. The company’s portfolio includes coal, combined-cycle gas, nuclear, wind, and renewable assets. To determine how best to sell electricity in the wholesale market, the company must accurately predict the next day’s prices and demand as well as the availability of electric power.

Gas Natural Fenosa uses MathWorks tools to develop optimization and forecasting models that incorporate historical usage patterns, weather forecasts, production costs, and other factors. They use the models to project capacity and demand and optimize their generation asset portfolios.

“Because we cannot store the electricity we produce, we must be prepared to sell it the next day,” says Angel Caballero, Forward Operations, Iberian Power Markets, at Gas Natural Fenosa. “The models that we have developed using MathWorks tools help us optimize our resources for production. They also enable us to predict periods of peak demand and increase our margins when the market is favorable.”


To put their generation capacity to good use and generate maximum profits, Gas Natural Fenosa needed to understand the factors behind electricity consumption and production. These factors include relative costs and capacity of generation assets; peak selling times for power; energy usage patterns; forecasts of temperature, wind, and rain; value of carbon credits; and transmission capacity on the grid. Determining how best to allocate demand involved solving a complex optimization problem that was beyond the capabilities of commercially available software. Furthermore, it was difficult to adapt commercially available models to changes in the regulatory and market environment of the Spanish power market.

“We must be able to respond quickly to changes in regulations, production capacity, and demand patterns,” says Caballero. “We tried using a commercial software package, but it could not provide the many answers we needed. In our situation, closed systems don’t work well. We needed an open development platform that we could use to develop our own algorithms and calculations.”


Gas Natural Fenosa engineers used MathWorks tools to develop models that predict demand, minimize production costs, and verify infrastructure capacity. The team used MATLAB® to develop a set of core models that analyze available data, forecast results, and optimize generation plans. Each MATLAB model accesses a central database for historical power consumption and price data, weather forecasts, and parameters for each power plant, including maximum power out, efficiency, costs, and all the operation constraints that influence the plant dispatch. The model processes the data using algorithms developed and fine-tuned by the market team. The results are written back to the database, where they are accessed by market traders or by another model for further processing.

To develop a wind farm model, Caballero used MATLAB to correlate historical wind-strength measurements with actual electrical wind production. Starting with a simple linear correlation, he improved the model using knowledge of the underlying technology.

The team used Optimization Toolbox™ to solve linear programming problems—for example, to minimize production costs among available production plants given a set of constraints, including carbon caps and maximum capacity. They used Statistics Toolbox™ to develop and evaluate price simulation scenarios and to produce value at risk (VaR) reports for management position. Using MATLAB Compiler™, the team created standalone programs for each model. These programs, which run automatically day and night, enable the development team to better manage updates and to control access to the models.

The team used Simulink® to model the behavior of generators in the company’s infrastructure.


  • Response time reduced by months. “The architecture allows for fast work putting into production new computer programs. Because our MATLAB model was designed to be flexible and scalable, we found it very easy to react to regulatory changes within one or two weeks,” says Caballero. “We would have to wait months for a supplier to commercialize a product with the new specifications.”
  • Productivity doubled. “Developing our models in a language like Visual Basic or C would be very difficult because these languages don’t have many of the features and functions we need,” Caballero notes. “To build models within our current development time frame without MATLAB, we would need double the staff.”
  • Program maintenance simplified. “With MATLAB, it is easy to maintain programs. We don’t waste time creating paper documents to explain what the models do,” says Caballero. “MATLAB code is easy to understand and practically self-documenting, so that a program developed by one person can be modified by another without difficulty.”


Maximize margins in energy trading by predicting available supply and peak demand


Use MathWorks tools to build and optimize models that incorporate historical data, weather forecasts, and regulatory rules


  • Response time reduced by months
  • Productivity doubled
  • Program maintenance simplified

Products Used

Learn more about Gas Natural Fenosa