Frequency resampling primer
Risk factor models often rely upon data that is of different frequencies. A typical example is when using quarterly macroeconomic data, such as prices, unemployment rates, etc., with financial data, which is often daily (or even intra-daily). To use both data sources in the same model, higher frequency data needs to be resampled to match the lower frequency data.
The DataFrame and Series Pandas objects have a built-in .resample() method that specifies the lower frequency. This method is chained with a method to create the lower-frequency statistic, such as .mean() for the average of the data within the new frequency period, or .min() for the minimum of the data.
In this exercise you'll practice converting daily returns data to weekly and quarterly frequency.
Cet exercice fait partie du cours
Quantitative Risk Management in Python
Instructions
- Convert 
returnsto quarterly frequency averagereturns_qusing the.resample()and.mean()methods. - Examine the header of 
returns_q, noting that the.resample()method takes care of the date index for you. - Now convert 
returnsto weekly frequency minimumreturns_w, using the.min()method. - Examine the header of 
returns_w. 
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Convert daily returns to quarterly average returns
returns_q = returns.____('Q').____
# Examine the beginning of the quarterly series
print(returns_q.____)
# Now convert daily returns to weekly minimum returns
returns_w = ____.resample('W').____
# Examine the beginning of the weekly series
print(returns_w.____)