Extracting weekly or monthly data from a daily Daru time series

57 views Asked by At

I am trying to understand how to obtain weekly or monthly data from a daily Daru time series.

Given this sample time series:

require 'daru'

index = Daru::DateTimeIndex.date_range start: '2020-01-15',
  periods: 80, freq: 'D'

data = { price: Array.new(index.periods) { rand 100 } }
df = Daru::DataFrame.new data, index: index

I would like to:

  1. Create a new monthly data frame with only the last row in each month.
  2. Create a new weekly data frame with only the last row of each week.

In fact, I am not sure if I need to create a new data frame, or just query the original data frame.

The objective is to be able to plot weekly and monthly percentage change.

I am not even sure if this operation is something I am supposed to do on the index or on the data frame, so I am a bit lost in the documentation.

Any assistance is appreciated.

0

There are 0 answers