Skip to content

Instantly share code, notes, and snippets.

@josephdunn
Created July 24, 2012 23:51
Show Gist options
  • Save josephdunn/3173473 to your computer and use it in GitHub Desktop.
Save josephdunn/3173473 to your computer and use it in GitHub Desktop.
library(quantmod)
getSymbols('SPY')
expiry_idx <- options.expiry(SPY)
for (i in 2:length(expiry_idx)-1)
{
period_start <- index(SPY[expiry_idx[i] + 1])
period_end <- index(SPY[expiry_idx[i + 1]])
message('i is ', i, ', period start is ', period_start, ', period end is ', period_end)
subset_string <- paste0(period_start, '::', period_end)
period_subset <- SPY[subset_string]
period_min <- min(period_subset$SPY.Close)
period_max <- max(period_subset$SPY.Close)
message('period min is ', period_min, ', period max is ', period_max)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment