-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBinomialTreeEuropean.R
More file actions
57 lines (40 loc) · 934 Bytes
/
BinomialTreeEuropean.R
File metadata and controls
57 lines (40 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
rf=0.06
S0=12089
K=12200
T=50/365
nT=100
delT=T/nT
sig=0.15
u= exp(sig*sqrt(delT))
d = 1/u
p = (exp(rf*delT)-d)/(u-d)
#MATRIX
binaryMatrix = matrix(0,nrow=nT, ncol=nT)
binaryMatrix[1,1]=S0
for ( i in 2:nT){ # i columns
for (j in 1:i){ # j rows [r,c]
if(j==1 ){ binaryMatrix[1,i] = binaryMatrix[1,i-1]*u} # done
if((j>1)){
binaryMatrix[j,i] = binaryMatrix[j-1,i-1]*d
}
}
}
#spot prices
# back calculation
AssetMatrix = matrix(0,nrow=nT, ncol=nT)
#payoff
for ( i in 1:nT){
AssetMatrix[i,nT]= max(binaryMatrix[i,nT]-K,0)
}
for(i in (nT-1):1){ # i column
for(j in 1:i){ # j rows
AssetMatrix[j,i] = (AssetMatrix[j,i+1]*p +AssetMatrix[j+1,i+1]*(1-p))*exp(-rf*delT)
}
}
'
for(i in 1:nT-1){ # i column
for(j in 1:i){ # j rows
AssetMatrix[nT-j,nT-i] = AssetMatrix[nT-j,nT-i+1]*p +AssetMatrix[nT-j+1,nT-i+1]*(1-p)
}
}
'