Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateAcct not working due to dates not matching, possible patch #49

Open
rogerjbos opened this issue May 12, 2017 · 1 comment
Open

Comments

@rogerjbos
Copy link

rogerjbos commented May 12, 2017

Based on the example code at the end, my additions, withdrawals and interest are not being added to the account summary. One fix would be to modify line 94 of updateAcct.R from

obsDates = index(table)

to

obsDates = as.Date(index(table))

I thought this was more of a hack than a fix, but then I saw this post where a user says "If you supply a POSIXct time xts tries to make an exact match, which it doesn't find in this case." and obsDates and TxnDate are both POSIXct, so it may be good enough to change obsDates to non-time based so xts will match it.

require(blotter)
require(FinancialInstrument)
require(quantmod)
rm(.blotter)
if(!exists(".instrument")) .instrument <<- new.env()
if(!exists(".blotter")) .blotter <<- new.env()

currency("USD")
symbols = c("IBM")
for(symbol in symbols){ # establish tradable instruments
  stock(symbol, currency="USD", multiplier=1)
}

getSymbols(symbols, from='2017-01-01', to='2017-01-10', src='yahoo', index.class=c("POSIXt","POSIXct"))

initPortf("p", symbols=symbols, currency="USD")

addTxn(Portfolio = "p", Symbol = "IBM", TxnDate = '2017-01-03', TxnQty = 1, TxnPrice = 166, TxnFees = 00)
addTxn("p", "IBM", '2017-01-10', -1, 170, TxnFees = 0)

updatePortf(Portfolio="p",Dates='2017-01')

initAcct(name="a", portfolios="p", initEq=166, currency="USD")

addAcctTxn(Account="a", TxnDate='2017-01-05', TxnType='Additions', Amount=1000)
addAcctTxn(Account="a", TxnDate='2017-01-06', TxnType='Withdrawals', Amount=1000)
addAcctTxn(Account="a", TxnDate='2017-01-09', TxnType='Interest', Amount=10)

updateAcct("a")
updateEndEq("a")

a <- getAccount("a")
a$summary
index(a$Additions)
a$Interest
@rogerjbos rogerjbos changed the title addAcctTxn not working due to dates not matching, possible patch updateAcct not working due to dates not matching, possible patch May 15, 2017
@joshuaulrich
Copy link
Collaborator

Hi Roger, thanks for the reproducible example! Could you please add the expected output? That would make the problem explicit and testable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants