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
<html> | |
<head> | |
<title>Test</title> | |
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/> | |
<meta name="apple-mobile-web-app-capable" content="yes" /> | |
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> | |
<link rel="apple-touch-icon" href="icon.png"/> | |
<style type="text/css"> | |
body{ margin: 0px;} | |
</style> |
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
#Load the dataset, adjust, and convert to monthly returns | |
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) |
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)) |