The function cumsum() is used to calculate cumulative product of arithmetic returns
You write about product but use cumsum() in calculations.
data['cumulative_arithmetic_return'] = (1 + data['arithmetic_return']).cumprod()
You write about product but use cumsum() in calculations.
data['cumulative_arithmetic_return'] = (1 + data['arithmetic_return']).cumprod()
Hi Litvin,
Could you please tell us in which course you find this error so that we can rectify this as soon as possible.
Thanks
Quantra Short Selling Resources/Section 4 Return Calculation
At the end of the notebook the author makes conclution that
"Log returns are time-additive. That is, n-period log return can be calculated by adding the consecutive single period log returns which is not possible for simple arithmetic returns. This makes manipulations much easier."
but in the code he does cumsum() for arithmetic returns.
Well, this is the problem with the Forums; there should be a way to specify which course your question is about, and then filter for such questions when searching the forum. As it is all the forum posts are randomly ordered. This could be much better structured. Also, if we have purchased a course it would make sense that when we asked a question that the actual author of the course (in this case Mr. Bernut) was reviewing and answering the question personally.
@Konstantin The arithmetic returns are calculated by adding the series of returns. But if the arithmetic returns are applied to calculate the time-series returns then it will give a false picture. Let's understand this with an example below. Consider the portfolio value moving from 100 to 150 and back to 100. This is a hypothetical situation.
The arithmetic returns show a 50% increase in portfolio value and then a 33% fall in portfolio value. When adding this, it shown a 17% increase in portfolio value. As you know this is far from true as there is no change in the portfolio value. Compared to this, the log return is able to capture the movement in the portfolio value.
Day | Portfolio Value | Arithmetic Returns | Log Returns |
1 | 100 | ||
2 | 150 | 50% | 41% |
3 | 100 | -33% | -41% |
Total | 17% | 0% |