This file contains hidden or 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 | |
""" | |
Example of using Keras to implement a 1D convolutional neural network (CNN) for timeseries prediction. | |
""" | |
from __future__ import print_function, division | |
import numpy as np | |
from keras.layers import Convolution1D, Dense, MaxPooling1D, Flatten | |
from keras.models import Sequential |
This file contains hidden or 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
# In my portfolio, I show how the popular Fama-MacBeth (1973) procedure is constructed in R. | |
# The procedure is used to estimate risk premia and determine the validity of asset pricing models. | |
# Google shows that the original paper has currently over 9000 citations (Mar 2015), making the methodology one of the most | |
# influential papers in asset pricing studies. It's used by thousands of finance students each year, but I'm unable to find a | |
# complete description of it from the web. | |
# | |
# While the methodology is not statistically too complex (although the different standard errors can get complex), | |
# it can pose some serious data management challenges to students and researchers. | |
# | |
# The goal of the methodology is to estimate risk premia in the financial markets. While newer, more sophisticated methods for |
This file contains hidden or 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
# Time Series Testing | |
import keras.callbacks | |
from keras.models import Sequential | |
from keras.layers.core import Dense, Activation, Dense, Dropout | |
from keras.layers.recurrent import LSTM | |
# Call back to capture losses | |
class LossHistory(keras.callbacks.Callback): | |
def on_train_begin(self, logs={}): | |
self.losses = [] |
This file contains hidden or 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
par(mar=c(0,0,0,0)) | |
plot(0,0,xlim=c(0,28),ylim=c(0,1), | |
xaxt="n",yaxt="n",bty="n",xlab="",ylab="",type="n") | |
i <- 1 | |
for(j in 1:20) | |
{ | |
test <- (6+j):26 | |
train <- 1:(5+j) | |
arrows(0,1-j/20,27,1-j/20,0.05) | |
points(train,rep(1-j/20,length(train)),pch=19,col="blue") |
This file contains hidden or 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
library(quantmod) | |
library(PerformanceAnalytics) | |
library(TTR) | |
############################################################### | |
### User Input ################################################ | |
############################################################### | |
getSymbols("SPY", from = "1900-01-01", to="2012-06-01") | |
close <- SPY$SPY.Close |
This file contains hidden or 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
#' Read xlsx files | |
#' | |
#' @param file The path to xlsx file | |
#' @param keep_sheets A vector of sheet name | |
#' @param header Whether include the head in the sheet | |
#' @param empty_row Whether to remove the empty rows | |
#' @export | |
xlsxToR <- function(file, keep_sheets = NULL, header = TRUE, empty_row = TRUE) | |
{ | |
suppressWarnings(file.remove(tempdir())) |
This file contains hidden or 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
# The MIT License (MIT) | |
# | |
# Copyright (c) 2012 Schaun Jacob Wheeler | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: |
This file contains hidden or 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
#' Read xlsx files | |
#' | |
#' @param file The path to xlsx file | |
#' @param keep_sheets A vector of sheet name | |
#' @param header Whether include the head in the sheet | |
#' @param empty_row Whether to remove the empty rows | |
#' @export | |
xlsxToR <- function(file, keep_sheets = NULL, header = TRUE, empty_row = TRUE) | |
{ | |
suppressWarnings(file.remove(tempdir())) |