Back to Community
percent returns does not match

Hello i have tried to calculate 30 days percent returns for AAPL in 4 different ways and none of them match with the others.

can someone help me to figure out this? i think i am not using properly the resample method
Thank you
.Giuseppe

Loading notebook preview...
Notebook previews are currently unavailable.
5 responses

Hi Giuseppe,

There are a few differences between how get_pricing() and pipeline work. Currently, get_pricing() is split adjusted from the end_date of the get_pricing() call whereas pipeline prices are split AND dividend adjusted from the date for which the function is being called (see this post for more detail).

That being said, this distinction isn't actually the cause of what you are seeing. Another distinction between pipeline and get_pricing() is that get pricing includes data up to and including the end_date whereas pipeline only has pricing data up to "yesterday's" date in the simulation (I hope that makes sense). Because of this, there is an off-by-one discrepancy between your pipeline and get_pricing values.

Additionally, in the monthly returns, you are looking back 30 days in pipeline (for example, (day29 - day0)/day0), but with get_pricing, you are doing pct_change(30), which gets you 30 percent changes. This actually makes the calculation (day30-day0)/day0, which is slightly different than the pipeline version.

I've attached a copy of your notebook with the corrections. I hope this helps!

Loading notebook preview...
Notebook previews are currently unavailable.
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Where can we find details of your dividend adjustment method please? Is it by subtraction or is it proportional?

It is proportional. We look at the value of the dividend and what % of the share pice it is, and then use that ratio to make the historical adjustments. I am not sure if there is documentation on it anywhere, but will ask and let you know.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

thank you Jamie actually if i take the pipeline df and add .shif(-1) to them i have much more close values to the get_pricing.

i am doing some exercises following your answer and i have found this other new resample problem that i don't understand even after reading the pandas doc:

i thought that resample with no functions just returns the exact values of the original data resampled, not shifted nor modified, and instead of that i see that my results are unexpected, on the contrary if i resample my data using asfreq() i have the desired outcome.

So it guess that resample performs some functions to the data even if no functions is specified, because prices in the resampled series are not even in the original data.

Can someone help me to understand that please?

Loading notebook preview...
Notebook previews are currently unavailable.

My error was not specifying the parameter how wich had to be ='first' for what i wanted to achieve.
However i still do not understand what kind of function pandas apply if you don't assign any value to the how parameter