Quantitative Risk Management in R
Alexander McNeil
Professor, University of York
$$\ln(Z_{t+5}) - \ln(Z_t) = \sum_{i=1}^{5} X_{t+i} $$
sum()
function within apply.weekly()
and use apply.monthly()
in the xts
packagesp500x_w <- apply.weekly(sp500x, sum)
head(sp500x_w, n = 3)
^GSPC
1950-01-09 0.02489755
1950-01-16 -0.02130264
1950-01-23 0.01189081
$$ $$ $$ $$
sp500x_m <- apply.monthly(sp500x, sum)
head(sp500x_m, n = 3)
^GSPC
1950-01-31 0.023139508
1950-02-28 0.009921296
1950-03-31 0.004056917
Quantitative Risk Management in R