I am using blotter to hold and do the accounting of some transactions, but I would need to save and load them on a daily basis.
I haven´t been able to save my transactions, I believe that that happens because they are in a different enviroment created by blotter (.blotter) - from what I´ve been able to pick up by googling my questions.
I have set up an example of a transaction:
require(quantstrat)
currency("USD")
stock(primary_id = "SB1", currency = "USD", multiplier=1120, tick_size = 0.01)
initPortf(name="testport", symbols="SB1", initDate = "2017-11-01")
initAcct(name="testacct", portfolio="testport", initDate = "2017-11-01", initEq = 100000)
ls_instruments()
addTxn(Portfolio="testport", Symbol="SB1", TxnDate="2017-11-22", TxnPrice=15.00, TxnQty = 2 , verbose=TRUE)
getPos(Portfolio="testport", Symbol="SB1", "2017-11-22", Columns=c("Pos.Qty"))
Then I try to save it (which didn´t work) and was thinking about loading it like in the code below:
save("testport", file="C:/Users/augus/Dropbox/Trading/R/Trading/Dados/test.RData", envir=.blotter)
load(file="C:/Users/augus/Dropbox/Trading/R/Trading/Dados/test.RData", verbose=TRUE)
I am pretty knew to R and stackoverflow, so please let me know if I am missing any information in my question, and thanks a lot for the help.
All the best,
Augusto
The object you wanted was actually "portfolio.testport", not "testport" (this is designed this way in blotter). You can check by looking at what is in the
.blotter
environment:You could do this instead:
You may not want to store all of the stuff in this portfolio though, so it helps to understand what makes up the portfolio.
It is basically a list, containing a summary (xts) and a symbols object (another list):
The contents of the symbols list is:
And each symbol object is also a list, containing 3 xts objects:
txn
is one of the objects (an xts object itself):You may wish to save only sub parts of the above portfolio object.
Here is another approach you might find useful for saving: