Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import scipy
  2. import scipy.stats
  3. from scipy.stats import norm
  4. import math
  5. import random
  6. import statistics
  7. import codecs
  8.  
  9. def monteCarlo():
  10.     s = 600
  11.     k = 650
  12.     v = 0.25
  13.     T = 1
  14.     t = 1/52
  15.     r = 0.04
  16.     q = 0.04
  17.     N = 1
  18.  
  19.     stockPrices = []
  20.     callOptionPrices = []
  21.     putOptionPrices = []
  22.  
  23.     def blackScholesCall():
  24.         d1 = (math.log(s/k)+(r-q+(v*v)/2)*T)/(v*math.sqrt(T))
  25.         d2 = d1 - v*math.sqrt(T)
  26.         c = s*math.exp(-q*T)*norm.cdf(d1) - k*math.exp(-r*T)*norm.cdf(d2)
  27.         return c
  28.    
  29.     def blackScholesPut():
  30.         d1 = (math.log(s/k)+(r-q+(v*v)/2)*T)/(v*math.sqrt(T))
  31.         d2 = d1 - v*math.sqrt(T)
  32.         p = k*math.exp(-r*T)*norm.cdf(-d2) - s*math.exp(-q*T)*norm.cdf(-d1)
  33.         return p
  34.  
  35.     def nextPrice(cP):
  36.         p = cP*math.exp((r-q-(v*v)/2)*t+v*math.sqrt(t)* norm.ppf(random.random()))
  37.         return p
  38.  
  39.     def callOptionPricePV(sP):
  40.         p = math.exp(-r*T)*max(sP-k,0)
  41.         return p
  42.  
  43.     def putOptionPricePV(sP):
  44.         p = math.exp(-r*T)*max(k-sP,0)
  45.         return p
  46.    
  47.     for j in range(0,N-1):
  48.         for i in range(0,51):
  49.             s = nextPrice(s)
  50.            
  51.         stockPrices.append(s)
  52.         callOptionPrices.append(callOptionPricePV(s))
  53.         putOptionPrices.append(putOptionPricePV(s))
  54.    
  55.     print("------Call option------")
  56.     print("Black Scholes Pricing is: " + str(blackScholesCall()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement