在 Quantmod R 中获取商品价格历史的技巧? [英] Trick to getting commodities price history in Quantmod R?

查看:38
本文介绍了在 Quantmod R 中获取商品价格历史的技巧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

require("quantmod")

这有效:

#Symbol for 前一个月与雅虎财经的天然气getQuote("NGH16.NYM", src="雅虎")

但这没有"

getSymbols("NGH16.NYM", src="yahoo", from="2015-09-01")download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,无法打开 URL 'http://ichart.finance.yahoo.com/table.csv?s=NGF16.NYM&a=8&b=01&c=2015&d=11&e=24&f=2015&g=d&q=q&y=0&z=NGF16.NYM&x=.csv'另外: 警告信息:在 download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :无法打开:HTTP 状态为404 Not Found"

如何获取历史价格?

解决方案

你假设因为你可以获得当前数据快照,你也可以获得历史系列.>

这个假设是错误的.数据现在是许多交易所的重要产品,您通常需要为此付费.

不过,还有其他方法,对于商品数据,

require("quantmod")

This works:

#Symbol for Natural Gas in front month with Yahoo Finance
getQuote("NGH16.NYM", src="yahoo")

but this doesn't"

getSymbols("NGH16.NYM", src="yahoo", from="2015-09-01")

    Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,
  cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=NGF16.NYM&a=8&b=01&c=2015&d=11&e=24&f=2015&g=d&q=q&y=0&z=NGF16.NYM&x=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  cannot open: HTTP status was '404 Not Found'

How do I get price history?

解决方案

You assume that because you can get current data snapshots you can also get historical series.

That assumption is incorrect. Data is now an important product for many exchanges, and you generally need to pay for it.

There are other ways, though, and for commodities data Quandl may be your best bet. Searching for 'natural gas nymex' leads you eg to this NG_H2014 contract, and the Quandl package on CRAN is excellent because all this is now very scriptable too.

Here eg is the March 2016 expiry from your question:

R> str(res <- Quandl("CME/NGH2016"))
'data.frame':   1935 obs. of  9 variables:
 $ Date         : Date, format: "2015-12-23" "2015-12-22" "2015-12-21" "2015-12-18" ...
 $ Open         : num  2.05 2.07 2.02 1.97 1.99 ...
 $ High         : num  2.12 2.08 2.09 2.01 2.02 ...
 $ Low          : num  2.01 2.02 1.97 1.91 1.96 ...
 $ Last         : num  2.11 2.05 2.08 1.96 1.96 ...
 $ Change       : num  0.067 0.031 0.093 NA 0.024 0.002 0.068 0.089 0.022 0.033 ...
 $ Settle       : num  2.1 2.03 2.06 1.97 1.97 ...
 $ Volume       : num  37213 32346 59892 53955 80027 ...
 $ Open Interest: num  210758 209803 208883 207250 212823 ...
 - attr(*, "freq")= chr "daily"
R> 

Or as a zoo object ready for plotting:

R> res <- Quandl("CME/NGH2016", type="zoo")
R> plot(res[,"Settle"], main="NGH2016", ylab="Settle")

这篇关于在 Quantmod R 中获取商品价格历史的技巧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