-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
92 lines (77 loc) · 1.92 KB
/
main.cpp
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
#define ARMA_NO_DEBUG
#define ARMA_ALLOW_FAKE_GCC
#include <armadillo>
#include <iostream>
#include "TimeSeries.hpp"
using namespace arma;
using namespace TimeSeries;
void markovExample();
void discretizeVARexample();
void discretizeStochasticVolVARexample();
int main()
{
// markovExample();
discretizeVARexample();
discretizeStochasticVolVARexample();
return 0;
}
/*
*
* Examples
*
*/
void markovExample()
{
cout << "Markov Example." << endl;
AR vol(0.0, 0.95, 0.005);
const MarkovChain mc(vol, 5, 3.0, true);
mc.print();
}
void discretizeVARexample()
{
cout << "Discretize VAR example. Results saved in myMCvar.h5" << endl;
// example 3d
vec icept = { 0.0, 0.25, 1.0 };
mat rho = { { 0.97, 0.0, 0.0 }, //
{ 0.0, 0.98, 0.0 }, //
{ 0.0, 0.0, 0.3 } };
mat sigma = { { 0.03 * 0.03, -0.0005, 0.0 }, //
{ -0.0005, 0.025 * 0.025, 0.0 }, //
{ 0.0, 0.0, 0.01 } };
// example 2d
/*
vec icept = { 0.0, 0.25 };
mat rho = {
{ 0.9, 0.0 }, //
{ 0.0, 0.8 } //
};
mat sigma = {
{ 0.03 * 0.03, -0.0005 }, //
{ -0.0005, 0.02 * 0.02 } //
};
*/
VAR myVarN(icept, rho, sigma);
if (!myVarN.stationaryQ()) {
cout << "Provided VAR is not stationary. Stopping." << endl;
return;
}
uvec gridSizes = { 15, 15, 15 };
DiscreteVAR myMCvar(myVarN, gridSizes, true, OrthoMethod::Cholesky);
myMCvar.save("myMCvar.h5");
}
void discretizeStochasticVolVARexample()
{
cout << "Discretize stochatic VAR example. Results saved in stochVol.h5"
<< endl;
AR vol(0.0, 0.9, 0.05);
vec icept = { 0.0, 0.0 };
mat rho = { { 0.9, 0.0 }, //
{ 0.0, 0.9 } };
mat sigma = { { 0.015 * 0.015, -0.3 * 0.015 * 0.015 }, //
{ -0.3 * 0.015 * 0.015, 0.015 * 0.015 } };
VAR atMeanVolVAR(icept, rho, sigma);
uvec gridSizes = { 15, 15 };
uword volGridSize = 15;
DiscreteStochVolVAR volVAR(atMeanVolVAR, vol, gridSizes, volGridSize, true);
volVAR.save("stochVol.h5");
}