Giter VIP home page Giter VIP logo

jcfrei / heston Goto Github PK

View Code? Open in Web Editor NEW
32.0 5.0 17.0 96 KB

Option pricing function for the Heston model based on the implementation by Christian Kahl, Peter Jäckel and Roger Lord. Includes Black-Scholes-Merton option pricing and implied volatility estimation. No Financial Toolbox required.

License: MIT License

MATLAB 100.00%
heston heston-model option-pricing optimi calibration stochastic-volatility-models

heston's Introduction

Heston Option Pricing Calibration

Heston1993KahlJaeckelLordRev3 is the Heston option pricing function based on the implementation by Christian Kahl, Peter Jäckel and Roger Lord. The standard Heston formula exhibits a high numerical instability of the integral which is remedied in this implementation.

This function works for plain vanilla (European-style) put and call options and also implements an automatic estimation of the optimal alpha required for the integrand. A user generated alpha can also be used as an optional last argument.

Included are also a Black-Scholes-Merton (BSM) function (bsmec.m) to price European vanilla options and bsmivec.m for calculating the BSM implied volatilites - in case the Financial Toolbox is not available.

References

  • Roger Lord, Christian Kahl. Optimal Fourier inversion in semi-analytical option pricing. 2007
  • Roger Lord, Christian Kahl. Why the Rotation Count Algorithm Works. 2006
  • Christian Kahl, Peter Jäckl. Not-so-complex logarithms in the Heston model. 2009
  • Steven L. Heston. A Closed-Form Solution for Options with Stochastic Volatility with Applications to Bond and Currency Options. 1993

Usage

Run HestonCalibration.m to perform a sample calibration.

Usage of Heston1993KahlJaeckelLordRev3:

Input: (PC till q can be vectorized)

  •  PC: 1 for Calls, 2 for Puts
    
  •  S: Spot
    
  •  K: Strike
    
  •  T: Maturity
    
  •  t: start date
    
  •  r: interest rate
    
  •  q: dividend
    
  •  v0: initial variance
    
  •  theta: long run mean variance
    
  •  kappa: mean reversion speed of  volatility
    
  •  sigma: volatility of volatility
    
  •  rho: correlation between returns volatility
    
  •  (alpha:) vector of alphas. if unset function generates alphas
    

    Output:

  •  Price for each option
    
  •  (Alphas)
    

Tips

Smaller upper boundaries of [100 100 1-eps 100 100 ] instead of [Inf Inf 1-eps Inf Inf ] and trying different starting parameters might help if the calibration gets stuck in a local minimum.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

30/04/2016: added the bsmec.m and bsmivec.m functions

License

MIT

heston's People

Contributors

jcfrei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

heston's Issues

verification of fwd vol skew

Greetings Jonathan -

I have been testing your function a little more and I wanted to verify with you that I am seeing the correct behavior. Please let me know if I am seeing the correct behavior. I pulled the Options Data for US Equity ticker XOM. I setup a calibration and arrived at the following:

Current Variance: +0.071
Theta: +0.066
Rho: -0.999
Kappa: +5.382
Sigma: +0.500

I then priced a selection of strikes assuming Maturity of .5 Years. After pricing, I backed out the Black Scholes Implied. This is a picture verifying my results. I think it looks correct. (Rho is nearly -1).

current_implied

After this I tried to run another test. I simulated a set of log-normal fwd prices .25 years away. I assumed in each Price Scenario, 2500 of them using Monte Carlo, that I buy the current ATM strike. In this case the price is currently 82.80, so the Strike in each case is 83. For each Fwd Price, I used your model to back out the Option Price. Again, I backed out the implied volatility. I show the graph below:

forward_implied

However on this graph, I want to verify what may be correct- but feels counter-intuitive: here we are seeing forward implied volatility which is lower for forward spot prices. Is this correct? This runs counter to my expectation. I tried to rationalize why this would be and decided to post here to get your feedback. Please let me know your thoughts.

alphas are ending up as not-a-number

with certain option montages, the calculated value for the alphas is ending up NaN. this in turn is causing strange optimization behavior. most of the time the optimizer does not crash, however the warnings are continuously presented. on occasion the calibration routine halts completely. i have attempted a numerical analysis on the data but have had no luck so far.

the following code + workspace zip file will replicate the warning:

xoptP = lsqnonlin(@(x) Heston1993KahlJaeckelLordRev3(PC+1, S,K,T,t,r,q,x(1),x(2),x(3),x(4),x(5)) - MarketPrice(:,2),...
startparameters, ... %start values
... % v0,theta,rho,kappa,sigma
[ eps eps -1+eps eps eps ], ... % lower bound for parameter vector
[ 100 100 +1-eps 100 100 ], ... % upper bound for parameter vector
options);

optimizer status:

                                     Norm of      First-order 

Iteration Func-count f(x) step optimality
0 6 836.793 1.1e+05
1 12 183.198 0.0511948 3.27e+04
2 18 19.5157 0.0481355 3.69e+03
3 24 13.8879 0.218201 2.43e+03
4 30 13.8879 0.418154 2.43e+03
5 36 8.22993 0.104539 434
6 42 4.2232 0.209077 124
7 48 1.37073 0.311223 53.4
8 54 0.827855 0.3201 41
9 60 0.53483 0.268784 27
10 66 0.278322 0.255432 10.2
Exiting fzero: aborting search for an interval containing a sign change
because NaN or Inf function value encountered during search.
(Function value at 1.71 is -Inf.)
Check function or try again with a different starting value.
349 warning(message('MATLAB:integral:NonFiniteValue'));

alpha_warnings.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.