Generic Trading Algorithms: For the Individual Trader

Generic trading algorithms (GTAs) are computerized algorithms that are used in the financial markets to evaluate and implement simple trading strategies. These algorithms are designed to make market decisions based on predefined rules and criteria. They are used to execute various types of trading strategies, such as trend following, mean reversion, and statistical arbitrage. Generic trading algorithms can help investors time their investments better.

There are five phases considered in a genetic algorithm.

  • Defining the trading strategy
  • Gathering historical stock data
  • Calculate indicators:
  • Implement trading rules
  • Simulate Trade

An individual investor can create a generic trading algorithm using Excel and Investment Data Cloud’s Historical Stock Data by following these steps:

1. Define the trading strategy: Decide on the specific rules and criteria that will guide the trading decisions. For example, the strategy could be based on moving average crossovers, technical indicators, or fundamental analysis.

2. Gather historical data: Using IDC datasets and functions, extract the historical price data for the relevant ‘tickers’ on which the strategy is to be implemented. Ensure that the data is organized in columns, with each row representing a specific time period.

3. Calculate indicators: Use Excel formulas and functions to calculate any necessary indicators or metrics required by the trading strategy. This may involve calculating moving averages, relative strength index (RSI), or other technical indicators.

4. Implement trading rules: Apply the predefined trading rules to the data in the spreadsheet. Use conditional statements and formulas to determine when to make trades, such as buying or selling based on indicator thresholds or crossover points.

5. Simulate trades: Incorporate calculations for trade prices, quantities, and transaction costs to simulate the execution of trades. Keep track of the portfolio’s value, positions.

Generic Trading example

One example of a simple generic trading strategy is the Stock Moving Average Crossover strategy. This strategy uses two moving averages of different lengths to generate trading signals.

The basic idea behind this strategy is to identify the trend in the market and enter trades in the direction of the trend. Here’s how it works:

1. Calculate two moving averages: One with a shorter time period (e.g., 50 days) and one with a longer time period (e.g., 200 days).

2. When the shorter moving average crosses above the longer moving average, it generates a buy signal. This indicates that the short-term trend is turning bullish.

3. When the shorter moving average crosses below the longer moving average, it generates a sell signal. This indicates that the short-term trend is turning bearish.

4. Enter a long position (buy) when the buy signal is generated, and exit the position (sell) when the sell signal is generated.

5. This strategy can be combined with additional risk management rules, such as setting stop-loss orders to limit potential losses and take-profit orders to lock in profits.

The Moving Average Crossover strategy is a simple and widely used strategy that can be easily implemented in code. However, it’s important to note that no strategy is guaranteed to be successful.

Here are several more examples of common generic trading strategies:

1. Trend Following: This strategy aims to identify and capitalize on long-term trends in the market. Traders using this strategy would enter a position when the market is trending upwards and exit when the trend reverses. Moving averages, price breakouts, and trend indicators can be used to identify these trends.

2. Mean Reversion: This strategy assumes that, over time, prices tend to revert to their average or mean level. Traders using this strategy would identify assets that have deviated significantly from their mean and take positions betting that they will move back towards the mean. Bollinger Bands, RSI indicators, and mean reversion statistical models can be used for this strategy.

3. Breakout: This strategy aims to capitalize on price movements following a period of consolidation or a significant breakout from a trading range. Traders using this strategy would enter positions when the price breaks above or below a predefined level of support or resistance. Moving average crossovers, support and resistance levels, and volatility indicators can be used for this strategy.

4. Statistical Arbitrage: This strategy involves identifying and exploiting pricing inefficiencies between related financial instruments. would simultaneously buy and sell correlated assets when there is a deviation in their prices. Pair trading, statistical models, and correlation analysis can be used for this strategy.

5. Momentum: This strategy assumes that assets that have been performing well in the recent past will continue to perform well soon. Traders using this strategy would enter positions in assets that show strong upward momentum and exit when momentum weakens. Relative strength index (RSI), moving averages, and other momentum indicators can be used for this strategy.

It’s important to note that these strategies are just examples, and the effectiveness of each strategy can vary depending on the market conditions and other factors. Traders should carefully back test, evaluate, and customize these strategies to suit their individual trading goals and risk tolerance.


EXAMPLE OF A MOMEMTUM STRATEGY

 Momentum investing is an approach that seeks to buy stocks with the best historical performance over a given period and then periodically rebalance the portfolio such that at any given time, it’s invested in the stocks with the highest momentum.

HOW DOES IT WORK

  • A momentum investor buys stocks that have performed best over the last 6 months (can be 3, 9, or 12 months)
  • The investor rebalances his portfolio every month or 3 months by selling the least performing ones and buying new stocks currently performing better.

A quick statistic about the rationale behind the momentum strategy:

Between 1985 and 2015 approximately 20% of all stocks accounted for all the gains during the period, meaning that the remaining 80% accounted for zero returns.”

Still need more proof that a well-designed momentum strategy can be effective!?

Using IDC Excel Plug-In to implement a Momentum Strategy 

To begin, fetch the price and trading volume data for the chosen time frame for the chosen stock, in this case Apple from IDC Excel. The time frame chosen is 1st January 2023 to 31st May 2023.  (below I pulled show January and February for Brievties sake), IDC makes pulling the data down easy.

FORMULA USED:

=IDC_AdjClosePrice($B2,$A2)

=IDC_AdjCloseSize($B2,$A2)

Next, calculate the 10 day moving averages for price and volume. The moving averages will give us metrics to compare the current price and volume of a stock during the most recent trading session.
averages for price and volume

For the strategy, we can create buy indicators when the stock price is below the 10 day moving average and the daily volume is above the 10 day moving average. This rule will decide the “buy” date. Vice versa, if the price drops, then we have our “sell” dates.

The length of the moving averages can be adjusted to fit your preference and will significantly affect how frequently your momentum trading strategy executes trades.

A longer moving average will result in less trades and vice versa. A longer moving average period may perform better on large cap stocks with less volatility. On the other hand, a shorter moving average period is more suited for equities with higher price volatility.

PLOTTING MOVING AVERAGES

PLOTTING MOVING AVERAGES

This is how a basic Momentum strategy can be created using the IDC plugin on excel.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Try Free demo!

Please enter your email address and hit the submit button and we will email you Excel Add-In with Complete Instructions