Forum: help


RE: PortfReturn Calculation [ Reply ] By: Brian Peterson on 2016-08-14 10:38 | [forum:43427] |
You're using Dates incorrectly, as I replied in a different thread. It should be an xts range. If I run the update* functions without a Date argument, your example actually runs, bringing us to the current day. I have the same tail as your example. let's examine the result: last(cumsum(PortfReturns('TEST')) #2016-08-12 0.33454252 tail(MMM,1) # MMM.Open MMM.High MMM.Low MMM.Close MMM.Volume MMM.Adjusted #2016-08-12 181.47 181.47 179.9 180.27 1229200 180.27 getTxns('TEST','MMM') # Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost Net.Txn.Realized.PL #1950-01-01 0 0.00 0 0 0.00 0 #2014-10-16 100 135.08 0 13508 135.08 0 last(cumsum(PortfReturns('TEST'))) # MMM.DailyEndEq #2016-08-12 0.3345425 180.27/135.08 #[1] 1.334542 Perfectly correct. Regards, Brian |
PortfReturn Calculation [ Reply ] By: John Smith on 2016-08-12 16:29 | [forum:43423] |
I am getting an incorrect return calculation when I run PortfReturn. I assume I may be missing something. See below for the code and also output. Please advise. Thank you. ------------ getSymbols("MMM", index.class="POSIXct") strategy <- "TEST" currency("USD") stock("MMM",currency="USD", multiplier=1) initPortf(strategy, c("MMM") ) initAcct(strategy, portfolios=strategy,initEq=13508) addTxn(strategy,"MMM",as.POSIXct("10-16-14", format="%m-%d-%y"),100,135.08) asOf <- as.POSIXct("08-11-16", format="%m-%d-%y") updatePortf(strategy,Dates=asOf) updateAcct(strategy,Dates=asOf) updateEndEq(strategy,Dates=asOf) PortfReturns("TEST", period="Daily") > MMM >1950-01-01 0.00000000 >2016-08-11 0.01613853 > tail(MMM,1) MMM.Open MMM.High MMM.Low MMM.Close MMM.Volume MMM.Adjusted 2016-08-11 179.08 181.1 178.88 181 2028700 181 |