-
Notifications
You must be signed in to change notification settings - Fork 0
/
mediator.h
51 lines (43 loc) · 1000 Bytes
/
mediator.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
/*
Mediator to put together all modules
*/
#include<functional>
#include<random>
#include<iostream>
#include<vector>
#include<memory>
#include "source.h"
#include "rgn.h"
#include "sde.h"
#include "fdm.h"
#include "pricer.h"
#include "builder.h"
template<typename T>
class Mediator final{
private:
std::shared_ptr<FDM<T>> fdm_;
ModelData<T> model_;
CsvModelStream<T> source_;
public:
Mediator(const std::string& sourceFile): source_{sourceFile}
{
source_ >> model_;
fdm_ = build_fdm<T>(model_);
};
T priceNextOption(int number_of_paths)
{
source_ >> model_;
T S;
int t;
OptionType optionType;
std::tie(S, t, optionType) = std::get<2>(model_);
auto pricer = build_pricer(optionType, S);
T sum;
for(int i = 0; i < number_of_paths; i++){
std::vector<T> path = fdm_->generatePath(S, t);
sum+= (*pricer)(path);
}
return sum / number_of_paths;
};
bool eof() {return source_.getStream().eof();};
};