Conceptual Framework and Methods - adelekap/capstone_algo_trading GitHub Wiki

Common Investment Strategies

There are typically three different approaches when it comes to forming an investment strategy: a mean-reversion strategy, a momentum strategy, and a value-based trading strategy. All three of these strategies have been used extensively, by both quants and active traders and both have their pros and cons. A mean-reversion strategy makes the assumption that a stock’s price will always return back to the mean after a temporary deviation. The common saying "buy low, sell high" is taken from this type of strategy, and in following these recommendations, a trader can take advantage of these deviations from the mean. This style of trading works well in the typical market environment since stocks move typically around the mean. The drawback to using this strategy is that profits come in trickles, only making small profits here and there. A momentum strategy, in contrast, is designed such that it will capitalize on big market movements. This means that large downward swings can be used to "short- sell" stocks (i.e. hold a short position) and large upward swings in the market can be used to "long" a stock (i.e. hold a long position). This results in long periods of inactivity and then a large number of positions being made when a a significant amount of deviation in the price occurs.

Therefore, it is easiest to describe a mean-reversion strategy as operating at high- frequency, and having low profit potential; while a momentum strategy operates at a low-frequency, and has a high profit potential. Finally, a value-based strategy is simply taking advantage of the general upward trend of the stock market. This involves holding a position for long periods of time and just selling and making a profit at the end of the position. Most individuals investing in the stock market take this approach to their investments. Although this strategy is fairly lower risk, it can result in much lower returns. It is important to note that different strategies thrive in different market environments. For instance, a mean reversion strategy would not work well in a "bull market" because it is difficult to tell where the true mean lies.

Trading System Components

Data Handler: gathering, storing, and querying data

The first component of the trading system deals with all interactions with the data, what I am calling the data handler. This includes the database and the set of methods that put and get data from the database. The data handler interacts with every other component in the trading system. The database and its structure is discussed in greater detail in Chapter 3.

Strategy: triggering entries and exits

Because the resolution of the data that was collected was only daily, we are limited in trading at a lower frequency. Therefore, I decided to adopt a momentum strategy rather than a mean-reversion strategy. A momentum strategy will allow us to make greater returns with less trades. The basic strategy that I implemented in this project is outlined in Algorithm 1. The trader assumed that if prices varied by more than p%, it was worthwhile to open a position (make a trade). Each day d, actions were determined by first predicting the average daily price and calculating the arithmetic returns Vd. These predictions (an output of a predictive model) were calculated for k=5 days in the future and gathered in a set of average daily prices. The value of p% was determined by conducting a grid search and choosing the p that resulted in the greatest returns. As a side-note, it is important to define the distinction between two very distinct types of positions that can be made. A long position is made with the expectation that the price of the asset will rise in the near future. When opening a long position, an investor purchases a number of shares of a stock and holds those shares until the price rises to some higher price. When the investor believes that they have gained a good return on their investment, they will sell their shares and gain the profits. This type of position is the most conventional investing practice in the stock market. In contrast, a short position is made when the investor believes that the price of an asset will decrease in the near future. One of the key distinctions between these two positions is the ownership of the stock. In a long position, the investor owns the shares that they purchased, but in a short position, the investor borrows the shares from a broker with the expectation of selling it and repurchasing it at a lower price. It is sometimes common for active traders to use the money that they made from the initial selling of shares that they intend to short to invest in other positions, however, this is extremely risky and I do not allow this possibility in this trading system.

The indicator value that was used to decide whether or not to make a position on each day was called T. The higher the value of T, the more confident we are that the price will be significantly swinging in one direction or the other. T is a total sum of the variations whose absolute value is above our target margin p%. For each day of trading, T was calculated for a particular stock and if its magnitude was greater than the threshold k × p × 0.5 (half of the next k days were p), a position was taken. A large, positive value of T meant that we believed that the stock price was going to go up in the future, indicating that we should open a long position. A large, negative value of T meant that we believed that the stock price was going to go down indicating that we should open a short position. Positions were closed when either (1) the price of the stock reached startPrice × (1 − p) (in the case of a short) or startPrice × (1 + p) (in the case of a long), or (2) the position had been held for 10 days, whichever instance arose first. Many traders also set a "stop loss" with their broker which is the maximum amount of their initial investment they are willing to lose in a position before they get out. This is typically done just for short positions, but I set this parameter for both short and long positions. The value was set for 30% of the original investment so that if a position was worth 70% of the starting worth, the position would be closed. So far, I have only discussed the strategy in terms of a single stock. In order to make decisions about which stock to invest in, a due-diligence bot identified prime sectors as well as the best stock within that sector to invest in. This will be dis- cussed in greater detail in Chapter 4. This was not something I encountered while researching other trading strategies, but it is common practice for human traders to do their research not only on the success of the stock being considered, but also on the success of that stock’s company before making an investment.

In this project I hold this strategy I have described constant. The variable that I manipulate and compare is the predictive model that informs the investor about what will happen to the price of the asset in the near future. I implement three different models in order to see which one is best suited for this task as well as this momentum type strategy. These models, as well as how they were optimized, will be explained in greater detail in Chapter 5.

Execution: backtesting the trading strategy

The term backtesting is often used in the quant-world to refer to testing a trading strategy on relevant historical data to see how it would have performed in a real- world market scenario. These trading simulations allow traders to determine if they have a viable trading system without losing any actual capital. The execution element of this trading system takes the instructions from the strategy and executes hypothetical trades, accomplishing the backtesting phase of development. The strategy was tuned to 4.5 years of data and the simulated live trading was done from September 2017 to February 2018. All of the investments and returns that the investor agent acquired were saved in the database.

Portfolio: evaluating the trading strategy

Performance in the trading simulation described in the last section was compared to a baseline trading measure. This measure was determined using the actual market prices for the dates of the simulation and was defined as a trader that held only a single long position for those dates. The percent returns of the trader in the simulation was compared to this percent return. Returns using different predictive models was also compared and visualized.This evaluation is different than the evaluation that is done in the "strategy" component. This evaluation is on the accuracy of the predictive model to predict the next price in the time series to evaluate the test performance of the model. This evaluation is comparing different prediction sources in combination with the trading strategy to see how well this combination does at making a profit. Once a suitable and profitable trading system has been identified, most quants would have their system participate in trading stocks in real-time. I, however, just report the results of my backtesting.