I tried replicating the stochastic vol example in the pymc3 documentation, but using a larger dataset.
NUTS was taking too long, so I tried ADVI.
from pandas_datareader import data import pymc3 as pm import pandas as pd returns = data.get_data_yahoo('SPY', start='2008-5-1', end='2016-12-1')['Adj Close'].pct_change() with pm.Model() as model: nu = pm.Exponential(name='nu', lam=1.0 / 10, testval=5.0) sigma = pm.Exponential(name='sigma', lam=1.0 / .02, testval=0.1) s = pm.distributions.timeseries.GaussianRandomWalk(name='s', sd=sigma, shape=len(returns)) volatility_process = pm.Deterministic(name='volatility_process', var=pm.math.exp(-2.0*s)) r = pm.StudentT(name='r', nu=nu, mu=0.0, lam=1.0 / volatility_process, observed=returns) start = pm.find_MAP() vparams = pm.variational.advi(start=start, n=5000) trace = pm.variational.sample_vp( vparams = vparams, draws = 10000 ) fix, ax = sns.plt.subplots() returns.plot(ax=ax) ax.plot(returns.index, 1/np.exp(trace['s',::5].T), 'r', alpha=0.03)
Unfortunately, the results were not similar to what was in the documentation. It looked liked it was modeling a constant vol, rather than a stochastic vol which was what I was expecting.
Is this to be expected or did I do something wrong? Is ADVI appropriate in this situation, and if not, why is that?