From 9903c9b31bcb442e0e250fe5f5642714737dd865 Mon Sep 17 00:00:00 2001 From: jhyoocoder Date: Fri, 18 Dec 2015 19:22:40 +0900 Subject: [PATCH 1/2] linked the undeclared functions and imported libraries --- bfc/binomial.py | 3 +++ hw2.py | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bfc/binomial.py b/bfc/binomial.py index b0ab209..a63c98a 100644 --- a/bfc/binomial.py +++ b/bfc/binomial.py @@ -5,6 +5,9 @@ --------------------- ''' +import numpy as np +from pfv import * # onePeriodPrice +from math import exp, sqrt class Binomial: ''' diff --git a/hw2.py b/hw2.py index e524081..1cd3c8a 100644 --- a/hw2.py +++ b/hw2.py @@ -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): @@ -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() @@ -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 - From f7c40206628830ce2dff7afcdaedbbf7ffdeeb3b Mon Sep 17 00:00:00 2001 From: jhyoocoder Date: Fri, 18 Dec 2015 19:26:12 +0900 Subject: [PATCH 2/2] Readme --- Readme.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Readme.md diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..5a14bd4 --- /dev/null +++ b/Readme.md @@ -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.