This file contains hidden or 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
#further explore Japanese trade data by region | |
#website is http://www.customs.go.jp/toukei/suii/html/time_e.htm | |
#format is http://www.customs.go.jp/toukei/suii/html/data/d42ma001.csv | |
#and the filename increments from 001 to 008 for the geographic areas | |
require(quantmod) | |
numgeog <- 8 #there are really 9 but the last is "special area" | |
urls <- paste("http://www.customs.go.jp/toukei/suii/html/data/d42ma00", |
This file contains hidden or 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
#quick example of d3.js style calendar heat map | |
#thanks so much Paul Bleicher, MD PhD who is Chief Medical Officer | |
# at Humedica, a next-generation clinical informatics company | |
# that provides novel business intelligence solutions | |
# to the health care and life science industries | |
#discussed in Revolution Analytics blog post | |
#http://blog.revolutionanalytics.com/2009/11/charting-time-series-as-calendar-heat-maps-in-r.html | |
con=url("http://blog.revolution-computing.com/downloads/calendarHeat.R") | |
source(con) |
This file contains hidden or 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:First Attempt at a knitr Performance Report | |
## author:Timely Portfolio | |
require(PerformanceAnalytics) | |
require(xtable) | |
data(edhec) | |
table.CalendarReturns(edhec[,1:3])[13:15] | |
charts.PerformanceSummary(edhec[,1:3], | |
colorset=c("gray50","steelblue2","steelblue4"), |
This file contains hidden or 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(knitr) | |
knit2pdf("performance summary.rnw") |
This file contains hidden or 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
%% LyX 2.0.2 created this file. For more info, see http://www.lyx.org/. | |
%% Do not edit unless you really know what you are doing. | |
\documentclass[english,nohyper,noae]{tufte-handout} | |
\usepackage{helvet} | |
\usepackage[T1]{fontenc} | |
\usepackage[latin9]{inputenc} | |
\usepackage{babel} | |
\usepackage[unicode=true,pdfusetitle, | |
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=1, | |
breaklinks=true,pdfborder={0 0 0},backref=false,colorlinks=false] |
This file contains hidden or 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) | |
require(PerformanceAnalytics) | |
getSymbols("VFINX",from="1990-01-01",adjust=TRUE) | |
getSymbols("VBMFX",from="1990-01-01",adjust=TRUE) | |
perf <- na.omit(merge(monthlyReturn(VBMFX[,4]),monthlyReturn(VFINX[,4]))) | |
colnames(perf) <- c("VBMFX","VFINX") | |
#get 8 month RSI; randomly picked 8; no optimization | |
rsi<- lag(merge(RSI(perf[,1],n=8),RSI(perf[,2],n=8)),k=1) | |
#allocate between vbmfx and vfinx based on highest RSI |
This file contains hidden or 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) | |
require(PerformanceAnalytics) | |
getSymbols("VFINX",from="1990-01-01",adjust=TRUE) | |
getSymbols("VBMFX",from="1990-01-01",adjust=TRUE) | |
perf <- na.omit(merge(monthlyReturn(VBMFX[,4]),monthlyReturn(VFINX[,4]))) | |
colnames(perf) <- c("VBMFX","VFINX") | |
#get 8 month RSI; randomly picked 8; no optimization | |
rsi<- lag(merge(RSI(perf[,1],n=8),RSI(perf[,2],n=8)),k=1) | |
#allocate between vbmfx and vfinx based on highest RSI |
This file contains hidden or 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 breakpoints with the R package bfast | |
#please read the paper | |
#Verbesselt J, Hyndman R, Newnham G, Culvenor D (2010) | |
#Detecting Trend and Seasonal Changes in Satellite Image Time Series. | |
#Remote Sensing of Environment, 114(1), 106–115. | |
#http://dx.doi.org/10.1016/j.rse.2009.08.014 | |
require(bfast) | |
require(quantmod) |
This file contains hidden or 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 breakpoints in realtime with the R package bfast | |
#please read the paper | |
#Jan Verbesselt, Achim Zeileis, Martin Herold (2011). Near Real-Time Disturbance | |
#Detection in Terrestrial Ecosystems Using Satellite Image Time Series: Drought | |
#Detection in Somalia. Working Paper 2011-18. Working Papers in Economics and | |
#Statistics, Research Platform Empirical and Experimental Economics, Universitaet | |
#Innsbruck. URL http://EconPapers.RePEc.org/RePEc:inn:wpaper:2011-18 | |
#http://scholar.google.com/scholar?cluster=9016488513865299942&hl=en&as_sdt=0,1 | |
#install r-forge development version of bfast |
This file contains hidden or 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
#thanks so much to the developers of quantstrat | |
#99% of this code comes from the demos in the quantstrat package | |
#now let's define our silly countupdown function | |
CUD <- function(price,n) { | |
#CUD takes the n-period sum of 1 (up days) and -1 (down days) | |
temp<-runSum(ifelse(ROC(price,1,type="discrete") > 0,1,-1),n) | |
colnames(temp) <- "CUD" | |
temp | |
} |