Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
First Algo on Quantopian using the Debt to Equity Ratio

Hi everyone,

I am a new member of the community and I have spent my time here as a mostly as a learner, trying to grasp new concepts through the lectures and tutorials. This algorithm is the result of my first 'hands-on experience' of the Algorithm API. Most of my code is based out of concepts taught in the tutorials and lectures so one might find this extremely rudimentary.

I use the most common financial ratio - the debt to equity ratio to create a long-short equity strategy, targetting the top and bottom 2000 stocks ranked on the basis of the debt/equity value. I noticed that Quantopian ranks the metric based on the numerical value. So a company with practically zero debt to equity ratio was ranked way below than it should ideally be. So I had to short the stocks with the top ranks and vice-versa.

The algorithm is backtested on a 5-year window starting Jan'13 and ending Jan'18. Although I couldn't beat the SPY benchmark in the backtest but I learnt a lot throughout the process of creating it and this definitely serves as a kickstart for many more such algorithms to come!

Please feel free to point out any mistakes that I might have committed and do give your suggestions on how this can be improved.

AJ

5 responses

Looks great! Just wanted to mention that since your strategy is long/short, the SPY is not the best benchmark since the SPY is long only. Comparing your strategy’s sharpe ratio to the sharpe ratio of the SPY during the same period might be a somewhat better comparison, though not really ideal either since again, the SPY is long only.

Thank you, Joakim for your valuable input. I will surely keep that in mind going forward with my long-short strategies. Could you link any similar algos/notebooks where I could see the implementation of the comparison of sharpe ratios?
Also, it feels awesome to get feedback from someone whose posts I have followed for a good period of time.

No worries AJ! I’m glad you like my posts. :)

Unfortunately I don’t know how to do that in the backtester, but what I tend to do is look at the ‘Volatility matched to benchmark’ graph in the Pyfolio tearsheet (leaving the benchmark to either the SPY or something broader). If the strategy performs better than the SPY, after it’s been adjusted to match the volatility of the SPY, I’m generally happy (though preferably a lot better). That to me is more of an apples to apples comparison.

Arnav, have a look at your strategy's alpha and beta stats. Beta represents how much of the returns can be attributed to long-market exposure. Alpha represents how much of the strategy return is unique to the market.

If you look at your returns chart, you can see it follows the same dips and bumps as SPY does. Since your beta is 0.37 and alpha is close to 0, this means you probably could have achieved more or less same result by simply investing 37% of your portfolio into SPY instead.

Ideally you want a beta as close to 0 as possible and an alpha that is as high as possible.

@ Joakim, thank you once again for this input. I will surely look at the mentioned graph the next time I compare it to the benchmark.

@Virdian, Thank you so much for your feedback...like I said, I am an absolute beginner here and ill be working more on my algos to get as pure an alpha, as I can.