当前位置:网站首页>Necessary artifacts - AKShare quants
Necessary artifacts - AKShare quants
2022-07-30 23:33:00 【The proud day lay】
Recommend a quantitative investment tools to you today-AKShare:https://www.akshare.xyz/
AKShare是基于 Python 的财经数据接口库,涵盖股票、期货、期权、基金、外汇、债券、指数、Encryption currency financial products such as the fundamentals of、实时和历史行情数据.
本文将在python中调用AKShare,获取A股市场(沪深京)The whole history of stock trading market data.首先获取AAll share market shares code,使用AKShare的股票(沪深京)Real-time market data interface:akshare.stock_zh_a_spot_em()
Remove the stock name for a null value,Two columns and extract the code and name.然后写一个循环,使用AKShare的股票(沪深京)Historical market data interfaceakshare.stock_zh_a_hist()获取全部AShares listed on the stock market history data.我们新建一个空的DataFrame,Each loop add corresponding historical market data of stock code in.在循环中使用Try Catch进行异常处理.The final general stock code is as follows:
### 导包
import akshare as ak
import pandas as pd
import numpy as np
import os
### 设置工作路径
mypath=r"..."
stock_zh_spot_df = ak.stock_zh_a_spot_em() ## 获取实时数据
stock_zh_spot_data=stock_zh_spot_df[stock_zh_spot_df['名称']!=''] ## Remove the name is empty value data
codes_names=stock_zh_spot_data[['代码','名称']]
length=len(codes_names)
all_data = pd.DataFrame([])
for i in range(length):
try:
data_df = ak.stock_zh_a_hist(symbol=codes_names['代码'][i], period="daily", start_date="20150101", adjust="hfq") ## 日度数据,后复权
data_df['stock_id']=codes_names['代码'][i]
all_data=all_data.append(data_df)
except:
KeyError()
all_data.to_csv(os.path.join(mypath+'\\'+'All_Data.csv'),encoding='utf_8_sig') ## 数据导出为csv文件
all_data.to_csv(os.path.join(mypath+'\\'+'All_Data.txt'),sep="\t",index=True) ## 数据导出为txt文件
The statement in the access to historical market data,We introduced into stock code parameters,"daily"Said, degree of data,"hfq"Answer authority after said.Then right chose,Because the stock is a rights issue、分拆、Events such as mergers and dividends,Lead to share price gap appeared.In order to guarantee the data consistency,Often through answer authority before and after the answer authority to adjust price sequence.
Before answer authority refers to maintain the current price is the same,Historical prices to increase or decrease,So that the share price continuous.Before the advantage of answer authority is able to see the history of share price movements,Superposition of various technical indicators are smooth,Is all sorts of quotation software default after right way.However, the disadvantage of former answer authority is also evident:
In order to ensure that the current price is the same,Every time the stock ex-dividend except authority,Both need to readjust the historical prices,Therefore its historical prices is time-varying. Which leads to the different point to see the history of complex price difference may occur before. For a company with continuous dividend,After price before may negative.
After answer authority is guarantee historical prices unchanged,Every time the stock rights after the incident,Adjust the current stock price. After the right price and real stock prices may vary,Not suitable for dish.After the advantage of answer authority is that can reflect the real rate of return of the investors.So after generally used in quantitative research of data.
边栏推荐
猜你喜欢

Gxlcms audio novel system/novel listening system source code

The difference between ?? and ??= and ?. and || in JS

Kotlin特殊类

智能创意中的尺寸拓展模块

image里的mode属性

Apache Doris series: detailed steps for installation and deployment

可视化工具Netron介绍

阿里云视频点播+项目实战

uniapp develops WeChat applet - soft exam brushing applet

Reverse linked list - in-place inversion method
随机推荐
Unity 加载读取PPT
Achievements of Science and Technology (31)
【VisDrone数据集】YOLOV4训练VisDrone数据集步骤与结果
ZZULIOJ:1119: 数列有序
Flex布局使用
Manually set transaction commit in mysql
flex布局父项常见属性flex-wrap
mysql 中手动设置事务提交
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 4 DHKLN
微软商店出现【0x800706D9】解决方法
win10重建索引
【MySQL】Mysql事务以及权限管理
软考总结
DFS题单以及模板汇总
借助深度估计的点云场景重建
【萌新解题】删除链表的倒数第 N 个结点
2021GDCPC广东省大学生程序设计竞赛 H.History
数据清洗-使用es的ingest
HashSet源码解析
The difference between ?? and ??= and ?. and || in JS