Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Basic Multi-Factor Backtest (Geneva)

Factors
I used the following 4 factors for my long/short model:

  • Revenue Growth (3-month average), Sentiment, Dividend Yield, Free Cash Flow

I used Dividend Yield as one of the four factors because dividend yielding stocks tend to outperform the market and I believe investors have an increased demand for yield in the current market environment. I used Free Cash Flow & Revenue Growth to assure that the company is able to sustain their dividend and fund capital expenditures with cash flow from operations rather than additional financing. I then used Sentiment in conjunction with the three other factors, in hopes that the model would pick up on securities that were in favor.

Benchmark
The S&P 500 probably wouldn’t be an appropriate benchmark for this strategy. An appropriate benchmark would be a similar long/short ETF. One could argue that a risk-free asset could be used for this equal weight long/short strategy, But I personally wouldn’t agree.
I couldn’t find a long/short ETF that was compatible with Quantopian so I used a risk-free ETF as the benchmark (SHY).
~SHY Objective: The iShares 1-3 Year Treasury Bond ETF seeks to track the investment results of an index composed of U.S. Treasury bonds with remaining maturities between one and three years

Recommendation
This model needs more work. This model doesn’t utilize enough factors to provide an accurate recommendation (I’m not implying that more factors would automatically improve this strategy).

Below are just some other factors that I will look to utilize in future models:
- Momentum, Quality, Volatility, Earnings, Analyst Revisions & Targets, Trend, Behavioral Finance Indicators, Technical Indicators, put/call ratios, Volume, Balance Sheet & Income Statement Ratios, Market Construction, Cyclical Companies, Market Environment

Please share your thoughts, comments, and model improvements. Thanks!

1 response

The code above has that flexibility of being able to swap other factors for example in place of cash_flow_statement.free_cash_flow.latest, trying different factors, and it sets longs and shorts from within pipeline. It then assigns equal weights.

In a tool I use, at 88 trading days, it was holding onto 381 of 382 positions. The only one not present had delisted.
At 860 trading days, 418 held of 463 all time, a fairly unusual and high retention rate from what I've seen.

2014-05-05 06:31 ti:490 INFO auto close -31 BEAM at 83.45  value -2586  
2014-05-08 13:00 _ti:963 INFO  88 trading days     0 hr 20.1 min   2017-12-05 22:30 US/Pacific  
    Portfolio: 1011248               2014-01-02 to 2017-06-01                  Alpha:  
 Initial Cash: 1000000                      Buys:   22753                       Beta:   -0.05  
  Unused Cash:  995137                     Sells:   23045                     Sharpe:  
   Max Margin:       0               Commissions:      10                   Drawdown:     0.7  
     Max Risk:  560320 (56%)          Shares Now:   23397                  Stability:   0.546  
  Cash Profit:   10505                Shares Val:     744                    Sortino:  
 Total Profit:   11248                  Cash Now: 1010505                   Shrt/Lng Now: 1.00  
     Q Return:   1.12% Profit/Init      Max Lvrg:    1.02  2014-02-12         Max Shorts: -560320  
   PvR Return:   2.01% Profit/Risk     PvR %/day:    0.02                     Max  Longs:  509939  
2014-05-08 13:00 ti:1135 INFO .  
2014-05-08 13:00 _ti:956 INFO   Sort column 1             Positions: 381 of 382 traded  
         Profit   Max    Return  Return   Buy    Price    Buy|Sell    Max     Shares   Shares  
 Symbol    PnL   Risked     %     %/day   Hold  Init|Now   Orders   Shrt|Lng    Now       %  
    NUS   1272    4138    30.7    0.35    -0.4   138|77    15|18     -36|0      -34   -0.0026  
    WTW   1201    3795    31.6    0.36    -0.3   32|22     33|30    -133|130   -119   -0.0026  
     MU   1098    3947    27.8    0.32     0.2   22|27     27|33    -127|123   -100   -0.0027  
     NE   1089    3742    29.1    0.33    -0.2   37|30     17|33     -89|91     -86   -0.0026  
    WHR    946    3512    26.9    0.31    -0.0  157|151     6|9      -19|20     -17   -0.0025  
    ADT    890    3325    26.8     0.3    -0.2   40|32     21|31     -93|91      85    0.0027  
   WYNN    854    3407    25.0    0.28    -0.0  197|196     4|7      -13|13     -13   -0.0025  
2014-05-08 13:00 _ti:956 INFO _  
    CLF    803    3721    21.6    0.25    -0.3   26|17     27|48    -153|149   -151   -0.0026  
    POM    797    3475    22.9    0.26     0.4   19|27     17|31    -142|141     96    0.0026  
    BBY    771    3917    19.7    0.22    -0.4   40|26     29|29    -117|109    105    0.0026  
    JCP    744    4135    18.0     0.2    -0.1    9|9      36|47    -527|364   -294   -0.0025  
    LYB    713    3359    21.2    0.24     0.2   79|94      5|12     -35|34     -28   -0.0026  
                     ... 370 midrange rows omitted, x_high_low is 12 ...  
    APC   -685    2607   -26.3    -0.3     0.3   79|100     6|4      -33|0      -26   -0.0026  
    BHI   -692    3282   -21.1   -0.24     0.3   55|70     18|11     -47|51     -38   -0.0026  
    HAR   -705    2603   -27.1   -0.31     0.3   81|104     10|6     -32|0      -25   -0.0026  
    DAL   -730    3496   -20.9   -0.24     0.4   28|38     33|18     -95|89     -70   -0.0026  
2014-05-08 13:00 _ti:963 INFO _  
 **BEAM   -731    3308   -22.1   -0.26    -1.0    67|0      5|6      -40|39       0         0  
    ANF   -832    3497   -23.8   -0.27     0.1   32|36     26|22     -81|77      73    0.0026  
   GMCR   -842    2551   -33.0   -0.49     0.3   80|104     6|8      -32|0      -27   -0.0028  
     LM   -919    3191   -28.8   -0.33     0.1   43|48     24|13     -65|60     -56   -0.0026  
    ATI  -1033    3066   -33.7   -0.38     0.2   35|42     26|13     -82|88     -63   -0.0026  
   QCOR  -1081    3604   -30.0   -0.34     0.6   54|88     22|15     -52|43     -31   -0.0027  
    NBR  -1126    2701   -41.7   -0.47     0.5   17|26     33|24     -158|0    -102   -0.0026  
   SPLS  -1186    3757   -31.6   -0.36    -0.2   16|13     40|29    -238|232   -211   -0.0027  
                          New delisted securities marked ** - BEAM  

To be closing more positions, below I tried adding https://www.quantopian.com/posts/take-profit. That's mostly all this adds, except close, shorting and longs are also separated from each other, leverage can be controlled a little better that way.

To mess around on a larger scale, in contrast to that approach, at https://www.quantopian.com/posts/universal-pipeline-experimentation-learning, instead of T/F, it utilizes numeric values produced by pipeline, normalizing & adding them, and from the totals going long those that wind up with a positive sum and short those negative, proportional weights fed to Optimize and a nice way to get rolling with that if not already. Easy experimentation that removes some obstacles and takes care of a lot of the grunge work. Might be interesting to plug your factors into that for comparison or adopt some of its pieces of code over to here.