summary: *think* i've found a bug in blotter's updatePortf which only arises
in the context of transactions priced from ticks that are not in the Symbols
pricing (OHLC daily for instance)
As you can see below, the posPL tables are correct. They list the
transactions and the Close prices and provide PL measurement for periods
between days UNLESS there is a transaction in which case the PL is broken up
into intraday segments.
THE PROBLEM is in calculating the p$summary table the following call:
table = .getBySymbol(Portfolio = Portfolio, Attribute = "Pos.Value", Dates
= Dates, Symbols = Symbols)
returns a table defined by:
for (symbol in symbols) {
tmp_col =
Portfolio$symbols[[symbol]][[namePosPL]][Dates,Attribute,drop=FALSE]
if(is.null(table)) table = tmp_col
else table = merge(table, tmp_col)
}
which uses whatever "Dates" you called updatePortf with or if nothing is
specified grabs price and transaction time stamps from the first symbol's
posPL list (which is an admitted bug):
if(is.null(Dates)) Dates <- time(Portfolio$symbols[[1]]$posPL) #not quite
right, only using first symbol...
So the only way it can work is with a "Dates" argument that includes every
transaction time in addition to whatever regular bar (5min, daily) you'd
like. If any transaction times are not included in the Dates argument to
updatePortf the intraday piece of PnL marked in symbol$posPL will not be
included in portfolio$summary (as seen below: specifically compare the rows
in p$symbols$`AAPL-US`$posPL with a time component in date index 2008-09-30
15:03:12.137 or 2008-10-01 16:00:00.000 to the rows in p$summary. The
p$summary table has a Net.Trading.PL entry corresponding to every line in
A-US and AAPL-US $posPL tables EXCEPT these two lines. *In summary:
-15558.27 and -10342.47 of Net.Trading.PL don't make it into the summary
calculations because they don't join to the time index as based upon the
price and transaction times of the arbitrarily first symbols's posPL table*
Also, given a hi-freq portfolio with many trades in many securities marking
the entire portfolio at every transaction time (which the above implies)
could become quite burdensome. It's one thing to mark any given symbol on
all it's transactions. But I would suggest it's more sensible to then
aggregate the symbol PnL to a regularized time signature defined as a
portfolio attribute.
I'm new to R and blotter so please let me know if I misunderstood something.
thoughts?
best, J
reproducible example:
initDate = '1950-01-01'
startDate = '2008-01-09'
endDate = '2010-10-28'
symbols<-c("A-US", "AAPL-US") # note: i'm loading proprietary Closing price
data from RData files
initPortf("p", symbols=symbols, initDate=initDate, currency="USD")
extractTxns("p")
[1] "addTxn(Portfolio ='p', Symbol ='A-US', TxnDate = '2008-09-30
11:27:38.586', TxnQty =34400, TxnPrice =29.05, TxnFees =-1498.98, ConMult
=1)"
[2] "addTxn(Portfolio ='p', Symbol ='A-US', TxnDate = '2008-10-06 16:00:00',
TxnQty =-34400, TxnPrice =26.7802, TxnFees =-1381.858, ConMult =1)"
[3] "addTxn(Portfolio ='p', Symbol ='AAPL-US', TxnDate = '2008-09-30
15:03:12.137', TxnQty =-8900, TxnPrice =112.08, TxnFees =-1496.268, ConMult
=1)"
[4] "addTxn(Portfolio ='p', Symbol ='AAPL-US', TxnDate = '2008-10-01
16:00:00', TxnQty =8900, TxnPrice =110.1169, TxnFees =-1470.061, ConMult
=1)"
updatePortf(Portfolio="p")
p <- getPortfolio("p") # make a local copy of the portfolio object
p$summary['2008-09-28/2008-10-8']
p$symbols$`A-US`$txn
p$symbols$`AAPL-US`$txn
p$symbols$`A-US`$posPL['2008-09-28/2008-10-8']
p$symbols$`AAPL-US`$posPL['2008-09-28/2008-10-8']
updatePortf(Portfolio="p")
[1] "p"
p <- getPortfolio("p") # make a local copy of the portfolio object
p$summary['2008-09-28/2008-10-8']