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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <math.h> | |
int main ( int argc, char *argv[] ) | |
{ | |
int n, r, k; | |
n = atoi(argv[1]); // # of available elements | |
k = atoi(argv[2]); // # of permutation index | |
r = atoi(argv[3]); // # of elements to be selected |
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) | |
#get index tickers without the ^ which we will add in the getSymbols | |
tckrs=c("GSPC","TNX","DJUBS","W3DOW","W5DOW") | |
#name the indexes | |
names(tckrs) <- c("S&P 500","US 10y Yld","DJ Commodity","Developed","Developing") | |
#use paste to add the ^ to the index tickers | |
getSymbols(paste("^",tckrs,sep=""), from="1986-01-01", to=Sys.Date()) |
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
library(quantmod) | |
# we're pulling the Google VIX index (VXGOG) but this also works for VXAPL, VXGS etc. | |
# see http://www.cboe.com/micro/equityvix/introduction.aspx | |
url <- "http://www.cboe.com/publish/ScheduledTask/mktdata/datahouse/VXGOGDailyPrices.csv" | |
# use read.zoo to read the data directly into a zoo object | |
z <- read.zoo(url, header=TRUE, sep=",", skip=1, FUN=as.Date, format="%m/%d/%Y") | |
# convert to xts |
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
objSize <- function(n=10, decreasing=TRUE) { | |
# list 'n' objects, sorted by size | |
l <- ls(envir=parent.frame()) | |
N <- seq(min(length(l),n)) | |
x <- setNames(lapply(l, object.size), l) | |
y <- x[order(unlist(x),decreasing=decreasing)] | |
z <- sapply(y, function(a) capture.output(print(a, units="auto"))) | |
return(z[N]) | |
} |
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
nonIndexAttr <- function(x) { | |
a <- attributes(x) | |
n <- names(a)[!names(a) %in% "index"] | |
a[sort(n)] | |
} |
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
/* Copyright (C) 2017 Joshua M. Ulrich | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
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
> f <- function(...) { | |
+ promises(environment()) | |
+ } | |
> g <- function(x = 3, ...) { | |
+ z <- 4 | |
+ f(z = z, ..., x = x) | |
+ } | |
> h <- function(..., a = 2) { |
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
library(xts) | |
library(microbenchmark) | |
set.seed(21) | |
m <- matrix(1,5e6,50) | |
x <- .xts(m,1:nrow(m)) | |
i <- sort(sample(nrow(m),2e4)) | |
j <- sample(50, 10) | |
I <- i[1] | |
J <- j[1] | |
microbenchmark(m[i,], x[i,], unit="us") # faster than matrix for rows |
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
/* | |
* Copyright (C) 2017 Joshua M. Ulrich | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
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
recplot <- function(var, rec.ind, maintitle = "", ylab = "", ylim = NULL) | |
{ | |
# Give each recession a separate number, so we can split data by recession | |
# and calculate the necessary values to pass to addPolygon() for shading | |
r <- rle(as.integer(rec.ind)) | |
r$values[r$values > 0] <- seq_len(sum(r$values)) | |
rec <- xts(inverse.rle(r), index(rec.ind)) | |
# Merge variable and recession data, as a left-join so we do not have | |
# observations that only exist in the recession indicator data |
OlderNewer