官术网_书友最值得收藏!

Introduction to the Quandl data delivery platform

Quandl is a data delivery platform that includes many free datasets. Its website is https://www.quandl.com. The following are a few programs written in R or Python to download data from the platform. The following program retrieves the latest 50 trading days' data for International Business Machine (IBM):

> library(Quandl) 
> x<- Quandl.dataset.get("WIKI/ibm", list(rows=50)) 
> head(x,2) 
        Date   Open    High     Low  Close  Volume Ex-Dividend 
1 2018-01-09 163.90 164.530 163.060 163.83 4333418           0 
2 2018-01-08 162.66 163.905 161.701 163.47 5101023           0 
  Split Ratio Adj. Open Adj. High Adj. Low Adj. Close Adj. Volume 
1           1    163.90   164.530  163.060     163.83     4333418 
2           1    162.66   163.905  161.701     163.47     5101023 

Note that we just need to issue the first two lines in the code once. The following code would get the data for a Chinese company with a ticker symbol of 601628. Obviously, DY4 is for Chinese data:

import Quandl as qd 
y<- Quandl.dataset.get("DY4/601628", list(rows=50)) 
> head(y,2) 

The corresponding output is shown here:

For the following R program, we assume that the Quandl application key is contained in the myQuandlKey variable. Later in the chapter, we explain how to get a Quandl application key:

> library(Quandl) 
> Quandl.api_key(myQuandlKey) 
> x<- Quandl.dataset.get("WIKI/wmt", list(rows=500)) 

For Python, we have the following code to download the Gross Domestic Product (GDP) from Quandl:

import quandl 
x= quandl.get("FRED/GDP") 
x.head() 
             Value 
Date                
1947-01-01  243.080 
1947-04-01  246.267 
1947-07-01  250.115 
1947-10-01  260.309 
1948-01-01  266.173 

The format of the output dataset is a pandas data frame. Quandl can also return data as a numpy array, shown here:

import quandl 
x=quandl.get("FRED/GDP",returns="pandas")     
y=quandl.get("FRED/GDP",returns="numpy") 

The following table shows patterns for different sources of data from the Quandl data platform:

Table 3.6: Max number of calls every 10 min and every day for Quandl users

The next program shows how to retrieve Walmart data for free subscribers, as in, those with a Quandl application key. Being a free subscriber means that you register with Quandl without paying any fees:

import quandl as qd 
quandl.ApiConfig.api_key = 'YOUR_API_KEY'  
y=qd.get("WIKI/WMT") 
y.head(2) 
y.tail(1) 

The output is shown here:

The second line of quandl.ApiConfig.api_key = 'YOUR_API_KEY' indicates that a user has to enter his/her Quandl application key.

主站蜘蛛池模板: 万宁市| 舞阳县| 措美县| 肥乡县| 波密县| 青冈县| 界首市| 万安县| 礼泉县| 沙田区| 灌南县| 怀远县| 德惠市| 平阳县| 肥乡县| 墨江| 呼图壁县| 云龙县| 济阳县| 静乐县| 县级市| 思茅市| 青浦区| 安国市| 渑池县| 绥芬河市| 岗巴县| 福清市| 合川市| 平定县| 琼结县| 襄垣县| 和田县| 吴忠市| 绍兴市| 罗甸县| 新密市| 阿拉善盟| 葵青区| 太湖县| 双城市|