File Exchange

image thumbnail

Natural Gas Storage Valuation

version (2.16 MB) by Ameya Deoras
Demos and files from the webinar


Updated 01 Sep 2016

View Version History

View License

This example demonstrates using MATLAB to analyze and value a natural gas storage contract. Such valuations are typically done when financing/purchasing storage facilities, structuring contracts to lease storage facilities or marking to market the value of these assets. In this example, we implement some of the most common approaches including Intrinsic Valuation, Spread-Option Valuation & Rolling Intrinsic Valuation. To view the webinar, please visit
The example demonstrates the complete MATLAB modeling workflow from accessing data, building analytics and sharing results as reports and an Excel deployed application.
Highlights include:
* Realistic storage constraints including ratchets on injection/withdrawal limits
* Linear & integer linear programming
* Downloading & processing data from Quandl using tables
* Spread option pricing
* Monte Carlo simulation of multi-factor forward models calibrated to historical futures and option data with PCA
* 3-D & heatmap visualizations
* Rolling position viewer app

For more information on gas storage valuation, see the included PDF document.

Cite As

Ameya Deoras (2021). Natural Gas Storage Valuation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (17)

Fabio Colaiacomo


when I run Script4_RollingValuation.m I find these errors:

"Performing rolling intrinsic valuation path 1 of 100
Error using linprog (line 199)
Invalid choice of Algorithm for LINPROG. Choose 'interior-point', 'dual-simplex' or 'interior-point-legacy'.

Error in optimizeStorage (line 104)
[optimPos, ~, exitflag] = linprog(f, A, b/scale, Aeq, beq/scale, lb/scale, ub/scale, [], options);

Error in optimizeRollingStorage (line 30)
[initPos, intrValue, exitflag] = optimizeStorage(facility, bid(1,:), ask(1,:), contract, valuation);

Error in script4_RollingValuation (line 69)
[rollPos{i}, rollValue{i}] = optimizeRollingStorage(facility, bid,..."

Did anyone have the same error?
Could you help me fixing the code?

Thank You

Martti FDkdlj

used indian futures, close enough

quer = ['MCX/' future alpha(j) yrsa{i}]

Alexander Krogh


NaturalGas Forward Curve.xls is missing as well as the Fwd Curve mat can you send it to me?



sourabh kulkarni

I too changed and ran but somehow still getting error as Error using Quandl.api (line 46)
QECx02,You have submitted an incorrect Quandl code. Please check your Quandl codes and try again.

Nivas Donthireddy L

quer = ['CME/' future alpha(j) yrsa{i}]

I tried to change the Line 25 Yet it isnt downloading NGQuandl

Vasos Kosmidov

NaturalGas Forward Curve.xls is missing as well as the Fwd Curve mat can you include them please

Chet Sharma

Thanks Ray - I got in touch with Quandl and they suggested the same. I've modified the files and let Matlab know....they should be updating the zip folder here soon.


This file was written pointing to an older data source that has since been deprecated. Please change line 25 of downloadNGQuandl.m to

quer = ['CME/' future alpha(j) yrsa{i}]

Chet Sharma

@I Alvarez V - I'm getting the same error as you. Looks like something is wrong with the authenticateQuandl.txt file. Were you able to get this thing to run?

I. Alvarez V

The data are not accesible, in command window this message is appeared: "QECx06","API requests for OFDP has been deprecated. Do you have an altenative data?, please share.

Jiri Kracik

Pls, may i ask you about mathematical formulation of maximum withdrawal or injection constraints? I was not able to find it in the description :)

Sean Corbett

Anybody else not even able to get this model setup? Something wrong with Quandl interface?

Lu Liu

hi, I read through the description of the valuation model. It seems that you work on a gas storage facility that has 0 working gas volume and returned empty. Have you run your model on a storage facility that has non-zero working gas and be left with gas at the end of contract? How do you value the gas inventory at the beginning and gas left in storage in the end? especially from the PFE/cpty risk point of view?

eko Primabudi

I couldn't find the excel file 'NGFuturesPriceHistory.xlsx' in the zip files. Can someone help?

Romain Duverge


Can we upload the slides for the webinar as well?

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!