如何自动化股票数据的提取和组织Yahoo Finance API

This past summer, my grandfather taught me the tips and tricks of investing in the stock market. We did detailed analyses of various companies, comparing profit margins, price to earnings, and other aspects of company fundamentals. After taking hours to dig through Yahoo Finance and compile stock info into spreadsheets, I began to wonder if there was a more efficient way to research companies. I decided to design code that would extract the data I needed so I could simply glance over the data table to decide if a company was profitable. Here’s how I did it:

去年夏天,我的祖父教给我有关投资股票市场的提示和技巧。 我们对各种公司进行了详细的分析,比较了利润率,价格与收益以及公司基本面的其他方面。 在花了几个小时来浏览Yahoo Finance并将股票信息编译成电子表格之后,我开始怀疑是否存在一种更有效的研究公司的方式。 我决定设计代码来提取所需的数据,因此我可以简单地浏览一下数据表来确定一家公司是否盈利。 这是我的操作方式:

My code takes a list of stock tickers and outputs a pandas data frame where the columns are stock attributes and the rows are the corresponding ticker data.

我的代码获取股票行情清单,并输出一个熊猫数据框,其中列为股票属性,行为相应的行情记录数据。

入门 (Getting Started)

Installing Yahoo Finance API

安装Yahoo Finance API

Before we can run the code, however, we have to install the Yahoo Finance API in our console. To do so, type “pip install yahoo_fin” and hit enter.

但是,在运行代码之前,我们必须在控制台中安装Yahoo Finance API。 为此,请输入“ pip install yahoo_fin”,然后按Enter。

Importing Modules

导入模块

Then we need to import the stock_info module from the yahoo_fin library so we can use its methods to extract stock data. Since we are using a pandas data frame to organize the data, we will also import pandas.

然后,我们需要从yahoo_fin库中导入stock_info模块,以便可以使用其方法提取库存数据。 由于我们使用的是熊猫数据框来组织数据,因此我们还将导入熊猫。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值