# Heston model - Andersen scheme implementation

I would like to implement Andersen scheme for Heston simulation. On the following snipped is my code for generating asset path:

double dt = option->T / static_cast<double>(size);

double k0, k1, k2, k3, k4, gamma1, gamma2;

gamma1 = 0.5;
gamma2 = 0.5;

k0 = -dt * (rho * kappa * theta) / (epsilon);
k1 = gamma1 * dt * (((kappa * rho) / epsilon) - 0.5) - (rho / epsilon);
k2 = gamma2 * dt * (((kappa * rho) / epsilon) - 0.5) + (rho / epsilon);
k3 = gamma1 * dt * (1 - pow(rho,2));
k4 = gamma2 * dt * (1 - pow(rho,2));

for (int i = 1; i < size; i++) {

double normalRandom = normalDist(generator);
spotPath[i] = spotPath[i - 1] * exp(option->r * dt + k0 + k1 * volPath[i - 1] + k2 * volPath[i] +
(sqrt(k3 * volPath[i - 1] + k4 * volPath[i]) * normalRandom));
}


Unfortunately, when I simulate this and compare to Euler scheme I got around 20% lower option value. I think that mistake is here (not in simulating volatility path), because when I make Euler scheme for asset and Andersen scheme for volatility, the option value is more less correct. Do you see any mistake in my code?

Edit: My Heston model: $$dS(t) = r S(t) dt + \sqrt{v(t)} S(t) dW^S(t)$$ $$dv(t) = \kappa (\theta - v(t))dt + \varepsilon \sqrt{v(t)} dW^v(t)$$ $$Cov[dW^S(t), dW^v(t)] = \rho dt$$

Andersen scheme (asset path): $$\hat{S}(t + \Delta) = \hat{S}(t) * exp(r \Delta + K_0 + K_1 \hat{v}(t) + K_2 \hat{v}(t+\Delta) + \sqrt{K_3 \hat{v}(t) + K_4 \hat{v}(t+\Delta)} \cdot Z)$$ where: $$K_0 = - \frac{\rho \kappa \theta}{\varepsilon} \Delta$$ $$K_1 = \gamma_1 \Delta \left( \frac{\kappa \rho}{\varepsilon} - \frac{1}{2} \right) - \frac{\rho}{\varepsilon}$$ $$K_2 = \gamma_2 \Delta \left( \frac{\kappa \rho}{\varepsilon} - \frac{1}{2} \right) + \frac{\rho}{\varepsilon}$$ $$K_3 = \gamma_1 \Delta (1 - \rho^2)$$ $$K_4 = \gamma_2 \Delta (1 - \rho^2)$$

• you need to define your Heston and the Andersen scheme first, otherwise, we do not know what are the parameters referred to. – Gordon Jan 11 '16 at 17:19
• @Gordon My Andersen scheme is nearly the same as in the Andersen paper. I only added interest rate component $r \Delta$. – JosephConrad Jan 11 '16 at 19:54
• @Gordon Ok, thank you, I found an error. It was in generating volatility path. Instead of psi = s2 / (m * m) I had psi = s2 / m * m... – JosephConrad Jan 11 '16 at 23:06
• Congratulations. – Gordon Jan 12 '16 at 13:27