Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scipy
- import scipy.stats
- from scipy.stats import norm
- import math
- import random
- import statistics
- import codecs
- def monteCarlo():
- s = 600
- k = 650
- v = 0.25
- T = 1
- t = 1/52
- r = 0.04
- q = 0.04
- N = 1
- stockPrices = []
- callOptionPrices = []
- putOptionPrices = []
- def blackScholesCall():
- d1 = (math.log(s/k)+(r-q+(v*v)/2)*T)/(v*math.sqrt(T))
- d2 = d1 - v*math.sqrt(T)
- c = s*math.exp(-q*T)*norm.cdf(d1) - k*math.exp(-r*T)*norm.cdf(d2)
- return c
- def blackScholesPut():
- d1 = (math.log(s/k)+(r-q+(v*v)/2)*T)/(v*math.sqrt(T))
- d2 = d1 - v*math.sqrt(T)
- p = k*math.exp(-r*T)*norm.cdf(-d2) - s*math.exp(-q*T)*norm.cdf(-d1)
- return p
- def nextPrice(cP):
- p = cP*math.exp((r-q-(v*v)/2)*t+v*math.sqrt(t)* norm.ppf(random.random()))
- return p
- def callOptionPricePV(sP):
- p = math.exp(-r*T)*max(sP-k,0)
- return p
- def putOptionPricePV(sP):
- p = math.exp(-r*T)*max(k-sP,0)
- return p
- for j in range(0,N-1):
- for i in range(0,51):
- s = nextPrice(s)
- stockPrices.append(s)
- callOptionPrices.append(callOptionPricePV(s))
- putOptionPrices.append(putOptionPricePV(s))
- print("------Call option------")
- print("Black Scholes Pricing is: " + str(blackScholesCall()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement