Skip to content

Instantly share code, notes, and snippets.

View timelyportfolio's full-sized avatar

timelyportfolio timelyportfolio

View GitHub Profile
#look at distance from the 3 month minimum
#to compare the magical US Russell 2000
#to the world
require(quantmod)
tkrs <- c("^W2DOW","^RUT")
getSymbols(tkrs,from="1896-01-01",to=Sys.Date())
#use Ken French momentum style indexes for style analysis
#http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/6_Portfolios_ME_Prior_12_2.zip
require(PerformanceAnalytics)
require(quantmod)
my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/6_Portfolios_ME_Prior_12_2.zip"
my.tempfile<-paste(tempdir(),"\\frenchmomentum.zip",sep="")
my.usefile<-paste(tempdir(),"\\6_Portfolios_ME_Prior_12_2.txt",sep="")
download.file(my.url, my.tempfile, method="auto",
@timelyportfolio
timelyportfolio / MAImp.r
Created November 29, 2011 15:31
Improved Moving Average R Function
# Function to implement a version of the improved moving average functionality
# introduced and tested in:
#
# Papailias, Fotis and Thomakos, Dimitrios D.,
# "An Improved Moving Average Technical Trading Rule,
# (September 11, 2011). Available at SSRN: http://ssrn.com/abstract=1926376
#
# Original code written by Kent Russell @ timelyportfolio.com
#
# Cross-checked by Dimitrios Thomakos on 11/29/2011, @ quantf.com
@timelyportfolio
timelyportfolio / MAImp.test.r
Created November 29, 2011 17:11
MAImp Sample
#get MAImp code from GIST
#thanks to http://systematicinvestor.wordpress.com
#for showing me how to do this
con=url("https://raw.github.com/gist/1405187/92e7c24ff2459a0830c45b828f1dba41143e9436/MAImp.r")
source(con)
require(quantmod)
require(PerformanceAnalytics)
getSymbols("^GSPC",from = "1896-01-01", to = Sys.Date())
require(ttrTests)
require(quantmod)
require(PerformanceAnalytics)
#simple price crossover moving average system
#style slightly different to conform to ttrTests
oneSMA <- function(x,params=10,burn=0,short=FALSE) {
mac2<-runMean(x,params[1])
sig<-ifelse(x>=mac2,1,0)
sig[is.na(sig)]<-0
#I very much appreciate Joshua Ulrich's (http://blog.fosstrading.com) forked version
#which offers a much nicer top section of the final graph
#forked version resides here https://gist.github.com/1443358
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")
@timelyportfolio
timelyportfolio / taleoftwo.r
Created December 9, 2011 17:19
Tale of Two Frontiers
require(quantmod)
require(PerformanceAnalytics)
require(PortfolioAnalytics)
require(fPortfolio)
require(ggplot2)
#read a csv file of returns
#unfortunately I cannot share
portfolio <- read.csv("iv stocks bonds international.csv",stringsAsFactors=FALSE)
portfolio <- portfolio[2:NROW(portfolio),2:NCOL(portfolio)]
#use Ken French market cap series
#http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/Portfolios_Formed_on_ME.zip
require(PerformanceAnalytics)
require(quantmod)
my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/Portfolios_Formed_on_ME.zip"
my.tempfile<-paste(tempdir(),"\\frenchsize.zip",sep="")
my.usefile<-paste(tempdir(),"\\Portfolios_Formed_on_ME.txt",sep="")
download.file(my.url, my.tempfile, method="auto",
@timelyportfolio
timelyportfolio / lattice explore vbmfx.r
Created December 16, 2011 20:58
lattice explore vbmfx
#lattice exploration of Vanguard Bond Fund (vbmfx)
#returns since 1990
require(quantmod)
require(lattice)
require(latticeExtra)
require(PerformanceAnalytics)
getSymbols("VBMFX",from="1896-01-01",to=Sys.Date(),adjust=TRUE)
@timelyportfolio
timelyportfolio / vustx forward and back.r
Created December 21, 2011 16:01
vustx forward and back
require(quantmod)
require(PerformanceAnalytics)
require(latticeExtra)
require(grid)
require(reshape)
tckr <- "VUSTX"
getSymbols(tckr,
from="1900-01-01", to=format(Sys.Date(),"%Y-%m-%d"),
adjust = TRUE)