-3

这是我之前的问题的后续,我试图从雅虎财经下载期权数据。它仍然不起作用。但我在互联网上找到了另一个代码,它可以工作,但输出格式我无法使用,因为我对 R 有点陌生。

该代码给了我一个名为 OptionPrices 的变量。

以下是使用命令 fix(OptionPrices) 打印的 OptionPrices 的输出:


structure(list(call = structure(list(Strike = 26, Symbol = structure(1L, .Label = "VIXM131221C00026000", class = "factor"), 
    Last = 1.8, Chg = 0, Bid = 2.05, Ask = 2.65, Vol = 10L, Open.Int = 10L), .Names = c("Strike", 
"Symbol", "Last", "Chg", "Bid", "Ask", "Vol", "Open.Int"), row.names = c(NA, 
-1L), class = "data.frame"), put = structure(list(Strike = c(24, 
25, 26, 29), Symbol = structure(1:4, .Label = c("VIXM131221P00024000", 
"VIXM131221P00025000", "VIXM131221P00026000", "VIXM131221P00029000"
), class = "factor"), Last = c(1.05, 2, 3.2, 4.3), Chg = c(0, 
0, 0, 0), Bid = c(1, 1.45, 1.95, 3.8), Ask = c(1.4, 1.85, 2.35, 
4.4), Vol = c(20L, 1L, 10L, 10L), Open.Int = c(20L, 5L, 10L, 
10L)), .Names = c("Strike", "Symbol", "Last", "Chg", "Bid", "Ask", 
"Vol", "Open.Int"), row.names = c(NA, -4L), class = "data.frame"), 
    Stock.ticker = "VIXM", Quote.date = <S4 object of class structure("timeDate", package = "timeDate")>, 
    Strike.date = <S4 object of class structure("timeDate", package = "timeDate")>, 
    Stock.name = "ProShares VIX Mid-Term Futures ETF (VIXM)", 
    Stock.price = 26.34, TTM = 193, Short.rate = 0.0893939393939394), .Names = c("call", 
"put", "Stock.ticker", "Quote.date", "Strike.date", "Stock.name", 
"Stock.price", "TTM", "Short.rate"))

提取上述信息的雅虎财经页面为:

http://finance.yahoo.com/q/op?s=VIXM&m=2013-12

我想从上述变量 OptionPrices 中为罢工、期权符号、买入价、卖出价等创建向量。

我如何做到这一点。

4

1 回答 1

2

即使我加载了 R 包,我也无法让您的代码正常工作timeDate。但是,一旦我摆脱了Stock.dateQuote.date部分,我就能看到你得到了什么。

OptionPrices <- structure(list(call = structure(list(Strike = 26, Symbol = structure(1L, .Label = "VIXM131221C00026000", class = "factor"), 
    Last = 1.8, Chg = 0, Bid = 2.05, Ask = 2.65, Vol = 10L, Open.Int = 10L), .Names = c("Strike", 
    "Symbol", "Last", "Chg", "Bid", "Ask", "Vol", "Open.Int"), row.names = c(NA, 
    -1L), class = "data.frame"), put = structure(list(Strike = c(24, 
    25, 26, 29), Symbol = structure(1:4, .Label = c("VIXM131221P00024000", 
    "VIXM131221P00025000", "VIXM131221P00026000", "VIXM131221P00029000"
    ), class = "factor"), Last = c(1.05, 2, 3.2, 4.3), Chg = c(0, 
    0, 0, 0), Bid = c(1, 1.45, 1.95, 3.8), Ask = c(1.4, 1.85, 2.35, 
    4.4), Vol = c(20L, 1L, 10L, 10L), Open.Int = c(20L, 5L, 10L, 
    10L)), .Names = c("Strike", "Symbol", "Last", "Chg", "Bid", "Ask", 
    "Vol", "Open.Int"), row.names = c(NA, -4L), class = "data.frame"), 
    Stock.ticker = "VIXM", Stock.name = "ProShares VIX Mid-Term Futures ETF (VIXM)", 
    Stock.price = 26.34, TTM = 193, Short.rate = 0.0893939393939394), .Names = c("call", 
    "put", "Strike.date", "Stock.name", 
    "Stock.price", "TTM", "Short.rate"))

因此,OptionPrices是一个列表,您似乎对put元素中包含的信息感兴趣。您可以将此元素保存到数据框中,然后使用名称或列号访问数据框中的每个元素(向量)。

df <- OptionPrices$put
df$Last
df[, 3]
于 2013-06-11T15:37:24.957 回答