Showcase: algorithms from various books

To show TuringTrader’s capabilities, I have implemented the algorithms described in the following books:

  • Muscular Portfolios, by Brian Livingston
  • Dual Momentum Investing, by Gary Antonacci
  • The Ivy Portfolio, by Mebane T. Faber
  • Stocks on the Move by Andreas F. Clenow

Here is a brief overview of the algorithms, in the order of increasing complexity. In summary, these strategies show TuringTrader’s unique combination of power and ease-of-use: None of the strategies require more than 100 lines of code to implement their main logic.

You might find these implementations a useful starting point, when developing your own strategies. If you are new to TuringTrader, we recommend starting with reading the Quick Start Guide.

Muscular Portfolios: Mama Bear & Papa Bear

These strategies trade ETFs from a menu of 9 (Mama Bear) or 13 (Papa Bear) constituents. Each month, we calculate the momentum for each of the constituents and select the top 3. The strategy only rebalances the portfolio in case the target percentage is more than 20% off.

You can find the source code for the strategy here. The code for calculating the momentum, and for ranking the instruments each require only a single Linq expression. Only very little additional logic is required to determine when to re-balance, and to emit the actual trades.

Find the book’s homepage here.

Dual Momentum Investing

This strategy trades a menu of 9 ETFs, arranged in 4 asset classes of 2 instruments each, plus one safe instrument. For each asset class, the strategy picks the instrument with the highest momentum. This is also where the strategy gets its name from: instruments are ranked relative to each other, and also in absolute terms, as the momentum of the safe instrument is mostly time-invariant.

This strategy’s source code is here. As before, calculation of the instrument momentum is done in a single Linq expression. As the safe instrument is shared across all asset classes, we use a loop and a dictionary to accumulate the individual instrument weights. However, the resulting code is still surprisingly concise.

The book’s homepage is here.

The Ivy Portfolio

The book describes multiple strategies. They all trade a number of ETFs (5, 10, 20), selected by their momentum. There are 2 flavors:

  • The Timing Model. In this model, we define a bunch of equally-weighted asset classes, and hold the asset class’s main instrument, if it is trading above its 10-month moving average, or else hold a safe instrument.
  • The Rotation System. In this model, we just rank all of our instruments by their momentum and pick the top 3.

The source code for the strategy is here. To accommodate both strategy flavors, the data structure defining the asset classes is slightly more elaborate, allowing to define a number of asset classes, their weighting, and the number of instruments to pick from each class. The code is almost identical to the Dual Momentum strategy above, with the most notable difference being the ability to select multiple ‘best instruments’ per asset class. This code makes a great starting point for your own portfolio variations.

Mebane Faber’s books can be found here.

Stocks on the Move

While the above strategies had a lot in common regarding their method of portfolio construction, and their instruments traded, this one is very different. The strategy trades stocks from the S&P 500, selected by their momentum, calculated using logarithmic regression. Candidates are disqualified, if trading below their 100-day moving average, or if showing recent moves in excess of 15%. On top of all that, there is an index filter, disallowing new entries if the S&P is trading below its 200-day moving average. The strategy sizes positions using an equal-volatility approach.

The source code for the strategy is located here. With this strategy, TuringTrader really shines in making it easy to calculate a whole set of indicators with just a single LINQ expression. Even though this strategy is much more complex than the previous strategies, the code remains concise and readable.

Please find the book’s homepage here.

We hope you find these strategies useful as a starting point for your own projects. If you are just curious and like to see how well these strategies do, head over to, where we have daily updated charts.