Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Requirements

This solutions are implemented in python 2.7 with the following libraries

numpy, IPython, bfc(in this repo.)

...> sudo apt-get instal numpy ipython

# Some minor changes

hw2.py cant open class Binomial. so i added import line for this class.
Also, onePeriodPrice is not recognized well in hw2.py and in bfc/binomial.py, i declared explicitly in those files.
3 changes: 3 additions & 0 deletions bfc/binomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
---------------------

'''
import numpy as np
from pfv import * # onePeriodPrice
from math import exp, sqrt

class Binomial:
'''
Expand Down
10 changes: 6 additions & 4 deletions hw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
==========
'''
from bfc import *
from bfc.binomial import Binomial
from bfc.pfv import onePeriodPrice
import numpy as np

def calcAmericanCall(sel):
for i in range(sel.n,0,-1):
Expand All @@ -23,19 +26,19 @@ def calcAmericanCall(sel):

if __name__ == '__main__':
q = Binomial()

q.setFromBS(0.25,0.02,15,0.01,0.3,100,110,'american','call')
#print "Q1: option price: {0:4}".format(q.calcOptionPrice())

q2 = q
q2.type[1]='put'
print "Q2: option price: {0:4}".format(q2.calcOptionPrice())

q6 = q
q6.setFromBS(0.25,0.02,15,0.01,0.3,100,110,'american','call')
q6.n = 10
print "Q6: option price: {0:4}".format(calcAmericanCall(q6))

q8a = Binomial()
q8a.setFromBS(0.25,0.02,15,0.01,0.3,100,100,'european','call')
q8b = Binomial()
Expand All @@ -59,4 +62,3 @@ def calcAmericanCall(sel):
Cf = [onePeriodPrice(Cf[j],Cf[j+1],q8a.q,(q8a.R-1)) \
for j in range(0,i)]
print Cf