python - Calculating cumulative returns -


i have calculated daily returns market data , trying add each of returns in accumulation column (cum_rets). here's sample of data:

    timestamp   dash_cap    litecoin_cap    dogecoin_cap    nxt_cap total_mc    dal_rets 0   2014-02-14  702537  410011811   80883283    61942277    553539908   nan 1   2014-02-15  1054625 413848776   73684156    59127182    547714739   -1.052349 2   2014-02-17  1882753 407014106   70512004    59753481    539162344   -1.561469 3   2014-02-18  3766068 398556278   69890414    60219880    532432640   -1.248178 4   2014-02-19  3038521 404855950   71588924    59870181    539353576   1.299871 

i don't understand why, when use code:

merged['cum_rets'] = 0 merged['cum_rets'] = merged['cum_rets'].shift(1) + merged.dal_rets merged 

it returns

    timestamp   dash_cap    litecoin_cap    dogecoin_cap    nxt_cap total_mc    dal_rets    cum_rets 0   2014-02-14  702537  410011811   80883283    61942277    553539908   nan nan 1   2014-02-15  1054625 413848776   73684156    59127182    547714739   -1.052349   -1.052349 2   2014-02-17  1882753 407014106   70512004    59753481    539162344   -1.561469   -1.561469 3   2014-02-18  3766068 398556278   69890414    60219880    532432640   -1.248178   -1.248178 

merged['cum_rets'].shift(1) should retrieve previous value cum_rets , add current value of dal_ret incrementally sumating values in dal_rets. know use .cumprod() i'd learn why method doesn't work

merged['cum_rets'].shift(1) should retrieve previous value cum_rets , add current value of dal_ret

is correct. however, conclusion

thus incrementally sumating values in dal_rets

is not.

the expression

 = b + c 

treats a, b, , c distinct arrays in sense first adds b , c, assigns results a. doesn't matter if a , b refer same thing.


incidentally, want here cumsum, not cumprod.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -