Running Weekly, monthly, Quarterly Returns for S&P500

65 Views Asked by At

I have a DataFrame containing Date as an index and S&P500 closing prices.

Next I compute % change on Daily Basis

data["daily_return"] = data["Close"].pct_change()

I can compute Returns as follows:

data_weekly = 100*data["daily_return"].resample("W").agg(lambda x: (x + 1).prod() - 1)
dwk['SP500'] = data_weekly 

Resample shrinks daily data into smaller weekly data. Instead How do I compute running Weekly Return, i.e., I need to see partial weekly returns every week that gets reset at the beginning of the week or month etc?

I tried the following that yields useful info, but not quite the same info I am looking for

data_weekly = 100*data["daily_return"].resample("W").agg(lambda x: (x + 1).prod() - 1)
dwk['SP500'] = data_weekly 
0

There are 0 best solutions below