r语言quantmond_R语言金融基础:tidyquant获取数据(股票每日行情)

本文介绍了如何使用R语言的tidyquant包获取苹果公司的股票数据,包括每日行情、股息和分股信息。tidyquant提供的数据包含日期、开盘价、最高价、最低价、收盘价、成交量和矫正收盘价,后者考虑了股息、分股等因素,更准确反映股票价值。
摘要由CSDN通过智能技术生成

原标题:R语言金融基础:tidyquant获取数据(股票每日行情)

作者:黄天元,复旦大学博士在读,目前研究涉及文本挖掘、社交网络分析和机器学习等。希望与大家分享学习经验,推广并加深R语言在业界的应用。

邮箱:huang.tian-yuan@qq.com

tidyquant除了能够获得大市的信息以外,还能够对个股行情进行采集。以苹果公司为例:

library(tidyquant)

aapl_prices

aapl_prices

# A tibble: 7,391 x 7

date open high low close volume adjusted

1 1990-01-02 1.26 1.34 1.25 1.33 45799600 0.122

2 1990-01-03 1.36 1.36 1.34 1.34 51998800 0.123

3 1990-01-04 1.37 1.38 1.33 1.34 55378400 0.123

4 1990-01-05 1.35 1.37 1.32 1.35 30828000 0.124

5 1990-01-08 1.34 1.36 1.32 1.36 25393200 0.124

6 1990-01-09 1.36 1.36 1.32 1.34 21534800 0.123

7 1990-01-10 1.34 1.34 1.28 1.29 49929600 0.118

8 1990-01-11 1.29 1.29 1.23 1.23 52763200 0.113

9 1990-01-12 1.22 1.24 1.21 1.23 42974400 0.113

10 1990-01-15 1.23 1.28 1.22 1.22 40434800 0.112

# ... with 7,381 more rows

只要输入股票代码APPL,并且注明需要获取的是“stock.prices”股价信息,即可获得自1990年1月1日以来苹果股票价格的变化(可自定义调整)。我们可以看到结果里面有日期、开盘价、最高价、最低价、收盘价、成交量和矫正收盘指数(adjusted)。很多指标都很好理解,但是对于adjusted我们需要进一步解释

原文如下:

If you're a new investor, you may have heard the terms "closing price" and "adjusted closing price." These two terms refer to slightly different ways of valuing stocks. The closing price of a stock is the price of that stock at the close of the trading day. The adjusted closing price is a more complex analysis that uses the closing price as a starting point, but it takes into account factors such as dividends, stock splits and new stock offerings to determine a value. The adjusted closing price represents a more accurate reflection of a stock's value, since distributions and new offerings can alter the closing price.

也就是说,矫正收盘价是考虑了股息、分股和增股之后,股票收盘时候价格的变化。tidyquant也支持查询股息和分股信息:

# 查看股息

aapl_divs

aapl_divs

# A tibble: 51 x 2

date dividends

1 1990-02-16 0.11

2 1990-05-21 0.11

3 1990-08-20 0.11

4 1990-11-16 0.12

5 1991-02-15 0.12

6 1991-05-20 0.12

7 1991-08-19 0.12

8 1991-11-18 0.12

9 1992-02-14 0.12

10 1992-06-01 0.12

# ... with 41 more rows

# 查看分股

aapl_splits

aapl_splits

# A tibble: 3 x 2

date splits

1 2000-06-21 2

2 2005-02-28 2

3 2014-06-09 7

也就是说,自1990年以来,苹果公司在2000、2005和2014年进行了分股,以增加其流动性。与此同时,苹果在这个时间段内进行了51次分红。

不过对公共数据的请求有时候要依赖网络,如果失败了,请再试一次。这个工具对国外网络的稳定性具有很强的依赖性,主要是从雅虎金融网址直接抓取的数据。

——————————————返回搜狐,查看更多

责任编辑:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值