{"id":3749,"date":"2020-08-09T06:34:05","date_gmt":"2020-08-09T06:34:05","guid":{"rendered":"https:\/\/www.aiproblog.com\/index.php\/2020\/08\/09\/pricing-options-using-monte-carlo-simulations\/"},"modified":"2020-08-09T06:34:05","modified_gmt":"2020-08-09T06:34:05","slug":"pricing-options-using-monte-carlo-simulations","status":"publish","type":"post","link":"https:\/\/www.aiproblog.com\/index.php\/2020\/08\/09\/pricing-options-using-monte-carlo-simulations\/","title":{"rendered":"Pricing Options Using Monte Carlo Simulations"},"content":{"rendered":"<p>Author: Kevin Mekulu<\/p>\n<div>\n<h1 id=\"69e3\" class=\"kp kq bj bi fo kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg fr\"><strong class=\"ay\">Summary<\/strong><\/h1>\n<ul class=\"\">\n<li id=\"6336\" class=\"lh li bj lj b hp lk ll hs lm ln lo lp hx lq lr ia ls lt id lu lv lw lx fr\">Monte Carlo simulation is one of the most important algorithms in quantitative finance<\/li>\n<li id=\"0e23\" class=\"lh li bj lj b hp ly ll hs lz ln lo ma hx lq mb ia ls mc id lu lv lw lx fr\">Monte Carlo simulation can be utilized as an alternative tool to price options ( the most popular option pricing model is based on the Black-Scholes-Merton formula)<\/li>\n<\/ul>\n<h1 id=\"98c9\" class=\"kp kq bj bi fo kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg fr\"><strong class=\"ay\">How Does Monte Carlo Simulation Work?<\/strong><\/h1>\n<p id=\"64ea\" class=\"lh li bj lj b hp lk ll hs lm ln lo lp hx lq lr ia ls lt id lu gp fr\">Before demonstrating the implementation of the Monte Carlo algorithm, it&rsquo;s important to fully comprehend the science behind it. Simply put, Monte Carlo simulation generates a series of random variables that have similar properties to the risk factors which the simulation is trying to simulate.<\/p>\n<p id=\"22fd\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">The simulation produces a large number of possible outcomes along with their probabilities. In summary, it&rsquo;s used to simulate realistic scenarios (stock prices, option prices, probabilities&hellip;).<\/p>\n<blockquote class=\"mi mj mk\">\n<p id=\"724f\" class=\"lh li ml lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">Note: Monte Carlo simulations can get computationally expensive and slow depending on the number of generated scenarios.<\/p>\n<\/blockquote>\n<p id=\"4f34\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">Next, I will demonstrate how we can leverage Monte Carlo simulation to price a European call option<span>&nbsp;<\/span>and implement its algorithm in Python.<\/p>\n<h1 id=\"1c22\" class=\"kp kq bj bi fo kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg fr\">Pricing a European Call Option Using Monte Carlo Simulation<\/h1>\n<p id=\"4030\" class=\"lh li bj lj b hp lk ll hs lm ln lo lp hx lq lr ia ls lt id lu gp fr\">Let&rsquo;s start by looking at the famous Black-Scholes-Merton formula (1973):<\/p>\n<p class=\"lh li bj lj b hp lk ll hs lm ln lo lp hx lq lr ia ls lt id lu gp fr\"><a href=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/7358081681?profile=original\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/7358081681?profile=RESIZE_710x\" class=\"align-center\"><\/a><\/p>\n<\/p>\n<div class=\"gj gk mm\">\n<div class=\"kb r cd fx\">\n<div class=\"mn kd r\"><\/div>\n<\/div>\n<\/div>\n<p style=\"text-align: center;\">Equation 3&ndash;1: Black-Scholes-Merton Stochastic Differential Equation (SDE)<\/p>\n<p id=\"5f5b\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\"><strong class=\"lj mo\">S(t) = Stock price at time<span>&nbsp;<\/span><em class=\"ml\">t<\/em><\/strong><\/p>\n<p id=\"aa95\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\"><strong class=\"lj mo\">r = Risk free rate<\/strong><\/p>\n<p id=\"7d5a\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\"><strong class=\"lj mo\">&sigma; = Volatility<\/strong><\/p>\n<p id=\"6eff\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\"><strong class=\"lj mo\">Z(t) = Brownian motion<\/strong><\/p>\n<p id=\"367f\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">Our goal is to solve the equation above to obtain an explicit formula for<span>&nbsp;<\/span><strong class=\"lj mo\">S(t).<\/strong><\/p>\n<p id=\"0fcc\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">We utilized Euler Discretization Scheme to solve the stochastic equation above. The solution is given by the expression:<\/p>\n<\/p>\n<div class=\"jv jw cd jx ai\">\n<div class=\"gj gk mp\">\n<div class=\"kb r cd fx\">\n<div class=\"mq kd r\">\n<div class=\"cc jy s t u ep ai bv jz ka\"><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"Image for post\" class=\"fc ug s t u ep ai c\" width=\"723\" height=\"110\" src=\"https:\/\/miro.medium.com\/max\/723\/1*c6NBbPOaH_5A9OOEf9FVCg.png\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"text-align: center;\">Equation 3&ndash;2: Euler Discretization of SDE<\/p>\n<p id=\"4626\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">Let&rsquo;s apply the logarithm function to equation 3&ndash;2 above which will allow a faster implementation in Python (the vectorization process using the numpy package in Python would easily ingest the log version of the solution above).<\/p>\n<\/p>\n<div class=\"jv jw cd jx ai\">\n<div class=\"gj gk mr\">\n<div class=\"kb r cd fx\">\n<div class=\"ms kd r\">\n<div class=\"cc jy s t u ep ai bv jz ka\"><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"Image for post\" class=\"fc ug s t u ep ai c\" width=\"701\" height=\"102\" src=\"https:\/\/miro.medium.com\/max\/701\/1*w-MNPrU0bM0pcy_lZaER4w.png\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"text-align: center;\">Equation 3&ndash;3: Euler Discretization of SDE (log version)<\/p>\n<h1 id=\"5758\" class=\"kp kq bj bi fo kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg fr\"><strong class=\"ay\">Monte Carlo Implementation in Python<\/strong><\/h1>\n<p id=\"901a\" class=\"lh li bj lj b hp lk ll hs lm ln lo lp hx lq lr ia ls lt id lu gp fr\">We will utilize the numpy package and its vectorization properties to make the program more compact, easier to read, maintain and faster to execute. The source code below is available <a href=\"https:\/\/gist.github.com\/JKEVIN2010\/442f527050d65d7ede7e8d9e1135dfd8#file-monte_carlo-py\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p>#<br \/> # Monte Carlo valuation of European call options with NumPy (log version)<br \/> # Monte_Carlo.py<br \/> #<br \/> import math<br \/> from numpy import *<br \/> from time import time<br \/> # star import for shorter code<br \/> random.seed(20000)<br \/> t0 = time()<br \/> # Parameters<br \/> S0 = 100.; K = 105.; T = 1.0; r = 0.05; sigma = 0.2<br \/> M = 50; dt = T \/ M; I = 250000<br \/> # Simulating I paths with M time steps<br \/> S = S0 * exp(cumsum((r &#8211; 0.5 * sigma ** 2) * dt<br \/> + sigma * math.sqrt(dt)<br \/> * random.standard_normal((M + 1, I)), axis=0))<br \/> # sum instead of cumsum would also do<br \/> # if only the final values are of interest<br \/> S[0] = S0<br \/> # Calculating the Monte Carlo estimator<br \/> C0 = math.exp(-r * T) * sum(maximum(S[-1] &#8211; K, 0)) \/ I<br \/> # Results output<br \/> tnp2 = time() &#8211; t0<\/p>\n<p>print(&#8216;The European Option Value is: &#8216;, C0) # The European Option Value is: 8.165807966259603<br \/> print(&#8216;The Execution Time is: &#8216;,tnp2) # The Execution Time is: 0.9024488925933838<\/p>\n<h1 id=\"6467\" class=\"kp kq bj bi fo kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg fr\">Graphical Visualization<\/h1>\n<p id=\"ea96\" class=\"lh li bj lj b hp lk ll hs lm ln lo lp hx lq lr ia ls lt id lu gp fr\">The graph below displays a plot of the first 10 simulated paths. Those simulated paths represent different outcomes for the price of the underlying asset (index level).<\/p>\n<pre class=\"jp jq jr js jt mu mv dp\"><span id=\"2cc4\" class=\"fr mw kq bj mx b cb my mz r na\">import matplotlib.pyplot as plt<br>plt.plot(S[:, :10])<br>\nplt.grid(True)<br>\nplt.xlabel('Steps')<br>\nplt.ylabel('Index level')<br>\nplt.show()<\/span><\/pre>\n<\/p>\n<div class=\"jv jw cd jx ai\">\n<div class=\"gj gk nb\">\n<div class=\"kb r cd fx\">\n<div class=\"nc kd r\">\n<div class=\"cc jy s t u ep ai bv jz ka\"><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"Image for post\" class=\"fc ug s t u ep ai c\" width=\"951\" height=\"474\" src=\"https:\/\/miro.medium.com\/max\/951\/1*nYWO8paEEYaOcHYTEZctuw.png\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"text-align: center;\">Figure 3&ndash;1: Simulated index levels by time steps<\/p>\n<p id=\"4ba9\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">Next, let&rsquo;s investigate the frequency of the simulated index levels at the end of the simulation period.<\/p>\n<pre class=\"jp jq jr js jt mu mv dp\"><span id=\"86b6\" class=\"fr mw kq bj mx b cb my mz r na\">plt.rcParams[\"figure.figsize\"] = (15,8)<br>plt.hist(S[-1], bins=50)<br>\nplt.grid(True)<br>\nplt.xlabel('index level')<br>\nplt.ylabel('frequency')<\/span><\/pre>\n<\/p>\n<div class=\"jv jw cd jx ai\">\n<div class=\"gj gk nd\">\n<div class=\"kb r cd fx\">\n<div class=\"ne kd r\">\n<div class=\"cc jy s t u ep ai bv jz ka\"><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"Image for post\" class=\"fc ug s t u ep ai c\" width=\"991\" height=\"488\" src=\"https:\/\/miro.medium.com\/max\/991\/1*ncOFi_zl_bz5FzOgrckcJA.png\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"text-align: center;\">Figure 3&ndash;2: Histogram of all simulated end-of-period index values<\/p>\n<p id=\"3aac\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">Next, let&rsquo;s look at the histogram of all simulated end-of-period option values.<\/p>\n<pre class=\"jp jq jr js jt mu mv dp\"><span id=\"a4d5\" class=\"fr mw kq bj mx b cb my mz r na\">import numpy as np<br>plt.rcParams[\"figure.figsize\"] = (15,8)<br>\nplt.hist(np.maximum(S[-1] - K, 0), bins=50)<br>\nplt.grid(True)<br>\nplt.xlabel('option inner value')<br>\nplt.ylabel('frequency')<br>\nplt.ylim(0, 50000)<\/span><\/pre>\n<\/p>\n<div class=\"jv jw cd jx ai\">\n<div class=\"gj gk nf\">\n<div class=\"kb r cd fx\">\n<div class=\"ng kd r\">\n<div class=\"cc jy s t u ep ai bv jz ka\"><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"Image for post\" class=\"fc ug s t u ep ai c\" width=\"1045\" height=\"486\" src=\"https:\/\/miro.medium.com\/max\/1045\/1*OFXGo2-w4g2x3bBMGj13Ug.png\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"text-align: center;\">Figure 3&ndash;3: Histogram of all simulated option values<\/p>\n<p id=\"2457\" class=\"lh li bj lj b hp md ll hs me ln lo mf hx lq mg ia ls mh id lu gp fr\">We notice something very interesting in the latter plot. The European call option expires worthless the majority of the time. This might be useful information for an astute options trader! But that&rsquo;s a discussion for another day.<\/p>\n<h1 id=\"938f\" class=\"kp kq bj bi fo kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg fr\">References<\/h1>\n<p id=\"54c0\" class=\"lh li bj lj b hp lk ll hs lm ln lo lp hx lq lr ia ls lt id lu gp fr\">Hilpisch, Y. (2015). Python for Finance: Analyze Big Financial Data<\/p>\n<p><em>Originally posted&nbsp;<a href=\"https:\/\/towardsdatascience.com\/option-pricing-using-monte-carlo-simulations-41d9e4ad95f6?source=friends_link&amp;sk=8fd2a29b2bf9599d21013767ad22fbec\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/em><\/p>\n<\/div>\n<p><a href=\"https:\/\/www.datasciencecentral.com\/xn\/detail\/6448529:BlogPost:976225\">Go to Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: Kevin Mekulu Summary Monte Carlo simulation is one of the most important algorithms in quantitative finance Monte Carlo simulation can be utilized as an [&hellip;] <span class=\"read-more-link\"><a class=\"read-more\" href=\"https:\/\/www.aiproblog.com\/index.php\/2020\/08\/09\/pricing-options-using-monte-carlo-simulations\/\">Read More<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":459,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/3749"}],"collection":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=3749"}],"version-history":[{"count":0,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/3749\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media\/462"}],"wp:attachment":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=3749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=3749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=3749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}