Terms

This blog is for educational and informational purposes only. The contents of this blog are opinions of the author and should not be interpreted as investment advice. The author takes no responsibility for the investment decisions of other individuals or institutions, and is not liable for any losses they may incur. By reading this blog, you are agreeing that you understand and agree to the terms above.
Showing posts with label High Frequency Trading. Show all posts
Showing posts with label High Frequency Trading. Show all posts

Tuesday, June 28, 2011

Hidden Markov Models: Part II

Since hidden Markov models help researchers to find what sorts of observations tend to come after other types of observations, we have a situation where we can forecast stock behavior once we know what hidden state the security/commodity/currency/synthetic time series was most recently in. (By a synthetic time series, I mean some type of hedged position with a single value being bet on; cointegration residuals in statistical arbitrage, implied volatilities after delta hedging, and PCA-derived risk factor values.)

To successfully deploy capital using an HMM-driven technique, one needs to avoid overfitting the model to the data. I struggled with this. Closing prices from each day turned out to be too unpredictable to work, because the more time passed, the less the older patterns mattered; consequently, I was forced to limit the size of the training sequence I was using, so that the hidden Markov model would only bother trying to learn from the relevant data. Unfortunately, a training set of only 40 days is too small to work well. But 50 days is pushing it, and more than that is quite outdated any daily trading model.

The way around the problem was to use higher frequency data--because it would be relevant while still providing a wealth of information and hidden patterns. Besides all that, higher frequency data allows for more predictions to be made in any given day, and thus limits volatility in portfolio returns. (Real time prices are available through professional brokerage or subscriptions to specific Reuters or Yahoo Finance services. Delayed, but regularly updated prices are available on Google Finance, and no subscription is necessary.)

In order for a hidden Markov model--or any statistical strategy--to work, the trading techniques must be used many, many times. As the number of times the strategy is used increases, the variability in strategy's overall success decreases, and the strategy has more potential for a clean statistical edge to shine through. Conversely, if only a few instruments are held as a portfolio, the portfolio's return is less certain. Trading a few instruments with a prediction algorithm is like going spearfishing with a toothpick. It really is that impractical.

Also, if you know how to do something with a synthetic time series, do it. There tends to be much less variability in outcomes when unwanted risk factors are hedged, and thus much less uncertainty regarding the hidden Markov model's predictive ability.

Sunday, June 5, 2011

Hidden Markov Models

Hidden Markov models have been proven successful for speech recognition, and their success carries over to the prediction of financial time series. According to Patterson's The Quants, and Mallaby's More Money Than God, Renaissance Technologies owes a great deal of their success to hidden Markov models. Research by academics in this paper and this other paper further validated the financial utility of hidden Markov models, and papers such as this one demonstrated their superiority over GARCH(1, 1) models for accurate volatility modeling.

The major issue with using hidden Markov models to predict financial time series is that we are trying to forecast the inherently chaotic. Put differently, forcing HMMs to learn from raw financial data is not always the best idea because it forces them to learn to try and predict the outcome of Brownian motion. On the other hand, that's what information theory is supposed to be about--detecting and predicting signals through a 'noisy' passageway. So while HMMs can still certainly be used on financial data, it's a bit much to ask. The one glaring exception to this is the use of high frequency data, which contains more data and hence is more likely to contain some pattern or other that daily or longer-term data does not reveal. So if dealing with daily or longer-term data, it's a lot easier to do something that eliminates market noise and results in a more statistically calm, pattern-containing time series. Some such methods for hidden Markov models include statistical arbitrage, volatility arbitrage, correlation forecasting, and volume prediction.

Of course, HMMs can also be used even less directly; for instance, by doing information extraction--getting pure information from humans' news articles, such as those on Reuters.com. (My next post will discuss this briefly, and the one after that will talk about other information extraction methods.)

But the most fruitful, direct application of HMMs is in high frequency trading. Because they inherently sort returns into groups (with observations of these returns corresponding to certain probability distributions) that are the underlying 'states,' hidden Markov models can separate out statistically different price movements the same way they can distinguish between vowels and consonants in a two-state model. Put differently, the way underlying states fit together with each other means that even if observed returns are uncorrelated with each other across time, they may be related in a more subtle way: one single certain type of return may be followed by another certain type of return more often than by returns not belonging to that type. I'll leave the rest up to the reader's imagination and programming skills.

Tuesday, May 31, 2011

High Frequency Portfolios

An investment management company must keep track of risk across all positions and strategies used in each of its funds. At high frequency, however, this matters less because the positions are held only a short time, and the strategies can be made market neutral or even componentless (as measured by Principal Components Analysis). Instead, the focus is on transaction costs. How much money does the strategy lose from market impact when entering and exiting the trade? How much of those remaining profits are eaten away at by broker fees? These costs will determine how much of a position may be built in the time available for the strategy to work. Thus, the costs and the time series forecast determine how much may be invested, and the investment is entirely time based. Enter here; wait for the time series' next value; exit here if prediction is unfavorable or if a better post-transaction cost profit is predicted elsewhere--and hold position if it is favorable; repeat.

However, the size of orders should also be limited to a certain percentage of portfolio value, the leverage should remain fixed, and a Value-at-Risk system should also be used to determine whether a trade's marginal VaR is too high to make it a worthwhile investment.

One theoretical (gasp!) price impact model is written as an integral, (from the initial price to the final acceptable transaction price) where the integrand is the price multiplied by the liquidity function, which is a function of the price, and can be derived empirically through experimentation and the use of some statistical regression. Of course, we integrate with respect to the price.

This is intuitive because we have an infinitely small amount we can buy without moving the price. The price moves as we buy, so we have the price times the amount we can buy at that price, for every price between the initial and the final one. (And this works in reverse if selling--the top term of the integral will just be lower than the bottom.)

If there is a certain largest absolute price impact that the investor is willing to allow, he can simply set that impact equal to the integral described above, and solve for the upper term. Then, he can see how many shares he will be buying by integrating the liquidity function with respect to the price, and using the earlier boundaries for the new boundaries of integration. Conversely, if an investor wants to see how much of an impact will be made by a trade of a certain size, the later expression can be set equal to a certain number of shares, and the upper bound of the integral can be solved for. In that case, we plug the upper bound into the former expression, and integrate to find the market impact of the trade.

From there, the investor can construct a search heuristic (particle swarm optimization, cuckoo search, etc.) to search for the optimal trade size. From there, we can use a sort of execution algorithm that allows for transactions across time--something that minimizes (if buying) or maximizes (if selling) the VWAP or TWAP.