Open CPU is a great project. Few months back, I wrote a function for plotting a moving window of the market average correlation. Jeroen C.L. Ooms was nice enough to upload it to their server. Something is now changed. Quotes now return as a character class, as oppose to numeric. This messes up the function and the plot does not renders. I don’t wish to disturb Jeroen C.L. Ooms again with the correction for the code (despite his kind replies in the past). This problem creates the opportunity to look at the glistening “Shiny” package. I used it to (quickly..) build an app for the plot. You can now view a live correlation plot with the moving window of your choice. Live, as the app requests current market data. The width of the window for correlation calculation is given as an input parameter.
Category: Finance and Trading
A Simple Model for Realized Volatility
The post has two goals:
(1) Explain how to forecast volatility using a simple Heterogeneous Auto-Regressive (HAR) model. (Corsi, 2002)
(2) Check if higher moments like Skewness and Kurtosis add forecast value to this model.
On Volatility Proxy
Volatility is unobserved. Hence we need to use observed quantity as a proxy. Every once in a while I still see people using squared daily return as a proxy. However, there is ample evidence that it is a bad one. Bad in a sense that it is noisy, which means that although on average it is a good estimate, on any individual day the estimate can be very far from the actual unobserved volatility. Here is a figure of the alleged standard deviation in the form of (square root of the) squared daily return for the recent year:
You can see that in many days, this noisy estimate suggests that the volatility was around 2% and more. To me, it does not make too much sense. The series is the S&P 500, so a move of 3% is a BIG one. You can also see how “jumpy” the series is. The figure illustrates why we should avoid using this estimate.
Forecasting the Misery Index, follow-up
Five months ago I generated forecasts for the Eurozone Misery index. I used the built-in “FitAR” package in R. Using different models differing in their memory length (how many lags were considered for each model) 24 months ahead forecasts were generated. Might be interesting to see how accurate are the forecasts. The previous post is updated and few bugs corrected in the code. The updated data is public and can be found here. It is the sum of inflation rate and unemployment rate in the Euro-zone area.
Volatility forecast evaluation in R
In portfolio management, risk management and derivative pricing, volatility plays an important role. So important in fact that you can find more volatility models than you can handle (Wikipedia link). What follows is to check how well each model performs, in and out of sample. Here are three simple things you can do:
Intraday volatility measures
In the last few decades there has been tremendous progress in the realm of volatility estimation. A major step is the additional use of intraday price path. It has been shown that estimates which consider intraday information are more accurate. Which is to say they converge faster to the real unobserved value of the true volatility.
A shrinkage estimator for beta
In the post pairs trading issues one of the problems raised was the unstable estimates of the stock’s beta with respect to the market. Here is a suggestion for a possible solution, which is not really a solution but more stuff to do to make you feel less stupid when trading based on your fragile estimates.
Random books
It seems like a very long while since my bachelor. Checking my bookshelf the other day I was thinking to flag some of those books which helped or inspired me along the way. Here they are in no particular order.
Forecasting the Eurozone Misery index
Is Miss Stagflation coming to visit?
The Misery index is the sum of inflation and unemployment rate. We would like them both to stay naturally low, and we are miserable when they are not. The index is currently floating in it’s record scratching levels. In this post I demonstrate the use of the nice FitAR package in R to fit an AR model and see what we can expect accordingly. Inflation and unemployment numbers concerning the Eurozone (17 countries) can be found here.
Have a look at the index over time:
Stock market Kurtosis over time
In the last decade we have observed an increase in computational power, information availability, speed of execution and stock market competition in general. One might think that, as a result, we are prone to larger shocks that occur faster than what was common in the past. I crunched some numbers and was surprised to see that this is not the case.
Backtesting trading strategies with R
Few weeks back I gave a talk about Backtesting trading strategies with R, got a few requests for the slides so here they are:
Most profitable hedge fund style
This is not an investment advice!!
Couple of weeks back, during amst-R-dam user group talk on backtesting trading strategies using R, I mentioned the most effective style for hedge funds is relative value statistical arbitrage, I read it somewhere. After the talk was over, I was not sure anymore if it was correct to say it and decided to check it.
Live Rolling Correlation Plot
Open source is amazing! I cannot even start to imagine the amount of work invested in R, in firefox browser (Mozilla), or Rstudio IDE, all of which are used extensively around the globe, free. Not free as in: free sample till you decide to upgrade, or: sure it’s free, just watch this one minute commercial every time you need to use it, but free, as in: we think it might make your life better, enjoy. Warms the heart, in direct opposite to the fabulous fabs out there, that instead of contributing to a better, safer society, set it back and get paid for it (see appendix). Character is also normally distributed I guess.
Price is right, part two – Trading strategy.
Having stock market in mind, in the previous post: “Price is right, part one.”, I stated that we should not think in terms of “the price went up/down too much” but that “the current price level is wrong since…. and the market is not getting it because…”, bearing in mind that Mr. Market is not a weak player to say the least.
In this post I back this claim with the examination of a trading strategy that ignores economical arguments, thus is only based on relative price moves. Say you believe my previous post is horseshit, wouldn’t it be nice to short the market if it’s “too high” and to long it when it “went down too much”? Fine!, let’s have a look at the performance of such a strategy.
Price is right, part one.
Efficient Market Hypothesis states that the price you see is the price you should see. The price that exactly reflects the expectation of engaging a lottery.