So I've managed to backtest simple strategies, like MA, RSI and some fundamental ones (P/E ratios etc) but Im stuck at my last strategy. Here is some information:
Tools: Excel and Python (also a little familiar with R)
My strategy is based on 3 momentum factors:
- Weekly %net change in mean analyst reccommendations 1-5, where 1 is the best.
- Weekly %net change in mean analyst NTM EPS estimates, and
- Weekly % net change in stock price.
Every factor is equally weighted.
My stock Universe is the Nordics (Norway, Sweden, Denmark and Finland) where I filter on 3 month average volume and nr of analysts so that I end up with ~100 stocks as my final stock universe.
I have 20 years of weekly historical factor data downloaded from my data vendor. The file format is xls(excel). I guess (although not sure with all stocks) I can retrive the OHLC and volume data from Yahoo Finance with Pandas.
So the crude process is sketched out like this:
- Lookback period = t-1W
- Fetch all stocks in universe by reading CSV (Read from Yahoo with Pandas.io.data?)
- Read the excel file with all the factors for all the stocks (Work with xlwing, xlrdr, Pandas?)
- Compute Z-Score for all the factors for all stocks
- Aggregate the total Z-Score (AZS) for all stocks
- Eliminate outliers and Winsorize s.t. -3 >= AZS =< 3
- BUY top decile and SHORT bottom decile
From here I can either
- Equal Weight or,
- Weight with Expected Excess Return/Std.dev (SR): Where I calculate Expected Excess Return = IC * rank * vol where IC=0,05 (constant for all stocks), rank=Z-score rank and vol is the past 3 months volatility in %(stored in another excel file). std.dev is the past 3 years realized volatility (I know, the best would be to forecast std.dev with GARCH or similar)
- At t+1W, repeat step 1-9 and reweight if necessary.
I am a little familiar with the open source backtesters out there: bt, backtester.com, pyalgotrade and zipline. But perhaps my strategy is a bit more complicated to work out with these backtesters? Or can one use fex zipline to backtest this strategy? I don't know.