Barrier Option Pricing with Binomial Trees || Theory & Implementation in Python
Vložit
- čas přidán 20. 07. 2024
- In this video we look at pricing Barrier Options using the Binomial Asset Pricing Model and show how you can implement the barrier tree model to price an up-and-out barrier option in Python. There are two types of barrier options which we look at in this tutorial, up-and-out barrier options and down-and-out barrier options. Here we go through the theory and implementation.
For those who just want to code, please skip ahead to the Python Implementation section. I will take you through two implementations of a simple barrier tree model in Python, one that will use ‘for loops’ to step through each node at each time step (a function I have defined as binomial tree slow), and the other (binomial tree fast) will vectorize these steps using numpy arrays, improving overall computation time as N time steps increase. Although not necessary for the example today, using numpy arrays and vectorizing our calculations will improve computations as we delve deeper into financial mathematics and implementation heading forward.
In this tutorial series we will be breaking down the theory described and published in Steven Shreve’s book’s Stochastic Calculus for Finance I & II. As a guide for implementing these concepts in Python, we will refer to the numerical methods and practices outlined in Les Clewlow & Chris Strickland’s book Implementing Derivatives Models.
For any observant viewers, I calculated the variable 'disc' incorrectly in this video. I used up factor 'u' in the numerator instead of the correct value with is the down factor 'd'. Also, in the slow tree only during backward recursion the stock price should be calculated as S = S0 * u**j * d**(i-j) instead of S = S0 * u**j * d**(N-j). Code is correct on my website (link above).
00:00 Intro
00:17 Theory || What are Barrier Options?
02:25 Theory || European vs Barrier Option Payoff
04:42 Theory || Multi-period Binomial Model with Barrier Value H
08:08 Python Implementation || Barrier Tree Slow
18:50 Python Implementation || Barrier Tree Fast
25:26 Python Implementation || Comparing the Slow vs Fast Implementation
★ ★ Code Available on GitHub ★ ★
GitHub: github.com/TheQuantPy
Specific Tutorial Link: github.com/TheQuantPy/youtube...
★ ★ QuantPy GitHub ★ ★
Collection of resources used on QuantPy CZcams channel. github.com/thequantpy
★ ★ Discord Community ★ ★
Join a small niche community of like-minded quants on discord. / discord
★ ★ Support our Patreon Community ★ ★
Get access to Jupyter Notebooks that can run in the browser without downloading python.
/ quantpy
★ ★ ThetaData API ★ ★
ThetaData's API provides both realtime and historical options data for end-of-day, and intraday trades and quotes. Use coupon 'QPY1' to receive 20% off on your first month.
www.thetadata.net/
★ ★ Online Quant Tutorials ★ ★
WEBSITE: quantpy.com.au
★ ★ Contact Us ★ ★
EMAIL: pythonforquants@gmail.com
Disclaimer: All ideas, opinions, recommendations and/or forecasts, expressed or implied in this content, are for informational and educational purposes only and should not be construed as financial product advice or an inducement or instruction to invest, trade, and/or speculate in the markets. Any action or refraining from action; investments, trades, and/or speculations made in light of the ideas, opinions, and/or forecasts, expressed or implied in this content, are committed at your own risk an consequence, financial or otherwise. As an affiliate of ThetaData, QuantPy Pty Ltd is compensated for any purchases made through the link provided in this description.
During backward recursion through the tree shouldn't S = S0 * u**j * d**(i-j) instead of S = S0 * u**j * d**(N-j)
Yes it should be, nice pick up. Just a typo that went unnoticed on the video.
Fast implementation is ok. Code on website is updated with correct version.
I am doing the assignment related to pricing the barrier option using a binomial tree, explicit, and implicit methods. Your video is useful for me. I appreciated it. Many thanks.
As I student I thoroughly enjoy your vids mate
Thanks, if you have any recommendations for tutorials going forward, feel free to let me know
your video inspired me a lot, but could you please show how could we graph the result?
thank you a lot
you are amazing
Great video thx! And i wonder if you can make a video about discrete dividends on binomial models.
Definitely can
@@QuantPy Very appreciated! Coz your video is soooo good, helped me a lot👍
I have just started with Python and need to value some options. I copied the code directly from the website, But I get an "Process Finished with exit code 0" and No output. I searched that this means there is no error in the code. However, can anyone suggest how to get the Output??
Recommend watching this czcams.com/video/nWslah9tHLk/video.html I believe you'll be using grossly incorrect parameters for binomial tree
just so i know this is not Barriers in python multi-threading right? I am in the wrong place?
Are you sure abount q = (exp(rt)-u)/(u-d)? Shouldn't it be (exp(rt)-d)/(u-d)?
Yes good pick-up, as I have mentioned in the description you are one of those observant viewers 👍
"For any observant viewers, I calculated the variable 'disc' incorrectly in this video. I used up factor 'u' in the numerator instead of the correct value with is the down factor 'd'. Also, in the slow tree only during backward recursion the stock price should be calculated as S = S0 * u**j * d**(i-j) instead of S = S0 * u**j * d**(N-j). Code is correct on my website (link above). "