我使用 R 通过 quantmod 包下载期权链。 我的目标是下载和导出期权链,以便在其他软件上使用。
如果我只下载前一个月的到期日,我可以使用这些行正确导出到 .txt 文件:
library(quantmod)
aapl_front <- getOptionChain ('AAPL')
front <- do.call('rbind', aapl_front)
write.table (front, 'data_front.txt')
当我下载所有到期时出现问题。这里 rbind
函数无法正常工作,我导出了一个无用的表;这些是行:
aapl_total <- getOptionChain('AAPL', NULL)
total <- do.call('rbind', aapl_total)
write.table(total, 'data_total.txt')
我想在第二种情况下 aapl_total
是一个列表列表,其中包含所有过期时间,但我无法正确拆分它们。
有什么建议吗?
最佳答案
您可以遍历每个过期时间并rbind
看涨期权和看跌期权。
lapply(aapl_total, function(x) do.call(rbind, x))
然后,您将得到一个列表,您可以do.call(rbind())
。
一步到位:
do.call(rbind, lapply(aapl_total, function(x) do.call(rbind, x)))
关于r - 具有多个到期时间的 getOptionChain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17774992/