From wikipedia: Monte Carlo methods are useful in many areas of computational mathematics, where a lucky choice can find the correct result. Interesting, huh !!
http://en.wikipedia.org/wiki/Monte_Carlo_methods_in_finance
All the formula in the code are taken from FE5102 notes, chapter 5 on Statistical Methods.
import random
import math
price = 33
exercise = 30
expiry = 6.0
vol = 9.0/100
rate = 5.0/100
simNum = 5000000
mean = math.log (price) + (rate - vol * vol / 2) * expiry / 12.0
stddev = math.sqrt(vol * vol * expiry / 12.0)
sum = 0
for i in range (simNum):
ft = math.exp(random.normalvariate(mean,stddev)) - exercise
if (ft <= 0): ft = 0 sum = sum + ft average = sum / simNum optionsPrice = average * math.exp(-rate*expiry/12.0) print "The options price based on " + str(simNum) + " observations is " + str(optionsPrice)
No comments:
Post a Comment