Algorithmic Trading

Trading algorithms, models, and systems can help you trade more profitably, predict the markets more accurately, and consistently beat the markets in the long run. This systematic approach takes the emotions and doubt out of trading. Algorithmic traders know exactly what and when to buy/sell at any given point in time.

In this guide to algorithmic trading I will show you several trading algorithms and systems you can start using today.

U.S. & Emerging Markets Momentum Strategy

The momentum factor is well-documented in financial literature. Most momentum-based trading strategies focus on U.S. stocks. We can increase our trading returns by adding emerging markets to a momentum-based trading strategy.

Data needed

  1. S&P 500
  2. MSCI Emerging Markets Index
  3. Bloomberg Barclays U.S. Treasury Bond Index
  4. CBOE Equity Put/Call ratio

*All data is monthly, based on month-end close value.

Trading algorithm’s rules

  1. Calculate the Equity Put/Call ratio’s (1 month average) / (6 month average) – 1
  2. Was this Equity Put/Call ratio’s calculation above -0.1 last month or the previous month?
  3. Is the S&P 500 above its 10 month average and is the S&P 500’s 2 month average above its 10 month average?

If the answer to all these questions is YES:

  1. If the S&P 500’s 12 month rate-of-change > MSCI Emerging Markets’ 12 month rate-of-change, go long the S&P 500 for the next month.
  2. If the MSCI Emerging Markets’ 12 month rate-of-change > S&P 500’s 12 month rate-of-change, go long MSCI Emerging Markets for the next month.

If the answer to any of these questions is NO:

  1. Do not buy the S&P 500 or MSCI Emerging Markets Index. Go long the Bloomberg Barclays U.S. Treasury Bond Index

ETFs for trading with this algorithm

  1. SPY
  2. EEM
  3. TLT

Algorithm’s performance

The average return for this algorithm is 15.86% per year.

Performance Chart:

The maximum drawdown for this algorithm is -15.79%.

Drawdown chart:

This trading algorithm’s Sharpe Ratio is 0.9671


NASDAQ vs. S&P Algorithm

This trading algorithm was originally created by my friend Carlo Seneci.

The NASDAQ Composite tends to outperform the S&P 500 during bull markets and underperform during bear markets. Hence, it’s better to buy the NASDAQ during strong uptrends, buy the S&P during weak uptrends, and hold cash during a bear market.

Data needed

  1. S&P 500
  2. NASDAQ Composite

*All data is daily

Trading algorithm’s rules

  1. If the NASDAQ Composite is above its 27 day moving average, go long the NASDAQ for tomorrow.
  2. If the NASDAQ Composite is not above its 27 dma AND the S&P 500’s 50 dma is above its 200 dma, go long the S&P for tomorrow.
  3. Otherwise, hold 100% cash for tomorrow.

Algorithm’s performance

The average return for this algorithm is 18.1% per year.

Performance Chart:

Sector Trading Algorithm

The Sector Trading Algorithm makes use of sector rotation based on the strength of markets’ momentum. This algorithm trades 3 markets among 9 S&P 500 sectors and Treasury bonds. We pick the 3 strongest ETFs with the highest 12 month rate-of-change and hold them in our portfolio. We rebalance every month.

Trading algorithm’s rules

  1. At the end of every month, look at the sector ETFs which closed at a 12 month high. Among these ETFs, buy the 3 ETFs with the highest 12 month rate-of-change. Invest 1/3 of your portfolio’s value into each ETF.
  2. If only 2 ETFs are at a 12 month high, only buy 2 ETFs. Invest 1/3 of your portfolio’s value into each ETF. Invest 1/3 of your portfolio’s value into Treasury bonds.
  3. If only 1 ETF is at a 12 month high, only buy 1 ETF. Invest 1/3 of your portfolio’s value into the ETF. Invest 2/3 of your portfolio’s value into Treasury bonds.
  4. If no ETFs are at a 12 month high, buy no ETFs. Invest your entire portfolio into Treasury bonds.
  5. Re-balance this portfolio once every month.

Algorithm’s performance

The average return for this algorithm is 7.2% per year.

Performance Chart:

The maximum drawdown for this algorithm is -12.2%.

Drawdown chart:

To see how to code this trading algorithm yourself, we have created a step by step tutorial below:


Insider Trading Strategy

There are 2 general ways to outperform buy and hold in the stock market:

  1. Time the broad “stock market”
  2. Buy stocks that outperform the broad stock market

Here’s how you can use insider trading data to double your trading profits by buying stocks that are better than the broad stock market (S&P 500).

Use insider trading data to double your trading returns

Corporate insiders (e.g. CEOs, CFOs) are smart money. If you buy and sell the stocks that they’re trading, you can significantly improve your trading performance!

The following chart demonstrates that corporate insiders beat the S&P 500 by an average of 12%+ per year! That’s double the S&P 500’s average annual return!

