Model


This trend-following model is based on the book “Stocks on the Move” by Andreas Clenow. I modified some parts of the model (e.g. position sizing or the universe of available stocks), but the basic calculations are done in the same way.

Stocks on the Move

I highly recommend you purchase his book and join his website!

Summary of the model

Ranking

  • All stocks are ranked according to their adjusted slope based on the closing price of the last 90 days
  • The ranking is refreshed each Tuesday

Market filter

  • New buys are only permitted if the market (S&P 500) is above the MA200 (market signal: green)
  • If the market is below the MA200, no new purchases are allowed (market signal: red)

Buy Rules

Position Sizing

The size of a position is determined by the portfolio size, risk factor and ATR.

Sell Rules

  • A position is sold when it is no longer in the top 20% of the ranking or when it is trading below the MA100.
  • A position is cut in half if it trades below the 21 EMA.
  • When a stock moves too far away from the MA200, the position size will be reduced (mean reversion)

Workflow to create the ranking

1. Obtaining the universe of stocks
The universe of US stocks is comprised of the members of the

This results in a list of about 1050 disjunct values.

I’m using BeautifulSoup and selenium to automatically parse these sources and create the current list of stocks.

2. Performing the calculations
Looping through the items of the list created in step 1, the calculations and sorting are done in python. The results are written in a csv file. In this step, I depend mostly on pandas, numpy, and scipy.stats

3. Generating the Excel output file
To make the result more appealing to the eye and to add some formatting, I’m using pandas and XlsxWriter. For example, in my own version of the file, all current holdings are color-coded and a list of to-dos (what to buy/sell) is generated automatically,

4. Reporting
Additional reporting and journaling is done with pandas.

I really like this approach because it provides you with clear, binary entry / exit signals and it removes all emotions, gut-decisions, second-guessing etc.

Stock data is sourced from Alpha Vantage.