# State price deflator in the Vasicek model

I am trying to implement a simple bond pricing model using state price deflators in a Vasicek model. I am simulating paths of the processes

$$\mathrm{d}r^{P} =\kappa^{P}(\theta^P - r^P(t))\mathrm{d}t + \sigma\mathrm{d}W(t),$$ $$\mathrm{d}r^{Q} =\kappa^{Q}(\theta^Q - r^Q(t))\mathrm{d}t + \sigma\mathrm{d}W(t),$$

Where I use the relation between the risk neutral $$\mathbb{Q}$$-measure parameters and the real world $$\mathbb{P}$$-measure parameters in the Vasicek model given by

$$\kappa^{Q} =\kappa^{P} + \lambda_1 \cdot \sigma$$ $$\theta^Q = \frac{\kappa^P \cdot \theta^P - \lambda_0\cdot\sigma}{\kappa^Q},$$

where the parameters $$\lambda_0$$ and $$\lambda_1$$ define the market price of risk in a so called essentially affine model as proposed by Duffie and Kan, such that the market price of risk $$\Lambda(t)=\lambda_0 + \lambda_1 \cdot r(t)$$. For now, I considered only the case $$\lambda_1 = 0$$.

The state price deflator $$\Pi(t)$$ will then be the solution to the following SDE:

$$\frac{\mathrm{d}\Pi(t)}{\Pi(t)} = -r(t)\mathrm{d}t - \Lambda(t)\mathrm{d}W(t)$$

Now, having implemented a simulation loop for these processes, I would like to verify that the theoretical affine model zero coupon bond price

$$P(t,T) = e^{A(T)-B(T)r(t)}$$

coincides with my simulations, eg. I would like to verify that

$$P(0, 10)=E^Q\left[e^{-\int_0^{10}r(t)\mathrm{d}t}\right]=E^P\left[\frac{\Pi(10)}{\Pi(0)}\cdot 1\right]=E^P\left[\Pi(10)\right].$$ I do this by simulating $$r$$ under the risk neutgral $$\mathbb{Q}$$-measure for the exponential integral, and this coincides with the theoretical affine model zero coupon bond price $$P(0,10)=e^{A(10)-B(10)r(0)}$$.

Then, as to my understanding of state price deflators, I would need to use the $$r$$-process simulated under the real world $$\mathbb{P}$$-measure in order to calculate the zero coupon bond price using SPD, ie.

$$\frac{\mathrm{d}\Pi(t)}{\Pi(t)} = -r^P(t)\mathrm{d}t - \Lambda(t)\mathrm{d}W(t).$$

This does, unfortunately not yield the same result as discounting the risk-neutral $$r$$, which in turn yields the theoretical affine model bond price that is I get

$$P(0, 10)=E^Q\left[e^{-\int_0^{10}r(t)\mathrm{d}t}\right]\neq E^P\left[\Pi(10)\right].$$

Instead, I get the correct price using the $$r$$ process simulated under the $$\mathbb{Q}$$-measure, ie. using

$$\frac{\mathrm{d}\Pi(t)}{\Pi(t)} = -r^Q(t)\mathrm{d}t - \Lambda(t)\mathrm{d}W(t).$$

My question is: Is it correct that by using state price deflators for pricing, you use real world measure $$\mathrm{P}$$ for pricing, such that

$$E^Q\left[e^{-\int_0^{10}r(t)\mathrm{d}t}\right]=E^P\left[\Pi(10)\right]$$

At least, this is how I understood the link between risk neutral, real world and pricing kernels. What confuses me is that under my simulations, the equality

$$E^Q\left[e^{-\int_0^{10}r(t)\mathrm{d}t}\right]=E^Q\left[\Pi(10)\right]$$

seems to hold true. Am I doing something wrong? I have provided my code below:

for (int i = 1; i < steps; i++)
{
// Simulating vasicek process
double rQ = qRateProcess[i - 1];
double rP = pRateProcess[i - 1];
double dwP = randomGenerator.NextGaussian() * sqrtDt;
double dwQ = randomGenerator.NextGaussian() * sqrtDt;
double dwD = randomGenerator.NextGaussian() * sqrtDt;

double drQ = KappaQ * (ThetaQ - rQ) * dt + Sigma * dwQ; // Risk neutral (Q-measure parameters)
double drP = KappaP * (ThetaP - rP) * dt + Sigma * dwP; // Real world   (P-measure parameters)

qRateProcess[i] = rQ + drQ;
pRateProcess[i] = rP + drP;
shortRateIntegral += qRateProcess[i] * dt;

// Simulating deflator with (P-)vasicek interest rate process - should be the right method but is not?
double deflator = deflatorProcess[i - 1];
double dDeflator = -pRateProcess[i] * deflator * dt - deflator * (Lambda + LambdaY * pRateProcess[i]) * dwD;
deflatorProcess[i] = deflator + dDeflator;
}