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
#!/bin/sh | |
### Make a directory to work from | |
mkdir -p ~/dev/R-libs | |
cd ~/dev/R-libs | |
### Check out source trees | |
svn co svn://svn.r-forge.r-project.org/svnroot/zoo/pkg/zoo | |
svn co svn://svn.r-forge.r-project.org/svnroot/xts/pkg/xts | |
svn co svn://svn.r-forge.r-project.org/svnroot/ttr/pkg ttr |
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
######################################################################################################################################################################### | |
#A simple moving average strategy to evaluate trade efficiency | |
#checks on SMA of 50 days and SMA of 200 days | |
#Author: R. Raghuraman("raghu"), Brian Peterson | |
######################################################################################################################################################################### | |
require(quantstrat) | |
suppressWarnings(rm("order_book.macross",pos=.strategy)) | |
suppressWarnings(rm("account.macross","portfolio.macross",pos=.blotter)) | |
suppressWarnings(rm("account.st","portfolio.st","stock.str","stratMACROSS","initDate","initEq",'start_t','end_t')) |
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
joseph@fletcher:~/dev/R-libs/quantstrat/demo/joe$ Rscript maCross.R | |
Loading required package: quantstrat | |
Loading required package: xts | |
Loading required package: zoo | |
Warning: locked binding of ‘as.Date.numeric’ will not be changed | |
Attaching package: ‘zoo’ | |
The following object(s) are masked from ‘package:base’: |
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
> mktdata[mktdata$ma50.gt.ma200 == 1] | |
AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted ma50 ma200 ma50.gt.ma200 ma50.lt.ma200 | |
2001-06-26 11.674914 11.890004 11.509844 11.88 9742200 11.88 11.4304 11.35785 1 NA | |
2002-01-04 11.674926 11.980055 11.499852 11.85 14642000 11.85 10.2674 10.26100 1 NA | |
2003-05-15 9.295035 9.419968 9.230069 9.36 10178400 9.36 7.4438 7.43875 1 NA | |
2006-09-25 73.810000 75.860000 73.720000 75.75 30678300 75.75 67.4122 67.08060 1 NA | |
2008-05-16 190.110000 190.300000 187.000000 187.62 27348900 187.62 156.5994 155.86610 1 NA | |
2009-05-13 123.210000 124.020000 119.380000 119.49 21284700 119.49 112.9098 112.47555 1 NA | |
> mktdata[mktdata$ma50.lt.ma200 == 1] | |
AAPL.Open AAPL.High AAPL.Low AAPL.Close |
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(quantstrat) | |
rm(list=ls()) | |
try(rm(list=ls(pos=.blotter), pos=.blotter), silent=TRUE) | |
try(rm(list=ls(pos=.strategy), pos=.strategy), silent=TRUE) | |
try(rm(list=ls(pos=.instrument), pos=.instrument), silent=TRUE) | |
# settings | |
s <- 'SPY' | |
initEq <- 100000 |
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
# {{{ chart_theme | |
chart_theme <- chart_theme_white <- function() { | |
theme <-list(col=list(bg="#FFFFFF", | |
label.bg="#F0F0F0", | |
grid="#F0F0F0", | |
grid2="#F5F5F5", | |
ticks="#999999", | |
labels="#333333", | |
line.col="darkorange", | |
dn.col="red", |
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
chart_Series <- function(x, | |
name=deparse(substitute(x)), | |
type="candlesticks", | |
subset="", | |
TA="", | |
pars=chart_pars(), theme=chart_theme(), | |
clev=0) { |
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
RocSys = function(x, nEMA, nROC, nTREND) | |
{ | |
rocema = ROC(EMA(x, nEMA), nROC) | |
trend = EMA(x, nTREND) | |
signal = | |
ifelse(rocema>0 & lag(rocema)<=0, ifelse(x>trend, 1, 0), | |
ifelse(rocema<0 & lag(rocema)>=0, ifelse(x<trend, -1, 0), | |
NA) | |
) |
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
<body> | |
<div class='navbar navbar-fixed-top'> | |
<div class='navbar-inner'> | |
<div class='container'> | |
<a class='btn btn-navbar' data-target='.nav-collapse' data-toggle='collapse'> | |
<span class='icon-bar'></span> | |
<span class='icon-bar'></span> | |
<span class='icon-bar'></span> | |
</a> | |
<a class='brand' href='#'>Frooom</a> |
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
running.acf.max <- function(returns, window=100, nlags=5, plot=TRUE, main='') | |
{ | |
clevel <- qnorm (0.5 + 0.95/2) / sqrt(window) | |
series <- rollapply(returns, window, align='right', by=1, function(w) | |
{ | |
acfs <- pacf(coredata(w), lag.max=nlags, plot=FALSE)$acf | |
cum <- cumsum(acfs) | |
low <- min(cum) |