-
Notifications
You must be signed in to change notification settings - Fork 2
/
Brownian.cpp
41 lines (30 loc) · 861 Bytes
/
Brownian.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
#include "Brownian.h"
using namespace std;
using namespace arma;
Brownian::Brownian(int dimension, double maturity, string s_correlation): m_dimension(dimension), m_maturity(maturity) {
m_correlation.load(s_correlation, raw_ascii);
}
vec Brownian::operator()() {
random_device rd;
mt19937 gen(rd());
normal_distribution<double> normal_density(0, m_maturity);
vec Z(m_dimension);
for(int i(0);i<m_dimension;i++) {
Z[i] = normal_density(gen); // N(0,I_d) gaussian vector
}
mat T(m_maturity*m_correlation); // From correlation matrix to covariance matrix
T = chol(T, "lower"); // Cholesky decomposition
return T*Z;
}
mat Brownian::opposite() {
mat B(m_dimension,2);
B.col(0) = operator()();
B.col(1) = -B.col(0);
return B;
}
int Brownian::getDimension() {
return m_dimension;
}
int Brownian::getMaturity() {
return m_maturity;
}