Skip to content

Instantly share code, notes, and snippets.

View zachmayer's full-sized avatar

Zach Deane-Mayer zachmayer

View GitHub Profile
#Setup
rm(list = ls(all = TRUE))
gc(reset=TRUE)
set.seed(42) #From random.org
#Libraries
library(caret)
library(devtools)
install_github('caretEnsemble', 'zachmayer') #Install zach's caretEnsemble package
@zachmayer
zachmayer / WebScrape.R
Created August 10, 2011 13:28
Scrape Web Data
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE
library(quantmod)
#Scrape data from the website
library(XML)
rawPMI <- readHTMLTable('http://www.ism.ws/ISMReport/content.cfm?ItemNumber=10752')
PMI <- data.frame(rawPMI[[1]])
names(PMI)[1] <- 'Year'
#Reshape
@zachmayer
zachmayer / additional demos.R
Created November 21, 2011 15:52
Functional and Parallel time series cross-validation
#Setup
set.seed(1)
library(fpp) # To load the data set a10
HZ <- 12
myControl <- list( minObs=60,
stepSize=1,
maxHorizon=HZ,
#Setup
rm(list = ls(all = TRUE))
gc(reset=TRUE)
set.seed(1234) #From random.org
#Libraries
library(caret)
library(devtools)
install_github('caretEnsemble', 'zachmayer') #Install zach's caretEnsemble package
library(caretEnsemble)
@zachmayer
zachmayer / cv.ts 4.R
Created June 11, 2012 17:52
Time series cross-validation 4: forecasting the S&P 500
#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')
@zachmayer
zachmayer / 2.15.sh
Last active December 19, 2015 14:09
cd /Library/Frameworks/R.framework/Resources/lib
# for vecLib use
ln -sf libRblas.vecLib.dylib libRblas.dylib
# for R reference BLAS use
ln -sf libRblas.0.dylib libRblas.dylib
@zachmayer
zachmayer / multiRF.R
Created May 10, 2013 13:26
A better multiRFfunction
multiRF <- function(X, Y, mtry_vector,...) {
stopifnot(require(doRNG))
stopifnot(require(randomForest))
stopifnot(is.numeric(mtry_vector))
stopifnot(all(mtry_vector>1))
foreach(i=mtry_vector,.combine=randomForest::combine,.packages='randomForest',.export=c('X','Y'),.inorder=FALSE) %dorng% {
<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>
#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)
#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)