Back to Community
Contest 32 entries

Here's my first.

Care to share yours?

Grant "Off-White Seal" Kiehne

NOTE: backtest is not loading--I've sent a request to Q support to look into the problem.

Clone Algorithm
29
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5971d6ebfcc2375381bbf751
There was a runtime error.
12 responses

And the second.

Any ideas for a third one?

Clone Algorithm
5
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 597487fb8d32cc4e1a9de7c6
There was a runtime error.

I also recently had backtest that just wouldn't load on a forum post. It eventually did.

Here's a shorter backtest of my first Contest 32 entry--flat, but if the market turns down, it should do o.k.

Clone Algorithm
29
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5974c189b6098e4e01316760
There was a runtime error.

Grant,

Interesting template for similar algorithms. You missed something though. You need to rank the combined_alpha before taking long short like this:

combined_alpha = combined_alpha.rank(ascending=False)  
longs = combined_alpha.top(NUM_LONG_POSITIONS)  
shorts = combined_alpha.bottom(NUM_SHORT_POSITIONS)  

When the backtest wasn't loading in a preview, I canceled the preview and hit the preview button again before posting. Sometimes that works.

Pravin -

Note that the output of each factor is passed though a preprocessing function prior to combination:

def preprocess(a):  
    a = np.nan_to_num(a - np.nanmean(a))

    return zscore(rankdata(a))  

It demeans, ranks, and then z-scores. So, the combined alpha is a linear combination of z-scores of ranks. It is not clear to me that then ranking the combined alpha would be the right thing to do, since the alphas have already been individually ranked and then normalized with a z-score. If the stock universe is the same for all factors, the z-score just effectively demeans the ranks, since the standard deviation in the denominator will be the same across all factors. However, if the stock universe varies by factor, then combining ranks won't work, since large-universe factors will be weighted more heavily in the combination; z-scoring fixes this problem (although as my code is written, I'm not sure that I could have variability in the stock universe across factors).

Regarding the idea of a generic long-short multi-factor template, Quantopian has a repository for this sort of thing. For example, see:

https://github.com/quantopian/research_public/blob/master/template_algorithms/long_short_equity_template.py

My sense is that they might welcome user-contributed content. It would make sense to architect a template is such a way that it would be compatible with more sophisticated alpha combination steps, such as machine learning (for example, see this post by Thomas Wiecki). Also, being able to combine pipeline-based alpha factors and non-pipeline derived ones (e.g. based on minute bars) should be an objective, too (apparently, this is tricky, since Pipeline only returns the most recent alpha factor values, not a trailing history).

I guess the Q crew is busy with other stuff, but a really well-engineered template would be the natural outcome of the framework provided by Jonathan Larkin, A Professional Quant Equity Workflow.

Grant,

I had noticed from one of your other posts how you do the rank then z score. And it kind of confused me?

What's the point of doing both, wouldn't you be better off just doing the rank or doing the z score? A ranked list won't be a normal distribution so I don't think the z score off that does much.

One thought I had is that you may be trying to soften the extremes? One trick I found is to explicitly remove them or set their z score to 2, or negative 2 to soften them.

Also, I like your stocktwits factor! Track the companies that aren't talked about.

As I mentioned, I think that the ranking then z-scoring just demeans when the universe is the same across all factors. However, if the universe size varies by factor, then there is a normalization problem. For example, if one factor takes 2 stocks, then my ranking will be from 1 to 2. If another factor takes 10 stocks, then my ranking will be from 1 to 10. So, if I combine, without scaling the first factor, then effectively it will carry a lower weight.

Without the z-scoring of the demeaned ranked factors, I'd get values of -0.5 & +0.5 for my factor that takes two stocks. This corresponds to the very center of the distribution of factor values for my factor that takes 10 stocks. However, if I apply the z-scoring to the demeaned ranks, then my factor values for the small universe factor land where there should with respect to the factor that takes 10 stocks.

Basically, I think we're saying that even though I'm only feeding one factor two stocks, if I were to feed it 10, then it would have the same distribution of values (which it would, since we are using ranks).

If you write a little Excel spreadsheet, you can see how this works.

Well I see how it can work for a small universe/population but aren't you using a universe of ~1500 (which Quantopian apparently really wants us to use SP1500)? And if you have a universe that large then the rank first ends up softening your factor weighting. Picture a population of 1000 for easy math and you have a factor where a stock ranks 100th. But the way the distribution is that same stock with a z score could have +1. By ranking first then z scoring you're removing the normal distribution element. A linear list is not a normal distribution and therefore a z score off that linear list is not really appropriate.

I guess all I mean to say is that z score is most appropriate, in my opinion, and ranking doesn't give the full picture.

a z score off that linear list is not really appropriate

Yeah, you might be right. I agree that it is kinda half-baked. I'll have to think about that one. I suppose that one could demean the ranked data, and then divide by the max-min (i.e. range), but I bet this does the same thing as a z-score.

Overall, if one doesn't rank, then there has to be some other way of dealing with outliers. Winsorizing is something I played around with, which does this. There's also the logistic function (https://en.wikipedia.org/wiki/Logistic_function). Etc.

I submitted a variation of my Sector Bridesmaid algo to contest 32. I don't have any expectations -- it's kind of a dopey algo, but I just wanted to have a horse in the race and none of my better algos were submittable. But so far it's held its own -- been in the top 20 pretty much the whole time. This is fun keeping track of the progress -- very much like racing paper boats in the breeze.

One of my Contest 32 algos is doing pretty well - currently ranked 24. However, it's only been a month, so time will tell. I think it is reasonably well constructed relative to the Q fund requirements, so even if I don't make any money off of the contest, I hope to get some feedback from the Q fund team, if they are willing to take a look at it (assuming it doesn't fall completely flat over the next 5 months).