Stock Price in Chinese Security Market

python
finance
Published

January 1, 2023

import matplotlib.pyplot as plt
import numpy as np
import tushare as ts
pro = ts.pro_api('c3b363af328c57f2e9b00f7a2d2df5d4b984dfa61e72e981be282da3')
# 定义数据类型
intList = [np.int8, np.int16, np.int32, np.int64,
           np.uint8, np.uint16, np.uint32, np.uint64]
floatList = [np.float16, np.float32, np.float64]

# 获取数据
df = ts.get_hist_data('hs300')
df = df.reset_index()  # 将索引转化为列


# 绘制图形
df[['close', 'ma5', 'ma10', 'ma20']].plot(
    kind='line',
    figsize=(16, 9), 
    grid=True, 
    title='HS300',
    fontsize=12)
plt.show()
本接口即将停止更新,请尽快使用Pro版接口:https://tushare.pro/document/2