0

I would like to perform some factor backtesting in python using a rank analysis, i.e. rank all of the stocks in a certain month based on some factor (say P/E ratio, attractiveness of CEO etc.) and then report an aggregate percentile performance (as in top 10% on average return was x% etc.). There is a package that does exactly that in R:

https://cran.r-project.org/web/packages/backtest/vignettes/backtest.pdf

The packages bt in python are providing an overall performance rather than the performance of the individual buckets.

To reiterate, my main goal is to obtain the performance of the buckets. A lot of the backtesting packages for python only provide overall performance.

Niccola Tartaglia
  • 1,537
  • 2
  • 26
  • 40

1 Answers1

2

This questions is somewhat off-topic, but I have some experience with bt so I'll share my thoughts.

bt is a nifty library that makes a lot of assumptions about what you are trying to accomplish. Because of this, it isn't as robust as other backtesting libraries, but it still has its strengths. Foremost of these, IMO, is the ability to define strategies as trees.

To accomplish what you describe: factor backtesting using rank analysis, I would suggest the following.

  1. Perform all your ranking calculations
  2. Create buckets that separate the securities e.g. 10% buckets
  3. Using the Tree Structure for algorithms, construct a strategy that longs that top bucket and shorts the bottom
  4. Compare total strategy performance of different factors

If you really need to determine individual bucket performance, just split the securities into buckets and run a separate backtest for each.

bphi
  • 3,115
  • 3
  • 23
  • 36
  • Thank you so much bphi. Yeah, I thought about that approach but I was hoping there was already a package out there that would provide something similar. But it seems that this is the way to do it. I am going to leave the question open, in hopes that some might know of a package that does exactly what I need. Thanks again!! – Niccola Tartaglia Jun 25 '18 at 19:46