#include <stdio.h>
#include <iostream>
using namespace std;
unsigned int N, unsigned int R, float mu, float kappa,
float vBar, float sigmaV, float rho, float x0,
float v0) {
float deltaT = T / (float)(N - 1);
float sqrtDeltaT = sqrt(deltaT);
float sqrtOneMinusRhoSquare = sqrt(1 - rho * rho);
float mArray[] = {rho, sqrtOneMinusRhoSquare};
unsigned int tPrevious = 0, tCurrent = 0;
for (unsigned int t = 1; t < N; t++) {
tPrevious = (t + 1) % 2;
tCurrent = t % 2;
x[tCurrent] = x[tPrevious] + (mu - 0.5 * v[tPrevious]) * deltaT +
(sqrtVLag * dBt(span, 0));
af::array vTmp = v[tPrevious] + kappa * (vBar - v[tPrevious]) * deltaT +
sigmaV * (sqrtVLag * matmul(dBt, m));
v[tCurrent] = max(vTmp, zeroConstant);
}
xres = x[tCurrent];
vres = v[tCurrent];
}
int main() {
float T = 1;
unsigned int nT = 10 * T;
unsigned int R_first_run = 1000;
unsigned int R = 20000000;
float x0 = 0;
float v0 = pow(0.087, 2);
float r = log(1.0319);
float rho = -0.82;
float sigmaV = 0.14;
float kappa = 3.46;
float vBar = 0.008;
float k = log(0.95);
try {
simulateHestonModel(x, v, T, nT, R_first_run, r, kappa, vBar, sigmaV,
rho, x0, v0);
timer::start();
simulateHestonModel(x, v, T, nT, R, r, kappa, vBar, sigmaV, rho, x0,
v0);
cout << "Time in simulation: " << timer::stop() << endl;
return 0;
fprintf(stderr,
"%s\n", e.
what());
return 1;
}
}
A multi dimensional data container.
dim4 dims() const
Get dimensions of the array.
An ArrayFire exception class.
virtual const char * what() const
Returns an error message for the exception in a string format.
AFAPI array exp(const array &in)
C++ Interface to evaluate the exponential.
AFAPI array sqrt(const array &in)
C++ Interface to evaluate the square root.
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
C++ Interface to generate an array with elements set to a specified value.
AFAPI void sync(const int device=-1)
Blocks until the device is finished processing.
AFAPI array max(const array &in, const int dim=-1)
C++ Interface to return the maximum along a given dimension.