[Blotter-commits] r309 - in pkg: blotter/R quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 28 17:38:49 CEST 2010
Author: braverock
Date: 2010-03-28 17:38:49 +0200 (Sun, 28 Mar 2010)
New Revision: 309
Modified:
pkg/blotter/R/chart.Posn.R
pkg/quantstrat/demo/BBands.R
pkg/quantstrat/demo/faber.R
Log:
- update to use new quantmod charts instead of the old ones
Modified: pkg/blotter/R/chart.Posn.R
===================================================================
--- pkg/blotter/R/chart.Posn.R 2010-03-27 16:33:43 UTC (rev 308)
+++ pkg/blotter/R/chart.Posn.R 2010-03-28 15:38:49 UTC (rev 309)
@@ -34,19 +34,21 @@
} else { n=mult }
tzero = xts(0,order.by=index(Prices[1,]))
- Prices=align.time(Prices,n)
+# Prices=align.time(Prices,n)
Trades = Portfolio[[Symbol]]$txn$Txn.Price*Portfolio[[Symbol]]$txn$Txn.Qty
Buys = Portfolio[[Symbol]]$txn$Txn.Price[which(Trades>0)]
- Buys = align.time(rbind(Buys,tzero),n)[-1]
+# Buys = align.time(rbind(Buys,tzero),n)[-1]
Sells = Portfolio[[Symbol]]$txn$Txn.Price[which(Trades<0)]
- Sells = align.time(rbind(Sells,tzero),n)[-1]
+# Sells = align.time(rbind(Sells,tzero),n)[-1]
#Position = Portfolio[[Symbol]]$posPL$Pos.Qty # use $txn instead, and make it match the prices index
Position = Portfolio[[Symbol]]$txn$Pos.Qty
Position = na.locf(merge(Position,index(Prices)))
- CumPL = cumsum(Portfolio[[Symbol]]$posPL$Trading.PL)
- if(length(CumPL)>1) CumPL = na.locf(merge(CumPL,index(Prices)))
- else CumPL = NULL
+ CumPL = cumsum(Portfolio[[Symbol]]$posPL$Net.Trading.PL)
+ if(length(CumPL)>1)
+ CumPL = na.locf(merge(CumPL,index(Prices)))
+ else
+ CumPL = NULL
# # These aren't quite right, as abs(Pos.Qty) should be less than prior abs(Pos.Qty)
# SellCover = Portfolio[[Symbol]]$txn$Txn.Price * (Portfolio[[Symbol]]$txn$Txn.Qty<0) * (Portfolio[[Symbol]]$txn$Pos.Qty==0)
# BuyCover = Portfolio[[Symbol]]$txn$Txn.Price * (Portfolio[[Symbol]]$txn$Txn.Qty>0) * (Portfolio[[Symbol]]$txn$Pos.Qty==0)
@@ -58,11 +60,11 @@
# scope the date, this is heavy-handed, but should work
if(!is.null(Dates)) Prices=Prices[Dates]
- chartSeries(Prices, TA=NULL,...)
- if(nrow(Buys)>=1) plot(addTA(Buys,pch=2,type='p',col='green', on=1));
- if(nrow(Sells)>=1) plot(addTA(Sells,pch=6,type='p',col='red', on=1));
- if(nrow(Position)>=1) plot(addTA(Position,type='b',col='blue', lwd=2));
- if(!is.null(CumPL)) plot(addTA(CumPL, col='darkgreen', lwd=2))
+ chart_Series(Prices, TA=NULL,...)
+ if(nrow(Buys)>=1) plot(add_TA(Buys,pch=2,type='p',col='green', on=1));
+ if(nrow(Sells)>=1) plot(add_TA(Sells,pch=6,type='p',col='red', on=1));
+ if(nrow(Position)>=1) plot(add_TA(Position,type='b',col='blue', lwd=2));
+ if(!is.null(CumPL)) plot(add_TA(CumPL, col='darkgreen', lwd=2))
}
###############################################################################
Modified: pkg/quantstrat/demo/BBands.R
===================================================================
--- pkg/quantstrat/demo/BBands.R 2010-03-27 16:33:43 UTC (rev 308)
+++ pkg/quantstrat/demo/BBands.R 2010-03-28 15:38:49 UTC (rev 309)
@@ -58,8 +58,8 @@
end_t<-Sys.time()
end_t-start_t
updatePortf(Portfolio='bbands',Dates=paste('::',as.Date(Sys.time()),sep=''))
-chart.Posn(Portfolio='bbands',Symbol=stock.str,theme='white')
-plot(addBBands(on=1,sd=SD,n=N))
+chart.Posn(Portfolio='bbands',Symbol=stock.str)
+plot(add_BBands(on=1,sd=SD,n=N))
###############################################################################
# R (http://r-project.org/) Quantitative Strategy Model Framework
#
Modified: pkg/quantstrat/demo/faber.R
===================================================================
--- pkg/quantstrat/demo/faber.R 2010-03-27 16:33:43 UTC (rev 308)
+++ pkg/quantstrat/demo/faber.R 2010-03-28 15:38:49 UTC (rev 309)
@@ -115,10 +115,14 @@
print("trade blotter portfolio update:")
print(end_t-start_t)
+# hack for new quantmod graphics, remove later
+themelist<-chart_theme()
+themelist$up.col<-'lightgreen'
+themelist$down.col<-'pink'
for(symbol in symbols){
dev.new()
- chart.Posn(Portfolio='longtrend',Symbol=symbol,theme=chartTheme('white', up.col='lightgreen', dn.col='pink'), type='bar')
- plot(addSMA(n=10,col='darkgreen', on=1))
+ chart.Posn(Portfolio='longtrend',Symbol=symbol,theme=themelist)
+ plot(add_SMA(n=10,col='darkgreen', on=1))
}
More information about the Blotter-commits
mailing list