MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / main

Function main

examples/financial/heston_model.cpp:76–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76int main() {
77 float T = 1;
78 unsigned int nT = 10 * T;
79 unsigned int R_first_run = 1000;
80 unsigned int R = 20000000;
81
82 float x0 = 0; // initial log stock price
83 float v0 = pow(0.087, 2); // initial volatility
84 float r = log(1.0319); // risk-free rate
85 float rho = -0.82; // instantaneous correlation between Brownian motions
86 float sigmaV = 0.14; // variance of volatility
87 float kappa = 3.46; // mean reversion speed
88 float vBar = 0.008; // mean variance
89 float k = log(0.95); // strike price
90
91 // Price European call option
92 try {
93 af::array x;
94 af::array v;
95
96 // first run
97 simulateHestonModel(x, v, T, nT, R_first_run, r, kappa, vBar, sigmaV,
98 rho, x0, v0);
99 af::sync(); // Ensure the first run is finished
100
101 timer::start();
102 simulateHestonModel(x, v, T, nT, R, r, kappa, vBar, sigmaV, rho, x0,
103 v0);
104 af::sync();
105 cout << "Time in simulation: " << timer::stop() << endl;
106
107 af::array K = exp(constant(k, x.dims()));
108 af::array zeroConstant = constant(0, x.dims());
109 af::array C_CPU =
110 exp(-r * T) * mean(af::max(af::exp(x) - K, zeroConstant));
111
112 af_print(C_CPU);
113 return 0;
114 } catch (af::exception &e) {
115 fprintf(stderr, "%s\n", e.what());
116 return 1;
117 }
118}

Callers

nothing calls this directly

Calls 9

powFunction · 0.85
logFunction · 0.85
simulateHestonModelFunction · 0.85
expFunction · 0.85
constantFunction · 0.85
syncFunction · 0.50
meanFunction · 0.50
maxFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected