Practical implementation of Option modelling with Python
Black-scholes first published their paper on option pricing way back in 1970 and little did they know that they would start a new branch of Finance which we know by name quantitative finance. Arguably black-scholes and binomial option modelling theory triggered the quant revolution . Merton and Scholes received the 1998 Nobel Prize in economic sciences for their seminal work. Option modelling has its applications in many areas in finance including valuation of derivatives, valuation of esops and recently option pricing is also increasingly used in valuation of start ups. In this article, i will explain how to code binomial option and blackscholes model in python from scratch.
An option can be modelled using either
a) Binomial model which assumes that the underlying security like stock or forward goes through abrupt shift or
b) Black-scholes model which assumes continuous time and the underlying follows GBM distribution.
First we would start with multi-period binomial model which is an approximation of Blackscholes-model. The binomial model gets converged to Blackscholes as the number of steps gets increase to a very large number or preferably infinity.
Full ipynb file can be downloaded from the following link: https://drive.google.com/file/d/1rSH1ih2eJaltgNpSdUBO38Wfl_i4mYnt/view?usp=sharing
and the option lattice is
British statistician George Box once famously quoted, "All model are wrong. Some models are useful". Just like any model, Blackscholes model also has its own set of assumptions and limitations. Thus, its important to know the assumptions and limitation of any model before putting it to use. Some of the key assumption of black scholes models are:
a) Underlying follows a statistical distribution called GBM (Geometric Brownian motion) which simply means that the underlying is continuous without any abrupt shifts
b) No arbitrage opportunity exists
c) Volatility of the underlying is constant
b) Borrowing and lending at risk free rate is possible at every instant at continuously compounded risk free rate.
Coding Blacksholes:
ipynb file for blackscholes code:
https://drive.google.com/file/d/1rSH1ih2eJaltgNpSdUBO38Wfl_i4mYnt/view?usp=sharing
Please feel free to leave comments if any below
Chief Risk Officer @Worldline,Expertise in Banking & Pay-Tech | Enterprise Risk Management |Compliance Risk | Risk Analytics | Credit Risk | Market Risk | Liquidity Risk | Operational Risk | Merchant Acquiring Risk
1 年Good work Manoj . Keep it up. I was modelling options in excel 25 years ago. You code in python takes me down the memory lane to my desk when as a passionate novice learner in financial market modeling. Extending the quant finance coding for more structured products where you can engineer cashflows as products will be interesting to attempt Again keep up the good work! and wish you the best.
Innovating SaaS with AI | Agile Product Leader | Turning Vision into Scalable Solutions
4 年Nice work Manoj!! 2 Observations: 1. The options you are covering are "US" style and we use "EU" style in India, you can add "EU" style to the code 2. You can use https://pypi.org/project/mibian/ to calculate everything automatically for all 3 models (BS, GK, MP) + you need not input interest rate if you are using Fut pricing (as Fut has interest rate accounted for) + you should calculate IV automatically instead of manual input as IV is not same for each option of same expiry We can discuss further on this, if needed as I won't be able to share my actual code here (since I'm using it for trading :P )
Senior Consultant at Infosys Consulting
4 年Just a thought, isnt the option chain and few of the websites already displaying the option prices the moment you key in the variables? I assume they are all based on Black-Sholes. Wanted to learn what advantage this peice of python code has over all of them. :)