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
# {{{ 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 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(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 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
> 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 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
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 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
######################################################################################################################################################################### | |
#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 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
#!/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 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
cat('hi\n') | |
read.csv(file('stdin'), header=FALSE) | |
print(information) | |
cat('hi again\n') |
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(xts) | |
data(sample_matrix) | |
dates <- as.POSIXct(rownames(sample_matrix), format = "%Y-%m-%d") | |
dayLookup <- 1:7 | |
names(dayLookup) <- c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") | |
datesDays <- dayLookup[weekdays(dates, abbreviate = TRUE)] | |
print(datesDays) | |
blah <- xts(cbind(sample_matrix, dow =datesDays), order.by = dates) | |
blah[blah$dow!=5] |
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
djbutton = $($('a').get(0)); | |
var djit = function() { | |
if (djbutton.css('display') != 'none') { | |
e = new jQuery.Event('click'); | |
e.pageX=1; | |
e.pageY=1; | |
turntable.lastMotionTime=new Date().getTime(); | |
djbutton.hover().trigger(e); | |
console.log(new Date() + ' -- triggered DJ'); | |
} else { |
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(quantstrat) | |
# clean up | |
rm(list=ls(all=TRUE, pos=.blotter), pos=.blotter) | |
rm(list=ls(all=TRUE, pos=.instrument), pos=.instrument) | |
rm(list=ls(all=TRUE, pos=.strategy), pos=.strategy) | |
# set initial values | |
initDate <- '2011-08-05 06:00:00' | |
initEq <- 10000 |