1

I'm trying to use the following code to convert daily OHLCV data to weekly:

#resample so that Open is the first monday price, High and low are the weeks min and max and close is the last sunday price and volume is the sum (can be customized - pandas docs)

logic = {'Open'  : 'first',
         'High'  : 'max',
         'Low'   : 'min',
         'Close' : 'last',
         'Volume': 'sum'}

from pandas.tseries.frequencies import to_offset

BTC.resample('W').apply(logic)
BTC.index -= to_offset("6D")
BTC.head()

this prints a dataframe that is simply the original daily data with the date index offset by 6 days - with none of the logic applied. How can I successfully resample to weekly and apply the logic?

1 Answers1

1

You missed an assignment:

BTC = BTC.resample('W').apply(logic) # <-- here
BTC.index -= to_offset("6D")
BTC.head()

One more advice when analyzing financial data: use the Adjusted Close column instead of Close to account for splits, dividends, etc.

Code Different
  • 90,614
  • 16
  • 144
  • 163