Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Implementing Complex Scoring Mechanisms

I implemented my own trading algorithm via JavaScript (Node.js) but want to port it to Quantopian. Due to its complexity and the way Quantopian wants us to develop our algorithms I struggle.

My algorithm gives all securities a value between 0% and 100% and buys the top securities and optionally shorts the bottom ones.

A simplified version would look like this:

Overall Percentage = (Fundamental Score + Trend Score) / 2

Fundamental Score = (Free Cashflow Score + Book Value Score) / 2
Free Cashflow Score and Book Value Score = Growth each year over the past 5 years as a percentage of 20
30% growth -> 100%
20% growth -> 100%
10% growth -> 50%
0% growth -> 0%

Trend Score = (Moving Averages Score + All Time Nearness Score) / 2
Moving Averages Score = How high is the trend
Last Price > SMA(10) > SMA(11) > ... > SMA(200) -> 100%
Last Price < SMA(10) < SMA(11) < ... < SMA(200) -> 0%
All Time Nearness Score = How near is the last price to the all time high
Last Price = All Time High -> 100%
Last Price = 50% under All Time High -> 50%

The result of my algorithm would be a sorted list with the overall percentage number and the algorithm would buy the first 10 securities and have a leverage of 100%.

I find it a bit hard to implement such a percentage based algorithm "in the Quantopian way" using the Quantopian API. Do you have any ideas or even sample codes on how to implement something like this?