-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl.go
41 lines (36 loc) · 1.32 KB
/
impl.go
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
package main
import (
"math"
"math/rand"
"github.com/RyoAsano/stochastic_calculus/pkg/cplxquad"
"github.com/RyoAsano/stochastic_calculus/pkg/cplxquadexp"
"github.com/RyoAsano/stochastic_calculus/pkg/grd"
"github.com/RyoAsano/stochastic_calculus/pkg/mthd"
"github.com/RyoAsano/stochastic_calculus/pkg/point"
"github.com/RyoAsano/stochastic_calculus/pkg/randgen"
"github.com/RyoAsano/stochastic_calculus/pkg/stchprc"
)
func EulerMaruyamaQuadratic(r rand.Rand, T float64, N int, x float64, y float64) stchprc.Process {
grid := grd.NewEquiDistGrid(N, T)
normGen := randgen.NewNorm(r, 0, 1.0)
eulerMaruyama := mthd.NewEulerMaruyama()
// Applies Euler-Maruyama Method to Black Scholes SDE
quadraticSDE := cplxquad.NewSDE(grid, x, y, normGen)
return eulerMaruyama.Apply(quadraticSDE)
}
func EulerMaruyamaQuadraticImproved(r rand.Rand, T float64, N int, x float64, y float64) stchprc.Process {
grid := grd.NewEquiDistGrid(N, T)
normGen := randgen.NewNorm(r, 0, 1.0)
eulerMaruyama := mthd.NewEulerMaruyama()
// Applies Euler-Maruyama Method to Black Scholes SDE
quadraticSDE := cplxquadexp.NewSDE(grid, x, normGen)
expEulerMaruyama := mthd.Inject(
eulerMaruyama,
func(p point.Point) point.Point {
X, _ := p.Pr(1)
Y, _ := p.Pr(2)
return point.New(X, y*math.Exp(Y))
},
)
return expEulerMaruyama.Apply(quadraticSDE)
}