-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdm.h
53 lines (42 loc) · 1010 Bytes
/
fdm.h
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
/*
module to model finite difference methods
*/
#ifndef FDM_H
#define FDM_H
#include<functional>
#include<memory>
#include<vector>
#include "rgn.h"
#include "sde.h"
#include "types.h"
template<typename T>
class FDM
{
using function_type = std::function<T (T, T)>;//how to avoid declaring this alias twice? to use param_type directly?
private:
function_type strat_;
public:
FDM(const function_type& s): strat_{s} {};
std::vector<T> generatePath(T s, int t){
std::vector<T> path{};
for(int i = 0; i < t; i++){
s += strat_(t, s);
path.push_back(s);
}
return path;
};
using param_type = function_type;
};
template<typename T>
class EulerFDM
{
private:
std::shared_ptr<SDE<T>> sde_;
std::shared_ptr<RNG<T>> rng_;
public:
EulerFDM(const std::shared_ptr<SDE<T>>& s, const std::shared_ptr<RNG<T>>& r): sde_{s}, rng_{r} {};
T operator () (T t, T s){
return sde_->drift(t, s) + sde_->diffusion(t, s) * (*rng_)();
}
};
#endif