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
/** | |
* @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> |
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
/** | |
* @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) |
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
# 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 |
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
# 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 |
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(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 |
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
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 |
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(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) |