转载Quandl R Package
Quandl R Package 
通过Quandl API可以快速准确地获取宏观经济数据。(https://www.quandl.com/docs/api)
分享两个国外的优秀网站
R和Python在线免费学习的网站》超赞
高频数据与算法学习
This is Quandl's R package. The Quandl R package uses the Quandl API. The official Quandl R package manual can be found here.
License provided by MIT.
For more information please contact raymond@quandl.com
Installation
To install the devtools package:
install.packages("devtools")
library(devtools)
install_github("quandl/quandl-r")
CRAN
To install the most recent package from CRAN type:
install.packages("Quandl")
library(Quandl)
Note that the version on CRAN might not reflect the most recent changes made to this package.
Authentication
To make full use of the package we recommend you set your api key. To do this create or sign into your account and go to your account api key page. Then input your API key (with quotes):
Quandl.api_key("tEsTkEy123456789")
Usage
The Quandl package functions use the Quandl API. Optional Quandl API query parameters can be passed into each function. For more information on supported query parameters, please see the Quandl API documentation page. Once you find the data you would like to load into R on Quandl, copy the Quandl code from the description box and paste it into the function.
data <- Quandl("NSE/OIL")
Graphing Data Example
To create a graph of Google's performance month-over-month:
plot(stl(Quandl("WIKI/GOOG",type="ts",collapse="monthly")[,11],s.window="per"))
Note: collapse
is a Quandl API query parameter. Click here for a full list of query parameter options.
Return Types
The supported return types for the Quandl(code)
function are:
- raw (which returns a data.frame)
- ts
- zoo
- xts
- timeSeries
To request a specific type, assign the type
argument the return type:
data <- Quandl('NSE/OIL', type = "xts")
Date Formats
zoo, xts, and ts have their own time series date formats. For example:
data <- Quandl('NSE/OIL', collapse = "quarterly", type = "zoo", limit = 3)
data
will have indexes 2015 Q1
, 2015 Q2
, and 2015 Q3
:
Open High Low Last Close Total Trade Quantity Turnover (Lacs)
2015 Q1 459.8 462.8 452.45 454.45 454.95 277225 1265.84
2015 Q2 448.0 451.7 445.10 447.80 446.80 352514 1576.93
2015 Q3 456.0 465.0 454.15 456.80 456.75 174154 797.79
If you want the time series index to be displayed as dates, you will need to set force_irregular = TRUE
:
data <- Quandl('NSE/OIL', collapse = "quarterly", type = "zoo", limit = 3, force_irregular = TRUE)
data
will now have indexes 2015-03-31
, 2015-06-30
, and 2015-09-30
:
Open High Low Last Close Total Trade Quantity Turnover (Lacs)
2015-03-31 459.8 462.8 452.45 454.45 454.95 277225 1265.84
2015-06-30 448.0 451.7 445.10 447.80 446.80 352514 1576.93
2015-09-30 456.0 465.0 454.15 456.80 456.75 174154 797.79
Merged Dataset Data
If you want to get multiple codes at once, delimit the codes with ',', and put them into an array. This will return a multiset.
merged_data <- Quandl(c('GOOG/NASDAQ_AAPL', 'GOOG/NASDAQ_MSFT'))
You can also specify specific columns to retrieve. For example, if you only want column 1 from GOOG/NASDAQ_AAPL
and column 2 from GOOG/NASDAQ_MSFT
:
merged_data <- Quandl(c('GOOG/NASDAQ_AAPL.1', 'GOOG/NASDAQ_MSFT.2'))
Downloading Entire Database
An entire database's data can be downloaded. For example, to download the database ZEA
:
Quandl.database.bulk_download_to_file("ZEA", "./ZEA.zip")
Note you must set your api key to download premium databases to which you are subscribed.
For a full list of optional query parameters for downloading an entire database, click here.
Datatables
To retrieve Datatable data, provide a Datatable code to the Quandl datatables function:
data = Quandl.datatable('ZACKS/FC')
The output format is data.frame
. Given the volume of data stored in datatables, this call will retrieve the first page of the ZACKS/FC datatable. You may turn on pagination to return more data by using:
data = Quandl.datatable('ZACKS/FC', paginate=TRUE)
This will retrieve multiple pages of data and merge them together as if they were one large page. In some cases, however, you will still exceed the request limit. In this case we recommend you filter your data using the available query parameters, as in the following example:
Quandl.datatable('ZACKS/FC', ticker=c('AAPL', 'MSFT'), per_end_date.gt='2015-01-01', qopts.columns=c('ticker', 'per_end_date', 'tot_revnu'))
In this query we are asking for more pages of data, ticker values of either AAPL or MSFT and a per_end_date that is greater than or equal to 2015-01-01. We are also filtering the returned columns on ticker, per_end_date and tot_revnu rather than all available columns.
Search
Searching Quandl from within the R console is now supported. The search function is:
Quandl.search(query = "Search Term", page = n, database_code = "Specific database to search", silent = TRUE|FALSE)
- query: Required; Your search term, as a string
- page: Optional; page number of search you wish returned, defaults to 1.
- per_page: Optional; number of results per page, defaults to 10 in the Quandl R package.
- database_code: Optional; Name of a specific source you wish to search, as a string
- silent: Optional; specifies whether you wish the first three results printed to the console, defaults to True (see example below).
Which outputs to console a list containing the following information for every item returned by the search:
- Name
- Quandl code
- Description
- Frequency
- Column names
Example
A search for Oil, searching only the National Stock Exchange of India (NSE).
Quandl.search("Oil", database_code = "NSE", per_page = 3)
prints:
Oil India Limited
Code: NSE/OIL
Desc: Historical prices for Oil India Limited<br><br>National Stock Exchange of India<br><br>Ticker: OIL<br><br>ISIN: INE274J01014
Freq: daily
Cols: Date | Open | High | Low | Last | Close | Total Trade Quantity | Turnover (Lacs)
Oil Country Tubular Limited
Code: NSE/OILCOUNTUB
Desc: Historical prices for Oil Country Tubular Limited<br><br>National Stock Exchange of India<br><br>Ticker: OILCOUNTUB<br><br>ISIN: INE591A01010
Freq: daily
Cols: Date | Open | High | Low | Last | Close | Total Trade Quantity | Turnover (Lacs)
Gulf Oil Corporation Limited
Code: NSE/GULFOILCOR
Desc: Historical prices for Gulf Oil Corporation Limited (GULFOILCOR), (ISIN: INE077F01027), National Stock Exchange of India.
Freq: daily
Cols: Date | Open | High | Low | Last | Close | Total Trade Quantity | Turnover (Lacs)
Additional Resources
More help can be found at Quandl in our R and API pages.
转载Quandl R Package的更多相关文章
- Factoextra R Package: Easy Multivariate Data Analyses and Elegant Visualization
factoextra is an R package making easy to extract and visualize the output of exploratory multivaria ...
- [转载]npm 与 package.json 快速入门教程
npm 与 package.json 快速入门教程 2017-08-02 19:16:20 拭心 阅读数 78648更多 分类专栏: 学学前端 版权声明:本文为博主原创文章,遵循CC 4.0 BY ...
- 【转载】R中有关数据挖掘的包
下面列出了可用于数据挖掘的R包和函数的集合.其中一些不是专门为了数据挖掘而开发,但数据挖掘过程中这些包能帮我们不少忙,所以也包含进来. 1.聚类 常用的包: fpc,cluster,pvclust,m ...
- R语言安装R package的2种方法
http://www.cnblogs.com/emanlee/archive/2012/12/05/2803606.html
- R: for installing package 'RODBC'
Today, i try to install a package in R named 'DOBDC', while i meet a message: > install.packages( ...
- Asynchronous and Distributed Programming in R with the Future Package
Every now and again someone comes along and writes an R package that I consider to be a 'game change ...
- The leaflet package for online mapping in R(转)
It has been possible for some years to launch a web map from within R. A number of packages for doin ...
- Create and format Word documents using R software and Reporters package
http://www.sthda.com/english/wiki/create-and-format-word-documents-using-r-software-and-reporters-pa ...
- 从Github上轻松安装R包—githubinstall包--转载
1.综述 越来越多的R包正在由世界上不同的人所创建,其中一部分原因是devtools包使得开发R包1变得更加简单.devtools包不仅让开发R包变得简单,而且用于分发R包. 当开发者发布一个R包的时 ...
随机推荐
- Linux监控工具 (Linux Monitor Tools)
最近发现几个好用的工具,顺便总结下. Zabbix和Nagios属于重量级,企业级Service procps-ng: top, free, ps, pgrep, vmstat ... sysstat ...
- 我也要学iOS逆向工程--全局变量
大家好!很久不见了.我之前去音乐学院进修爵士吉他去了.现在回来了.之前我一直在学windows开发和逆向.后来到了音乐学院,老师推荐了1个录音软件叫logic prox.可惜啊!当时我只有个索尼的笔记 ...
- DevExpress XtraTreeList的复选框 禁用
树的2个事件代码如下,通过节点的tag判断是否禁用节点前的复选框.树的节点加载时设置要禁用的节点tag为-1,不禁用的则设为相关的值 private void treeListPer_CustomDr ...
- android手机出现sqlite3 not found的解决方法
解决方法如下: 1.如果/system目录为不可读写的,需要挂载为读写: C:\Users\easteq>adb shell root@android:/ # mount -o remount, ...
- [转]VS2010中水晶报表安装应用及实例
基本分类如下:第一部分:VS2010简介VS2010是微软的提供的一套完整的开发环境,功能也是相当的大微软宣布了下一代开发工具和平台的正式名称,分别称为“Visual Studio Team Syst ...
- AssetBundle系列——打包前进行平台检测
在生成AssetBundle的时候,如果目标平台和当前平台不一致,Unity3D会自动将当前平台转换为目标平台. 如果项目中资源量比较大,这个转换过程是相当漫长的,并且不能够强行中止. 所以最好在Bu ...
- C# 类型基础
引言 本文之初的目的是讲述设计模式中的 Prototype(原型)模式,但是如果想较清楚地弄明白这个模式,需要了解对象克隆(Object Clone),Clone其实也就是对象复制.复制又分为了浅度复 ...
- 【MSDN原版】Windows 7 with SP1各版本下载
Windows 7 Ultimate with Service Pack 1简体中文旗舰版:Windows 7 Ultimate with Service Pack 1 (x86) - DVD (Ch ...
- Java Annotation认知(包括框架图、详细介绍、示例说明)
摘要 Java Annotation是JDK5.0引入的一种注释机制. 网上很多关于Java Annotation的文章,看得人眼花缭乱.Java Annotation本来很简单的,结果说的人没说清楚 ...
- [c++] Collection of key and difficult points
Operator Overload 1. 在重载下标运算符时(数组符号):不可重载为友元函数,必须是非static类的成员函数. why 2. overload ++ 时,如果是: int a; ...