Here’s how we discovered this trading strategy:

  1. We took all insider buy transactions for companies that are in the S&P 500.
  2. For every BUY transaction, we calculated how much that trade beat “buy and hold the S&P 500” over the next 3 months. E.g. if Apple’s CEO bought Apple, and Apple went up 10% over the next 3 months while the S&P went up 6%, “alpha” = 4%.
  3. On every single day, we calculated an average alpha for all the BUY transactions on that date. E.g. if on September 5, 2020 there were 4 buy transactions (alpha of +5%, -1%, +3%, +1%), “average alpha” = 2%

Essentially, “average alpha” shows you how much you will beat the S&P 500 (3 months later) if you buy the stocks that corporate insiders buy instead of buying an S&P 500 ETF like SPY.

From 2003-present, the average day saw insider BUY transactions beat the S&P 500 by 3.3% over the next 3 months!

On an annualized basis, if you bought the stocks that corporate insiders bought instead of buying the S&P 500, you would have beaten the S&P 500 by an average of 12%+ per year! This more than doubles the S&P 500’s performance from 2003-present!

It’s very easy to follow the trades that corporate insiders are making. We display up-to-date insider trading data for free on our website.


Long Term Investment Strategy

Trading can be extremely tough and time consuming if you don’t know what you’re doing. It’s hard to be consistently profitable, and not everyone has enough time to constantly trade.

This Long Term Investment Strategy allows you to rarely touch your portfolio while achieving great risk-adjusted returns. That way you can make money in good and bad market cycles without trading too often and losing any sleep. It will protect you during:

  1. Bull markets
  2. Bear markets & recessions
  3. High inflationary periods

To protect your portfolio during all market environments, the trading model will allocate your portfolio between stocks, bonds, and gold because each of these assets does well in a different market environment:

  1. Stocks do well during bull markets and economic expansions because traders bet that corporate profits will increase, thereby making companies more valuable.
  2. Treasury bonds do well during bear markets and recessions as traders and investors panic, sell risky assets, and rush towards safe havens.
  3. Gold does well during high inflationary periods when people lose confidence in fiat currencies.

Here are the trading algorithm’s rules.

Trading algorithm’s rules

  1. Allocate 30% of your portfolio to U.S. stocks
  2. Allocate 55% of your portfolio to U.S. Treasury Bonds
  3. Allocate 15% of your portfolio to gold
  4. Rebalance your portfolio once every quarter (end of March, end of June, end of September, end of December)

If you’re not familiar with the concept of “rebalancing your portfolio”, here’s an example.

Let’s assume that your $100,000 portfolio in January 1 has:

  1. $30k in U.S. stocks
  2. $55k in U.S. Treasury Bonds
  3. $15k in gold

At the end of March, your U.S. stock market position jumped from $30k to $60k because U.S. stock prices went up. Your U.S. Treasury Bond position didn’t move (still $55k), and your gold position didn’t move (still $15k).

Since your portfolio is now worth $130k, you need to rebalance your portfolio. Remember, 30% of your portfolio should be in U.S. stocks, 55% should be in U.S. Treasury Bonds, and 15% should be in gold. This means that at the end of March, you should sell your existing positions and purchase:

  1. $39k in U.S. stocks
  2. $71.5k in U.S. Treasury Bonds
  3. $19.5k in gold

If you want to execute this trading algorithm, use the ETFs:

  1. SPY for U.S. stocks
  2. TLT for U.S. Treasury Bonds
  3. GLD for gold

Algorithm’s performance

  1. This strategy yields an average of 7.23% per year
  2. In comparison, buy and hold U.S. stocks yields an average of 9.57% per year

Now you may be thinking “this doesn’t seem impressive, this strategy underperforms buy and hold!” While the strategy may underperform buy and hold U.S. stocks, it is MUCH less risky than buy and hold U.S. stocks

The following chart compares how risky each strategy is, also called the Sharpe ratio.

  1. The algorithmic strategy’s Sharpe ratio is 1.02
  2. Buy and hold’s Sharpe is 0.5

This means that buy and hold is TWICE as risky as this strategy!

To see this visually, we can look at a chart that compares the performance difference between these 2 strategies.

As you can see in this chart, buy and hold U.S. stocks does outperform this strategy. HOWEVER, investors and traders who buy and hold U.S. stocks must suffer through MASSIVE losses from time to time, such as 2000-2002 and 2007-2009.

In comparison, this trading strategy is remarkably safe and stable. Investors and traders who used this strategy booked profits during the 2000-2002 stock market crash, suffered minor losses during the 2007-2009 market crash, and almost didn’t suffer any losses during the March 2020 stock market crash.

Looking at a maximum drawdown chart makes this point very clear. This trading strategy results in MUCH SMALLER drawdowns and losses than if you buy and hold U.S. stocks. If you want to increase your returns from, say 7% to 14%, you can use 2x leverage while STILL experiencing smaller drawdowns than if you buy and hold U.S. stocks.