Probabilistic Programming (aka Bayesian statistics) allows flexible construction of statistical models to gain insight from data. Estimation of best fitting parameter values -- as well as uncertainty in these estimations -- can be automated by sampling algorithms such as Markov chain Monte Carlo (MCMC). The high interpretability and flexibility of this approach has already lead to a huge paradigm shift in scientific fields ranging from Cognitive Science to Data Science. In this blog post I will highlight what Probabilistic Programming can offer for algorithmic traders.
Bayesian Data Analysis with PyMC3 - Thomas Wiecki from PyData on Vimeo.
Bayesian statistics has many benefits, some of which I discuss in my talk. Most relevant to Quantitative Finance, however, is the fact that you can very flexibly model latent, unobservable processes and how they relate to observable events. As an example, we could model fear of investors. We can't measure it directly but it certainly has a bearing on market behavior and the stock price.
Bayes' formula allows us to then infer backwards: given the observable data (e.g. the stock price), what is the probability of the latent construct (e.g. investor fear)?
"Volatility is a strange thing - it exists but you can't measure it."
-- Tony Cooper on Quantopian forums.
If we can't measure something, the next best thing we can do is to try and model it. One way to do this is in a probabilistic framework is the concept of stochastic volatility: If we assume that returns are normally distributed, the volatility would be captured as the standard deviation of the normal distribution. Thus, the standard deviation gives rise to stochastic volatility. Intuitively we would assume that the standard deviation is high during times of market turmoil like the 2008 crash.
strongly dependent on the window size with no principled way of choosing it.
These properties are outlined in the plot below. The larger the window size, the more lag, the smaller the window size, the more unstable the estimate gets.
As we will see, the stochastic volatility model does a better job at all of them. But before we look at that we need to establish one more insight into the nature of volatility: it tends to cluster. This is nicely demonstrated by looking at the returns of the S&P 500 above. As you can see, during the 2008 financial crisis there is a lot volatility in the stock market (huge positive and negative daily returns) that gradually decreases over time.
So how do we model this clustering property? The Stochastic Volatility model assumes that that the standard-deviation of the returns follow a random-walk process. You can read the Wikipedia article I linked but essentially this process allows for slow, gradual changes over time.
What is interesting is that we can model the standard deviation itself to follow a random walk. Intuitively, we allow standard deviation to change over time but only ever so slightly at each time-point. For the mathematical and implementational details of the model applied see this IPython notebook which uses PyMC3 (a new, flexible probabilistic programming framework for Python).
The plot below shows the latent volatility (in orange) inferred from the model based on the market data (in mint). The orange lines represent the standard deviation of the Normal distribution we assume for the daily returns.
As you can see, the estimated volatility is much more robust. Moreover, all parameters are estimated from the data while we would have to find a reasonable window length for the rolling standard deviation ourselves. Finally, we do not just get a single estimate as with the rolling standard deviation but rather many solutions that are likely. This provides us with a measure of the uncertainty in our estimates and is represented by the width of the orange line above.
powerful sampling methods that allow automatic estimation of highly complex models.
We are currently working on making PyMC3 available on Quantopian to allow usage of this type of models -- so sign up and start getting familiar with our platform, discuss on the forums, and follow @Quantopian and me on Twitter. If you are interested in Probabilistic Programming I also sometimes blog about it here.
In math statistics there are some standard formulas that represent estimates of volatility of a random variable. It would be interesting to look the formulas one uses to estimate volatility of the stochastic process. The statistics used to estimate volatility for a stock can be good if volatility over the period close to constant. Otherwise model risk would be underestimated and suggests visible losses. Unfortunately financial experts do not pay attention to the fact. The stochastic volatility is more complex for calculation object. The stdv of the stock and stock itself are hold Wiener processes. If these Wiener processes are the same it is not clear how to estimate return and volatility of the stock diffusion term. If Wiener processes are independent or correlated it might possible but it does not look reliable its practical implementation. At least it is interesting to look at. I will grateful for directions to the stochastic volatility formula.