library(armacmp)
# Arnold, T., Kane, M., & Lewis, B. W. (2019). A Computational Approach to Statistical Learning. CRC Press.
# logistic regression using the Newton-Raphson
log_reg <- armacmp(function(X, y) {
beta <- rep.int(0, ncol(X))
for (i in seq_len(25)) {
b_old <- beta
alpha <- X %*% beta
p <- 1 / (1 + exp(-alpha))
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
# to run this firstly set up the MinIO server | |
# on Windows download this https://dl.min.io/server/minio/release/windows-amd64/minio.exe | |
# download("https://dl.min.io/server/minio/release/windows-amd64/minio.exe") | |
# to run minio make sure the executable is in the PATH | |
# then run | |
# ;minio.exe server /path/to/minio/data | |
# e.g. minio.exe server c:/minio-data/ | |
using Minio, Parquet, Parquet2, DataFrames, AWSS3 |
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
require(quantmod) | |
do_chart <- function(symbol) { | |
quote <- getQuote(symbol) | |
quote$Close <- quote$Last | |
xts(OHLCV(quote), quote[,"Trade Time"], | |
pct_change = quote[,"% Change"]) | |
} | |
filename <- "intraday-sp500.rds" |
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
# Instructions for 4.14 and cuda 9.1 | |
# If upgrading from 4.13 and cuda 9.0 | |
$ sudo apt-get purge --auto-remove libcud* | |
$ sudo apt-get purge --auto-remove cuda* | |
$ sudo apt-get purge --auto-remove nvidia* | |
# also remove the container directory direcotory at /usr/local/cuda-9.0/ | |
# Important libs required with 4.14.x with Cuda 9.X | |
$ sudo apt install libelf1 libelf-dev |
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
# Add rowwise summary lines to ggplot2::facet_grid style plots. | |
# Andy Barbour | |
# geokook.wordpress.com | |
# December 2012 | |
## clear workspace | |
rm(list=ls()) | |
library(multitaper) | |
library(rbenchmark) |
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
svmComputeOneForecast = function( | |
id, | |
data, | |
response, | |
startPoints, | |
endPoints, | |
len, | |
history=500, | |
trace=FALSE, | |
kernel="radial", |
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
# Starting with categorical data, ending with a table of log odds ratios | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("plyr", "reshape2") | |
if(doInstall){install.packages(toInstall, | |
repos = "http://cran.us.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Canonical example of categorical data | |
HEC <- melt(HairEyeColor) |
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
# Let's say you want to display a table of model coefficients | |
# in order of their significance, | |
# and you want to plot the distribution of model residuals, | |
# but you don't know how to access these values. | |
# Use str(). | |
# Generate some random data | |
NN <- 1000 | |
theData <- data.frame(Alpha = rnorm(NN), | |
Beta = rnorm(NN)) |
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
require(PerformanceAnalytics) | |
require(quantmod) | |
getSymbols("^GSPC", from = "1900-01-01") | |
#get return series from closing price | |
ret.bh <- ROC(GSPC[,4],n = 1,type = "discrete") | |
#change first value from NA to 0 | |
ret.bh[1,] <- 0 |
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
#analyze asset allocation experience in Spain | |
require(lattice) | |
require(latticeExtra) | |
require(reshape2) | |
require(directlabels) | |
require(quantmod) | |
require(PerformanceAnalytics) | |
require(RQuantLib) |
NewerOlder