Hi,
I was planning on using blotter for a project, and I've looked through the demos, but I'm having difficulty understanding some behavior in the simple example below. The initial account equity is set to exactly the close for SPY on 2012-01-03, and one share is bought @ 127.5. But as I examine the ending equity for a series of dates, it appears to correspond to the *following* day's close. Similarly, the output from PortfReturns implies the share purchased on Jan 3 experienced a return (that day) from Jan 3 -> 4, which seems odd. I must be missing something simple -- perhaps a subtle timezone issue or something.
-- Main output:
SPY.Close
2012-01-03 127.50
2012-01-04 127.70
2012-01-05 128.04
-- Code:
require(blotter)
require(quantmod)
# basic set up / data retrieval
currency('USD')
stock('SPY',currency='USD',multiplier=1)
getSymbols('SPY',from='2012-01-01',to='2012-12-31',src='yahoo', index.class=c("Date"))
# initial equity = price of SPY on txn.date
init.date = '2011-12-31'
txn.date = '2012-01-03'
price = as.numeric(Cl(SPY)[txn.date])
# portfolio/acct set up
.blotter <- new.env()
initPortf('tst', symbols='SPY', currency="USD", initDate=init.date)
initAcct(name='tst', portfolios='tst', initEq=price, currency='USD', initDate=init.date)
# add transaction
addTxn(Portfolio='tst', Symbol='SPY', TxnDate=txn.date, TxnQty=1, TxnPrice=price)
# updates
updatePortf(Portfolio='tst', Dates='2012')
updateAcct('tst', '2012')
updateEndEq('tst','2012')
# result
getTxns('tst','SPY')
getEndEq('tst','2012-01-03')
getEndEq('tst','2012-01-04')
head(PortfReturns('tst'),4)
head(Cl(SPY), 3)
Thanks!
Dhruv
P.S. sessionInfo (blotter, FinancialInstrument, quantmod all built from SVN this evening):
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] qmao_1.4.7 XML_3.95-0.1 gdata_2.12.0 blotter_0.8.13 FinancialInstrument_1.1.2
[6] quantmod_0.4-0 TTR_0.21-1 Defaults_1.1-1 xts_0.9-1 zoo_1.7-9
loaded via a namespace (and not attached):
[1] bitops_1.0-5 caTools_1.14 digest_0.6.0 grid_2.15.1 gtools_2.7.0 lattice_0.20-13 pander_0.3 RCurl_1.95-3
[9] RJSONIO_1.0-1 shiny_0.2.4 tools_2.15.1 websockets_1.1.7 xtable_1.7-0
THIS MESSAGE AND ANY ATTACHMENTS ARE CONFIDENTIAL, PROPRIETARY, AND MAY BE PRIVILEGED. If this message was misdirected, BlackRock, Inc. and its subsidiaries, ("BlackRock") does not waive any confidentiality or privilege. If you are not the intended recipient, please notify us immediately and destroy the message without disclosing its contents to anyone. Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized. The views and opinions expressed in this e-mail message are the author's own and may not reflect the views and opinions of BlackRock, unless the author is authorized by BlackRock to express such views or opinions on its behalf. All email sent to or from this address is subject to electronic storage and review by BlackRock. Although BlackRock operates anti-virus programs, it does not accept responsibility for any damage whatsoever caused by viruses being passed.