Skip to content

Instantly share code, notes, and snippets.

@rbresearch
rbresearch / Quandl_rev1.R
Last active January 21, 2016 04:40
Revised quandl to allow for loading multiple symbols
library(RJSONIO)
library(xts)
Quandl <- function(code, env = .GlobalEnv, type = c('raw', 'ts', 'zoo', 'xts'), start_date, end_date, transformation = c('', 'diff', 'rdiff', 'normalize', 'cumul'), collapse = c('', 'weekly', 'monthly', 'quarterly', 'annual'), rows, authcode = Quandl.auth()) {
## Flag to indicate frequency change due to collapse
freqflag = FALSE
# remove everything before the "/" for assigning the symbols to variable names
sym.names <- gsub(".*/", "", code)
@rbresearch
rbresearch / Quandl.R
Created March 23, 2013 21:39
Quandl API example for R
Quandl <- function(Symbols, env=.GlobalEnv, from="2000-01-01", to=Sys.Date(), auth=NULL) {
# Function to pull data using the quandl API
# Returns an xts object
# Input Args
# Symbols : character vector of quandl codes of the datasets you want to retrieve
# from : character vector of the start date in yyyy-mm-dd
# to : character vector of the end date in yyyy-mm-dd
# auth : authentication toke for quandl API access www.quandl.com/api
# Base url for the quandl api
@rbresearch
rbresearch / server.R
Created March 4, 2013 12:20
Shiny with Performance Analytics Example
library(shiny)
library(PerformanceAnalytics)
data(managers)
# Define server logic required to plot relative performance
shinyServer(function(input, output) {
# Use charts.PerformanceSummary from Performance Analytics package
# to generate a performance summary plot
@rbresearch
rbresearch / etf-replay-rank-backtest.R
Created January 28, 2013 04:20
etfReplayRank backtest
# Backtest of ETF Replay Ranking Algorithm
# clear the workspace
rm(list=ls())
# step-by-step example of ETF Replay Ranking Algorithm
##### etfReplayRank Function #####
# we can use the same step-by-step approach outlined above to write a function
# to rank instruments based on ETF Replay
@rbresearch
rbresearch / etfReplayRank.R
Created January 27, 2013 21:30
implementation of ranking algorithm similar to ETF Replay
# Ranking Algorithm for ETF Replay
# Rank based on 3 factors
# 1. ReturnA (ret1)
# 2. ReturnB (ret2)
# 3. Volatility (vol)
# Returns are ranked from high to low
# Volatility is ranked from low to high
@rbresearch
rbresearch / 2012-12-23-sugar-diff.cpp
Created December 23, 2012 16:00
Example of using the Rcpp sugar function diff()
/**
* @title Using Sugar Function diff()
* @author Ross Bennett
* @license GPL (>= 2)
* @tags sugar, diff
* @summary Illustrates the use of sugar function diff()
*/
/**
* The sugar function diff() computes the difference of consecutive elements (i.e. lag = 1)
@rbresearch
rbresearch / 2012-12-22-vector-cumulative-sum.cpp
Created December 22, 2012 18:18
Examples to compute the cumulative sum of a vector
/**
* @title Using Sugar Function cumsum()
* @author Ross Bennett
* @license GPL (>= 2)
* @tags sugar cumsum
* @summary Demonstrates different ways to compute the cumulative
* sum of a vector and illustrates the use of sugar function cumsum().
*/
#include <Rcpp.h>