Last active
November 12, 2015 08:15
-
-
Save yuanmai/d2f121ace5ed6445f07a to your computer and use it in GitHub Desktop.
Option price monte carlo. You can cross validate the pricing on http://www.optioncombo.com/#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import exp | |
from random import gauss, shuffle | |
interest=.01 | |
vol=.15 | |
T = 1.0/365 | |
def moved(x, _): | |
return x * exp((interest-.5*vol**2)*T + vol*T**.5*gauss(0,1)) | |
St0=400.0 | |
DTE=30 | |
def end_price(price): | |
return reduce(moved, range(DTE), price) | |
put_strike=395.0 | |
trials=1000 | |
def pos(price): | |
return price > 0 | |
def shuffled(lst): | |
l = list(lst) | |
shuffle(l) | |
return l | |
def avg(lst): | |
return sum(lst)/len(lst) | |
paths = [end_price(St0) for x in range(trials)] | |
payoffs = [max(0, put_strike - price) for price in paths] | |
put_price = avg(payoffs) | |
pnls = [put_price-price for price in payoffs] | |
fpnls = pnls | |
pnls2 = shuffled(fpnls) | |
pnls3 = shuffled(fpnls) | |
pnls4 = shuffled(fpnls) | |
pnls5 = shuffled(fpnls) | |
all_pnls = [pnls2[i] + pnls3[i] for i in range(len(pnls2))] | |
print put_price | |
print sum(pnls) | |
print 'pop:', len(filter(pos, pnls))/float(len(pnls)) | |
print 'pop:', len(filter(pos, all_pnls))/float(len(all_pnls)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment