当前位置:网站首页>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.
边栏推荐
- 雪佛兰开拓者,安全保障温暖你的家庭出行的第一选择
- reindex win10
- (WebFlux)001、如何自定义注解实现功能
- Reverse linked list - head insertion inversion method
- H5跳转微信公众号解决方案
- Android安全性优化——APP加固
- 2022 China Logistics Industry Conference and Entrepreneur Summit Forum will be held in Hangzhou!
- "Wei cup" school more than 2022 cattle summer camp 4 L.B lack Hole, computational geometry
- Abstract classes and interfaces (study notes)
- flex布局父项常见属性flex-wrap
猜你喜欢
随机推荐
HCIP Day 15 Notes
grub learning
“蔚来杯“2022牛客暑期多校训练营4 L.Black Hole 垃圾计算几何
flex-direction容器属性
leetcode(刷题篇13)
【MySQL】MySQL中对数据库及表的相关操作
【VisDrone数据集】YOLOV3训练VisDrone数据集步骤与结果
MySQL的一个问题
数据清洗-使用es的ingest
Bugku sql注入
软考总结
Shell编程条件语句 test命令 整数值,字符串比较 逻辑测试 文件测试
#Dasctf July Enabler WP
可视化工具Netron介绍
借助深度估计的点云场景重建
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
Week 19 Progress (Understanding IoT Basics)
Soft Exam Summary
10 个关于自动化发布管理的好处
uniapp develops WeChat applet - soft exam brushing applet









