#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 rho    = -0.82;  
    float sigmaV = 0.14;   
    float kappa  = 3.46;   
    float vBar   = 0.008;  
 
    
    try {
 
        
        simulateHestonModel(x, v, T, nT, R_first_run, r, kappa, vBar, sigmaV,
                            rho, x0, v0);
 
        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.
array exp(const array &in)
C++ Interface to evaluate the exponential.
array log(const array &in)
C++ Interface to evaluate the natural logarithm.
array pow(const array &base, const array &exponent)
C++ Interface to raise a base to a power (or exponent).
array sqrt(const array &in)
C++ Interface to evaluate the square root.
array matmul(const array &lhs, const array &rhs, const matProp optLhs=AF_MAT_NONE, const matProp optRhs=AF_MAT_NONE)
C++ Interface to multiply two matrices.
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.
void sync(const int device=-1)
Blocks until the device is finished processing.
array randn(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers normally distributed.
array max(const array &in, const int dim=-1)
C++ Interface to return the maximum along a given dimension.
array mean(const array &in, const dim_t dim=-1)
C++ Interface for mean.
seq span
A special value representing the entire axis of an af::array.