-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME
149 lines (134 loc) · 3.91 KB
/
README
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
Finite Difference Methods
=========================
2010-05-17
Finite difference methods!
* implicit finite difference method
* explicit finite difference method
* Crank-Nicolson scheme
Written in R.
Log of `code.R'
---------------
$ R
R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> source('functions.R')
>
> ######################################################################
> ## European put ##
> ######################################################################
>
> s <- 10
> k <- 10
> r <- .04
> t <- .5
> sd <- .2
> dt <- .002
> dx <- c(sd*sqrt(dt), sd*sqrt(3*dt), sd*sqrt(4*dt))
> type <- 'put'; style <- 'european'
>
> ## Binomial or Black-Scholes-Merton for comparison
> if (type == 'put' && style == 'american') {
+ binom.american.put(s, k, r, t, sd, n=1e3)
+ } else
+ bsm.option(s, k, r, t, sd, type)
[1] 0.4646945
>
> ## Regular implementation.
> fde.log(s, k, r, t, sd, type=type, style=style)
[1] 0.4623372
> fdi.log(s, k, r, t, sd, type=type, style=style)
[1] 0.4642185
> fdcn.log(s, k, r, t, sd, type=type, style=style)
[1] 0.4621469
>
> ## Convergence demonstration.
> n <- round(t/dt)
> m <- round(6*sd*sqrt(t)/dx[1]) # dx = sd*sqrt(dt)
> fde.log(s, k, r, t, sd, n, m, type, style)
[1] -67.22841
> fdi.log(s, k, r, t, sd, n, m, type, style)
[1] 0.4642181
> fdcn.log(s, k, r, t, sd, n, m, type, style)
[1] 0.4623665
>
> m <- round(6*sd*sqrt(t)/dx[2]) # dx = sd*sqrt(3*dt)
> fde.log(s, k, r, t, sd, n, m, type, style)
[1] 0.4619982
> fdi.log(s, k, r, t, sd, n, m, type, style)
[1] 0.4637008
> fdcn.log(s, k, r, t, sd, n, m, type, style)
[1] 0.4616131
>
> m <- round(6*sd*sqrt(t)/dx[3]) # dx = sd*sqrt(4*dt)
> fde.log(s, k, r, t, sd, n, m, type, style)
[1] 0.4616075
> fdi.log(s, k, r, t, sd, n, m, type, style)
[1] 0.463417
> fdcn.log(s, k, r, t, sd, n, m, type, style)
[1] 0.4612192
>
>
> ######################################################################
> ## American put ##
> ######################################################################
>
> s <- 10
> k <- 10
> r <- .04
> t <- .5
> sd <- .2
> dt <- .002
> ds <- c(0.5, 1, 1.5)
> type <- 'put'; style <- 'american'
>
> ## Binomial or Black-Scholes-Merton for comparison
> if (type == 'put' && style == 'american') {
+ binom.american.put(s, k, r, t, sd, n=1e3)
+ } else
+ bsm.option(s, k, r, t, sd, type)
[1] 0.4827014
>
> ## Regular implementation.
> fde(s, k, r, t, sd, type=type, style=style)
[1] 0.4803301
> fdi(s, k, r, t, sd, type=type, style=style)
[1] 0.4798712
> fdcn(s, k, r, t, sd, type=type, style=style)
[1] 0.4822621
>
> ## Convergence demonstration.
> n <- round(t/dt)
> m <- round(2*s/ds[1]) # ds = 0.5
> fde(s, k, r, t, sd, n, m, type, style)
[1] 0.4733109
> fdi(s, k, r, t, sd, n, m, type, style)
[1] 0.4724533
> fdcn(s, k, r, t, sd, n, m, type, style)
[1] 0.480942
>
> m <- round(2*s/ds[2]) # ds = 1
> fde(s, k, r, t, sd, n, m, type, style)
[1] 0.4399607
> fdi(s, k, r, t, sd, n, m, type, style)
[1] 0.4390812
> fdcn(s, k, r, t, sd, n, m, type, style)
[1] 0.475788
>
> m <- round(2*s/ds[3]) # ds = 1.5
> fde(s, k, r, t, sd, n, m, type, style)
[1] 0.394225
> fdi(s, k, r, t, sd, n, m, type, style)
[1] 0.3933963
> fdcn(s, k, r, t, sd, n, m, type, style)
[1] 0.4684005