python - Compute weekly returns from daily returns using Wed-to-Wed convention in pandas -


i'm python/pandas newbie. have data set looks following:

                permno       date      gret   gvwretd date                                              2012-01-03   10001 2012-01-03  1.001751  1.016152 2012-01-04   10001 2012-01-04  0.989510  0.999553 2012-01-05   10001 2012-01-05  1.003525  1.002928 2012-01-06   10001 2012-01-06  0.997368  0.997093 2012-01-09   10001 2012-01-09  0.999117  1.002815 2012-01-10   10001 2012-01-10  1.003534  1.010420 2012-01-11   10002 2012-01-11  0.981074  1.000951 2012-01-12   10002 2012-01-12  0.993243  1.003046 2012-01-13   10002 2012-01-13  1.003175  0.994688 2012-01-17   10002 2012-01-17  1.013562  1.003904 2012-01-18   10002 2012-01-18  1.001784  1.012296 2012-01-19   10002 2012-01-19  0.995013  1.005580 2012-01-20   10002 2012-01-20  0.984428  1.000881 2012-01-23   10002 2012-01-23  1.017273  1.001606 2012-01-24   10002 2012-01-24  0.987489  0.999196 

i wednesdays of week, using df.resample('w-wed'), cannot merge them correctly original data set can compute cumulative product of returns week starting on wednesday permno , date.

how attack problem?

  1. should use 'date' index or 'date' column create indicators weeks starting on wednesday?
  2. the series of dates falling on wednesdays shorter original data set. how can merge , fill in correctly dates?

thank you

i seem have found solution after serious effort:

f = lambda x: x.prod() - 1 # cumulative product of returns ("gret": 1+ret) in each week each firm weekly_rets = df.groupby('permno').resample('w-wed', closed='left', how=f) 

i wrong in beginning thinking should create new data set containing dates fall on wednesday, , merge original, bigger data set, filling missing values appropriate wednesday dates create groupby variable.

am missing here?


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -