This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Download S&P 500 data, adjust, and conver to monthly | |
set.seed(42) | |
library(quantmod) | |
getSymbols('^GSPC', from='1990-01-01') | |
GSPC <- adjustOHLC(GSPC, symbol.name='^GSPC') | |
GSPC <- to.monthly(GSPC, indexAt='lastof') | |
Target <- ClCl(GSPC) | |
#Calculate some co-variates | |
periods <- c(3, 6, 9, 12) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Multi-Class Summary Function | |
#Based on caret:::twoClassSummary | |
require(compiler) | |
multiClassSummary <- cmpfun(function (data, lev = NULL, model = NULL){ | |
#Load Libraries | |
require(Metrics) | |
require(caret) | |
#Check data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls(all = TRUE)) | |
memory.limit(size = 4095) | |
#Get Data | |
library(quantmod) | |
getSymbols('^GSPC',from='1900-01-01') | |
myStock <- Cl(GSPC) | |
bmkReturns <- dailyReturn(myStock, type = "arithmetic") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages(c('caret', 'doParallel', 'ggplot2', 'data.table', 'caTools', 'XML', 'quantmod'), dependencies=TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Setup | |
rm(list = ls(all = TRUE)) | |
setwd('path.to/cv.ts') | |
#Load Packages | |
require(forecast) | |
require(doParallel) | |
source('R/cv.ts.R') | |
source('R/forecast functions.R') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setClass("parDEoptim", representation(optim="list", member="list")) | |
parDEoptim <- function (fn, lower, upper, n=1, control = DEoptim.control(), .packages=NULL, ...) { | |
library("DEoptim") | |
library("foreach") | |
segSizes <- (upper-lower)/n | |
segments <- lapply(1:n, function(x){ | |
lower+segSizes*(x-1) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Function to cross-validate a time series. | |
cv.ts <- function(x, FUN, tsControl, xreg=NULL, ...) { | |
#Load required packages | |
stopifnot(is.ts(x)) | |
stopifnot(is.data.frame(xreg) | is.matrix(xreg) | is.null(xreg)) | |
stopifnot(require(forecast)) | |
stopifnot(require(foreach)) | |
stopifnot(require(plyr)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Function to cross-validate a time series. | |
cv.ts <- function(x, FUN, tsControl, xreg=NULL, ...) { | |
#Load required packages | |
stopifnot(is.ts(x)) | |
stopifnot(is.data.frame(xreg) | is.matrix(xreg) | is.null(xreg)) | |
stopifnot(require(forecast)) | |
stopifnot(require(foreach)) | |
stopifnot(require(plyr)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
#Constants.R | |
#Created by Kenneth J. Shackleton on 14 June 2011. | |
#Copyright (c) 2011 Ringo Limited. | |
#All rights reserved. | |
#R Port by Zach Mayer on 4 December 2011 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Setup | |
set.seed(1) | |
library(fpp) # To load the data set a10 | |
HZ <- 12 | |
myControl <- list( minObs=60, | |
stepSize=1, | |
maxHorizon=HZ, |