Blotter returns question, portfolio vs account

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Blotter returns question, portfolio vs account

Bos, Roger-2
All,

I am looking into calculating portfolio and/or account returns using blotter.  (I am also trying to learn better the difference between portfolios and accounts.)  So I created a simple example pasted below.  I get a portfolio return of 6.9% which matches my manual calculation, but I get an account return of -2.0%, so I asking why that might be?  The table below shows the portfolio returns, the account returns, and account returns I calculated myself and the account returns I calculated myself match pretty closely to the portfolio returns:

> cbind(portfolio_rets, account_rets, account_test)
              IBM.DailyEndEq                e1            End.Eq
1950-01-01                NA                NA                NA
2017-01-03                NA                NA      0.00716868674699
2017-01-04  0.01963852409639  0.00526341880180  0.01238108125628
2017-01-05 -0.00337348192771 -0.01564818890663 -0.00330850771915
2017-01-06  0.00500001204819  0.00840183742261  0.00491998823213
2017-01-09 -0.01132533132530 -0.01624412256496 -0.01108951224615
2017-01-10 -0.01283126506024 -0.00152318430183 -0.01270498106907
2017-01-11  0.01343371084337  0.02660636928014  0.01347266762995
2017-01-12  0.00120480120482 -0.01206680763400  0.00119223248882
2017-01-13 -0.00367470481928 -0.00487363426366 -0.00363203936229
2017-01-17  0.00331327108434  0.00701374936220  0.00328673965069
2017-01-18 -0.00656624096386 -0.00984688664341 -0.00649232239259
2017-01-19  0.00006021084337  0.00667025027784  0.00005992206127
2017-01-20  0.02253015060241  0.02246858690647  0.02242074842540
2017-01-23  0.00289154216867 -0.01920589668888  0.00281440041956
2017-01-24  0.02933731927711  0.02636952850479  0.02847450756285
2017-01-25  0.01439758433735 -0.01451393499485  0.01358726027017
2017-01-26  0.00222898192771 -0.01199589056355  0.00207533240522
2017-01-27 -0.00819277710843 -0.01039858078750 -0.00761222976352
2017-01-27 -0.00000001807229                NA                NA
2017-01-27                NA  0.00826043493841 -0.00000001692047
2017-01-30  0.00000000000000  0.00000001807229  0.00000000000000
2017-01-31  0.00000000000000  0.00000000000000  0.00000000000000


I tried to figure it out discrepancy with AcctReturns by running the code in AcctReturns interactively, but it uses a non-exported function called .getBySymbol, so I got stuck there.


While I am here, I would be happy to get some advice.  If I want to calculate the returns for three strategies, say a small cap fund, mid cap fund, and large cap fund, should I have 3 portfolios in one account or 3 accounts each with one portfolio?  I am leaning towards the latter, but then I am wondering why the difference between portfolio and account?

Thanks,

Roger


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-31', src='yahoo', index.class=c("POSIXt","POSIXct"))

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

## Trades must be made in date order.
addTxn(Portfolio = "p", Symbol = "IBM", TxnDate = '2017-01-03', TxnQty = 1, TxnPrice = 166, TxnFees = 00)
addTxn("p", "IBM", '2017-01-27', -1, 177.30, TxnFees = 0)

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

initAcct(name="a", portfolios="p", initEq=166, currency="USD")
updateAcct("a",'2017-01')
updateEndEq("a",'2017-01')

portfolio_rets <- PortfReturns(Account="a", Dates="2017", Portfolios="p")
Return.cumulative(rets)

account_rets <- AcctReturns(Account="a", Dates="2017", Portfolios="p")
Return.cumulative(arets)

p = getPortfolio("p")
a = getAccount("a")

account_test <- CalculateReturns(a$summary$End.Eq)
cbind(portfolio_rets, account_rets, account_test)




This message and any attachments are for the intended recipient’s use only. This message may contain confidential, proprietary or legally privileged information. No right to confidential or privileged treatment of this message is waived or lost by an error in transmission.
If you have received this message in error, please immediately notify the sender by e-mail, delete the message, any attachments and all copies from your system and destroy any hard copies. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message or any attachments if you are not the intended recipient.




_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.