blotter provides transaction infrastructure for defining transactions, portfolios and accounts for trading systems and simulation. Provides portfolio support for multi-asset class and multi-currency portfolios. Actively maintained and developed.
perTradeStats computes the trade statistics for a given symbol. We should also provide an option for trade statistics aggregated at the portfolio level (related to #42). One way is to modify perTradeStats to loop over all the symbols in the portfolio.
portf <- .getPortfolio(Portfolio)
for(Symbol in names(portf$symbols){
# do trade stats stuff
}
Another option is to do this with a separate function such as perTradeStats.portfolio. Then perTradeStats could call perTradeStats.portfolio if Symbol = "all" is passed in as an argument.
For example, something like
perTradeStats.portfolio <- function(Portfolio, Symbol, includeOpenTrade = TRUE, tradeDef = "flat.to.flat", ...){
symbols <- names(.getPortfolio(Portfolio)$symbols)
pts.list <- lapply(symbols, function(x) perTradeStats(Portfolio, Symbol = x, includeOpenTrade = includeOpenTrade, tradeDef = tradeDef, ... = ...))
# either return as a list or rbind and return a single data.frame (e.g. do.call(rbind, pts.list))
return(pts.list)
}
perTradeStats
computes the trade statistics for a given symbol. We should also provide an option for trade statistics aggregated at the portfolio level (related to #42). One way is to modifyperTradeStats
to loop over all the symbols in the portfolio.Another option is to do this with a separate function such as
perTradeStats.portfolio
. ThenperTradeStats
could callperTradeStats.portfolio
ifSymbol = "all"
is passed in as an argument.For example, something like