Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Built-in factor Returns does not provide results as expected

I am confused about built-in factor "Returns". API doc says "class Returns(*args, **kwargs)
Calculates the percent change in close price over the given window_length." But when I use it, I do not get the result as expected. See my shared notebook "Calculate returns.ipynb". When I used Returns in the pipeline, I got 0.013365 for 'DDC'
2017-06-06 00:00:00+00:00 Equity(21 [AAME]) 0.000000
Equity(25 [ARNC_PR]) 0.000000
Equity(39 [DDC]) 0.013365

But when I used get_pricing to manually calculate the daily return for 'DDC', I got 0.077579519007. And I checked with Google Finance,
https://www.google.com/finance?q=ddc&ei=9C43WcnKCcGzjAGt4ZTQDA
confirmed that 0.077579519007 should be correct for 2017-06-06.
I wonder if the built-in factor is really correct, or how it should be used.

2 responses

Is this the only discrepancy you found or are all the values wrong?

You're confusing the dates when using pipeline.

In the notebook the pipeline was run on 2017-06-06. That implies that it is using data from the previous day 2017-06-05 (which was a Monday) so the return is calculated from the previous trading day 2017-06-02 (which was a Friday). The return is NOT calculated from 2017-06-05 to 2017-06-06.

The way I keep it straight is to think of the pipeline dates as the dates it is run and NOT the dates of the data. The pipeline always uses the previous days data.

See attached notebook.