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
#Option 1 - install openblas with homebrew and link to CRAN installed R | |
brew tap homebrew/science | |
brew install openblas | |
ln -sf /usr/local/Cellar/openblas/0.2.12/lib/libopenblas.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib | |
#Option 2 - install r with openblas through homebrew | |
brew tap homebrew/science | |
brew install r --with-openblas |
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
#Code to re-create John Hussman's Recession warning index | |
#http://www.hussmanfunds.com/wmc/wmc110801.htm | |
#R code by Zach Mayer | |
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE | |
library(quantmod) | |
################################################# | |
# 1. Credit spreads | |
################################################# |
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
#Directory | |
setwd('~/wherever') | |
#Load Required Packages | |
library('caret') | |
library('glmnet') | |
library('ipred') | |
library('e1071') | |
library('caTools') |
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 Data | |
rm(list = ls(all = TRUE)) | |
library(quantmod) | |
library(PerformanceAnalytics) | |
symbols <- c('XLE','XLV','XLI','XLU','XLP','IYZ','XLK','XLY','XLF','XLB','GLD','SLV','EFA','EEM','FXA','FXE','FXY','HYG','LQD') | |
getSymbols(symbols,from='2007-01-01') | |
getSymbols('SPY',from='2007-01-01') |
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
################################################# | |
# Build a model | |
################################################# | |
#Choose Differencing window | |
#Hussman uses 6 months | |
Diff <- 6 | |
Data$PAYEMS <- (Data$PAYEMS-Lag(Data$PAYEMS,Diff))/Lag(Data$PAYEMS,Diff) | |
Data$UNRATE <- (Data$UNRATE-Lag(Data$UNRATE,Diff))/Lag(Data$UNRATE,Diff) | |
Data$SP500 <- (Data$SP500-Lag(Data$SP500,Diff))/Lag(Data$SP500,Diff) |
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
def dot_product(x, kernel): | |
""" | |
Wrapper for dot product operation, in order to be compatible with both | |
Theano and Tensorflow | |
Args: | |
x (): input | |
kernel (): weights | |
Returns: | |
""" | |
if K.backend() == 'tensorflow': |
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
getNews <- function(symbol, number){ | |
# Warn about length | |
if (number>300) { | |
warning("May only get 300 stories from google") | |
} | |
# load libraries | |
library(XML); library(plyr); library(stringr); library(lubridate); | |
library(xts); library(RDSTK) |
NewerOlder