r - 具有多个到期时间的 getOptionChain

标签 r quantmod chain

我使用 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/

相关文章:

node.js - Node Js 中带有同步的错误链

CXF WS,拦截器 : stop processing, 响应错误

r - 如何从 Yahoo! 抓取关键统计数据使用 R 进行财务?

r - quantmod 的简单功能不再起作用

Javascript( typescript )Chrome 扩展,函数回调如 promise ?

python - 在 R 或 Python 中转换数据类型

r - 如何在轴标签中制作平方根符号?

r - 创建一个带有渐变颜色的箭头

r - 如何选择 R 数据框中满足特定条件的第一行?

r - 基于因子使用不同颜色绘制时间序列