IBrokers R package: issue with class twsconn (R)
At the moment, I am switching from Python to R and I am trying to write some simple code to price a portfolio, using Jeff Ryan's Ibrokers package. I would like to have a field of class twsconn
in one of my objects
setClass( "MktAsset",
representation( IB开发者_C百科.id = "character",
asset.type = "factor",
ccy = "factor",
IB.conn = "twsconn") )
but the system does not seem happy about it
Msg is
In .completeClassSlots(ClassDef, where) : undefined slot classes in definition of "MktAsset": IB.connection(class "twsconn")
but when I ask the class of tws (initialized with tws <- twsConnect()
, it returns
[1] "twsconn" "environment"
I tried to go through the code to check for the existence of a class twsconn
but, I found nothing.
Can someone help?
Thanks a lot
The issue is S3 in S4. This should work:
setOldClass("twsconn") # this is what you are missing
setClass( "MktAsset",
representation( IB.id = "character",
asset.type = "factor",
ccy = "factor",
IB.conn = "twsconn") )
# [1] "MktAsset"
a <- new("MktAsset")
ibg <- ibgConnect() # connect to IB Gateway
a@IB.conn <- ibg
a
An object of class "MktAsset"
Slot "IB.id":
character(0)
Slot "asset.type":
factor(0)
Levels:
Slot "ccy":
factor(0)
Levels:
Slot "IB.conn":
<twsConnection,1 @ 20110325 13:15:22 CST, nextId=1>
If you're able to come to R/Finance in Chicago in April www.RinFinance.com, I'll be doing a two-hour workshop on Friday morning (April 29th) regarding IBrokers (and algorithmic trading in general with R) that would be of interest I suspect.
精彩评论