#!/bin/bash
cd /usr/lib/python2.5/idlelib/
python PyShell.py &
cd ~
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts
Tuesday, October 2, 2007
Python IDLE in Linux
A bash script to start Python IDLE in Linux :
Thursday, September 27, 2007
Options pricing based on Monte Carlo methods
Here is a python code to analyze options price based on Monte Carlo simulations.
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.
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)
Subscribe to:
Posts (Atom)