当前位置:网站首页>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.
边栏推荐
- leetcode(刷题篇13)
- 360核心安全大脑3.0正式发布,构建政企用户的“能力中枢平台”
- 写了多年业务代码,我发现了这11个门道,只有内行才知道
- win10重建索引
- In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
- "NIO Cup" 2022 Nioke Summer Multi-School Training Camp 2 H.Take the Elevator
- leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
- [MySQL] Mysql transaction and authority management
- 【VisDrone数据集】YOLOV3训练VisDrone数据集步骤与结果
- The problem of sticky packets in tcp protocol transmission
猜你喜欢
2022 China Logistics Industry Conference and Entrepreneur Summit Forum will be held in Hangzhou!
#yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
第十九周进度(了解物联网基础知识)
实验8(vlan实验)
CPM:A large-scale generative chinese pre-trained lanuage model
Flex布局使用
Apache Doris series: In-depth understanding of real-time analytical database Apache Doris
The difference between ?? and ??= and ?. and || in JS
#Dasctf July Enabler WP
Excel基础学习笔记
随机推荐
EasyExcel comprehensive course combat
从编译的角度来学作用域!
Lambda表达式
(WebFlux)001、如何自定义注解实现功能
2022牛客暑期多校训练营1 J Serval and Essay
uniapp折叠框二级循环
动态修改el-tab-pane 的label(整理)
uni-ui installation
智能创意中的尺寸拓展模块
第一节 zadig 入门
leetcode:127. 单词接龙
数据清洗-使用es的ingest
Shell脚本 if语句
Flex布局使用
Apache Doris series: In-depth understanding of real-time analytical database Apache Doris
反转链表-头插反转法
leetcode(刷题篇13)
EasyExcel综合课程实战
reindex win10
Week 19 Progress (Understanding IoT Basics)