Hello !
Last week I started to ask myself how I could estimate Value at Risk of a financial security from a Bayesian approach. I started my research and I found that Pyfolio gave a first solution (in Bayesian tear-sheet) :
As it is a fixed value and not a probability distribution, it is not exactly what I expected. As I understood it is the VaR estimated from simulated returns.
I made a small notebook to illustrate my intuition. I started by generating toy data :
data = sp.stats.t.rvs(8, loc = 0, scale = 0.4, size = 504)
And my model is the following (helped by Pyfolio):
with pm.Model() as model2:
mu = pm.Normal('mean returns', mu=0, sd=.01, testval=data.mean())
sigma = pm.HalfCauchy('volatility', beta=1, testval=data.std())
df = pm.Uniform('df', 0., 10.)
returns = pm.StudentT('returns', nu=df, mu=mu, sd=sigma,
observed=data)
returns_sim = pm.StudentT('returns_sim', nu=df, mu=mu, sd=sigma, shape = 504)
pm.Deterministic('annual volatility',
returns.distribution.variance**.5 * np.sqrt(252))
pm.Deterministic('sharpe', returns.distribution.mean /
returns.distribution.variance**.5 *
np.sqrt(252))
step = pm.NUTS()
trace = pm.sample(2000, step)
The intuition is to generate 2000 samples of 504 observation to draw the probability distribution of my VaR :
As I try to estimate a 95% VaR :
percentiles = np.percentile(trace['returns_sim'], 0.05, axis = 1)
sns.distplot(percentiles)
I uploaded the full notebook here if you are interested.
Do you agree with this approach ?
It is the good way for estimating the distribution of the percentile of a parent distribution ? Perhaps PyMC3 allows a more simple way through pm.Deterministic ?
The distribution has the shape I expected and illustrates our level of uncertainty (if we had stochastic volatility I think the distribution could even be wider).
Perhaps you know some resources on this topic ?
Thanks a lot for your ideas and comments !
Camile