IBrokers R 包:类 twsconn (R) 的问题

发布于 2024-10-26 13:21:24 字数 682 浏览 3 评论 0原文

目前,我正在从 Python 切换到 R,并尝试使用 Jeff Ryan 的 Ibrokers 包编写一些简单的代码来为投资组合定价。我想在我的一个对象中有一个 twsconn 类的字段

setClass( "MktAsset",
  representation( IB.id = "character",
                          asset.type = "factor",
              ccy = "factor",
              IB.conn = "twsconn") )

,但系统似乎对此不太高兴,

消息是

在 .completeClassSlots(ClassDef, where) 中: “MktAsset”定义中未定义的插槽类:IB.connection(class "twsconn")

但是当我询问 tws 的类(用 tws <- twsConnect() 初始化时,它返回

[1] "twsconn"     "environment"

我试图检查代码来检查类 twsconn 是否存在,但是我什么也没发现,

可以帮忙吗?

有人

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.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩起发的微风 2024-11-02 13:21:24

问题是S4中的S3。这应该可行:

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

[email protected] <- 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>

如果您能够在 4 月份访问芝加哥的 R/Finance www.RinFinance.com,周五我将参加一个两小时的研讨会
上午(4 月 29 日)关于 IBrokers(以及一般使用 R 的算法交易)
我怀疑这会很有趣。

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

[email protected] <- 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文