I am trying to calibrate a one-factor mean-reverting process in python 3. The process is defined as:
\begin{equation} dX = k(\alpha - X)dt + \sigma dW , \end{equation}
where $\alpha = \mu - \frac{\sigma^2}{2k}$ is the long-run mean log price and $k$ is the speed of adjustment. Under the risk neutral probability $Q$ we write the previous equation as
\begin{equation} dX = k(\alpha^* - X)dt + \sigma dW^*. \end{equation}
Here $\alpha^*= \alpha - \lambda$, where $\lambda$ is the market price of risk. Based on Girsanov's Theorem $dW^*$ is a Brownian Motion under the martingale measure $Q$.
My measurement and transition equations are:
- The measurement equation relates the time series of observable variables, in my case futures prices for different maturities, to the unobservable state variable, the spot price:
\begin{equation} y_{t} = Z_{t}X_{t} + d_{t} + \epsilon_{t}, \qquad t = 1, ..., NT \end{equation}
where
$y_{t}=\left[\ln F\left(T_{i}\right)\right]$, $i=1,...,N$, $N\times 1$ vector of observables,
$d_{t}=\left[\left(1-e^{-\kappa T_{1}}\right) \alpha^{*}+\frac{\sigma^{2}}{4 \kappa}\left(1-e^{-2 k T_{1}}\right)\right], \quad i=1, \ldots, N, \quad N \times 1$ vector,
$Z_{t}=\left[e^{-\kappa T_{i}}\right], \quad i=1, \ldots, N, \quad N \times 1$ vector,
$\epsilon_{t}, \quad N\times 1$ vector of serially uncorrelated disturbances with $\mathbb{E}(\epsilon_{t}) = 0$ and $Var(\epsilon_{t}) = H$.
- The transition equation is a discrete-time version of the O-U oil price stochastic process:
\begin{equation} X_{t}=c_{t}+Q_{t} X_{t-1}+\eta_{t}, \quad t=1, \ldots, N T \label{eq:38}, \end{equation}
where
$c_{t}=\kappa \alpha \Delta t$
$Q_{t}=1-\kappa \Delta t$
$\eta_{t}$, serially uncorrelated disturbances with $\mathbb{E}(\eta_{t}) = 0$ and $Var(\eta_{t}) = \sigma^2 \Delta t$.
The aim is to calibrate the model parameters using the time series of different maturities Futures prices via MLE. Any help with the coding part (in python 3) would be much appreciated!