当前位置:网站首页>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.
边栏推荐
- Achievements of Science and Technology (31)
- [SAM模板题] P3975 [TJOI2015] 弦论
- "NIO Cup" 2022 Nioke Summer Multi-School Training Camp 4 DHKLN
- “蔚来杯“2022牛客暑期多校训练营4 DHKLN
- Android安全性优化——APP加固
- 如何在 AWS 中应用 DevOps 方法?
- "NIO Cup" 2022 Nioke Summer Multi-School Training Camp 2 H.Take the Elevator
- $\text{ARC 145}$
- IJCAI2022 Tutorial | Spoken Language Comprehension: Recent Advances and New Fields
- Week 19 Progress (Understanding IoT Basics)
猜你喜欢
【LeetCode】70. 爬楼梯 - Go 语言题解
360核心安全大脑3.0正式发布,构建政企用户的“能力中枢平台”
雪佛兰开拓者,安全保障温暖你的家庭出行的第一选择
In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
Introducing the visualization tool Netron
实验7(MPLS实验)
JS中? ?和??=和?.和 ||的区别
EasyExcel comprehensive course combat
H5跳转微信公众号解决方案
通过对抗性知识蒸馏压缩深度图神经网络
随机推荐
Soft Exam Study Plan
Lambda表达式
Reverse linked list - in-place inversion method
软考学习计划
测试人面试 常被问到的计算机网络题,高薪回答模板来了
[MySQL] Mysql transaction and authority management
智能创意中的尺寸拓展模块
IJCAI2022教程 | 口语语言理解:最新进展和新领域
Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)
uni-ui installation
mysql中关于存储过程无法实现迁移复制表中数据问题
“蔚来杯“2022牛客暑期多校训练营4 N.Particle Arts 规律 方差
实验8(vlan实验)
leetcode 406. Queue Reconstruction by Height
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
[SAM模板题] P3975 [TJOI2015] 弦论
$\text{ARC 145}$
2022牛客暑期多校训练营1 J Serval and Essay
反转链表-就地逆置法
[MySQL] Related operations on databases and tables in MySQL