Help with Multivariate SDE Timeseries

I tried implementing the model without correlation as a starting point but am getting a “Bad Initial Energy” error. I tried setting init=‘adapt_diag’ in pm.sample but still get the error. I even tried changing my priors to ensure they are positive.


import numpy as np
import matplotlib.pyplot as plt
import pymc3 as pm
from pymc3.distributions.timeseries import EulerMaruyama

returns = np.genfromtxt(pm.get_data("SP500.csv"))

def Vt_sde(Vt, sigmaV, kappa, theta):
    return kappa*(theta-Vt), sigmaV *np.sqrt(Vt)

with pm.Model() as sp500_model:

    theta=pm.HalfNormal('theta',sd=0.4)
    kappa=pm.HalfNormal('kappa',sd=2)
    sigmaV=pm.InverseGamma('sigmaV',2.5,0.1)
    
    Vt = EulerMaruyama('Vt',1.0,Vt_sde,[sigmaV, kappa, theta],shape=len(returns),testval=np.repeat(.01,len(returns)))
    volatility_process = pm.Deterministic('volatility_process', np.sqrt(Vt))
    r = pm.Normal('r', mu=0,sd=volatility_process, observed=returns)
    
with sp500_model:
    trace = pm.sample(2000,chains=1,cores=1)
    
pm.traceplot(trace, [sigmaV, kappa, theta],init='adapt_diag');

ValueError: Bad initial energy: inf. The model might be misspecified.