SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: addDiv [ Reply ]
By: Joshua Ulrich on 2015-10-07 00:58
[forum:42625]
Here's an example, based on the "longtrend" demo in the blotter package. Hope it helps.

Best,
Josh

#####################################3
require(blotter)
demo(longtrend, ask=FALSE)

# Add dividends from SPY
spyDiv <- getDividends("SPY", from=initDate)
for(i in 1:nrow(spyDiv)) {
obs <- spyDiv[i,]
addDiv("longtrend", "GSPC", index(obs), obs)
}
# Need to update portfolio, account, etc again, since
# we added new transactions
updatePortf("longtrend")
updateAcct("longtrend")
updateEndEq("longtrend")

# Plot position with dividends, calling dev.new() so
# we can compare it to the original plot from the demo.
dev.new()
chart.Posn("longtrend", "GSPC", Dates="1998::")
add_SMA(n=10, col="darkgreen", on=1)

#look at a transaction summary
getTxns(Portfolio="longtrend", Symbol="GSPC")

addDiv [ Reply ]
By: Levi Turner on 2015-07-23 00:23
[forum:42603]
Could I get an example of how to use addDiv properly? I know how to use the inputs correctly, but I don't know where to place the dividends. After I instantiate the portfolio, but that's all I've got.

Thanks to:
Vienna University of Economics and Business Powered By FusionForge