Python之Tushare模块实现股票分析案例整合版

Python之Tushare模块实现股票分析案例整合版

本文是对我的另一篇博文的整理以及简化,原博文链接如下:
https://blog.csdn.net/m0_54218263/article/details/114550380
原博文的名称为:
Python之Tushare模块实现股票分析案例

本例中:

代码实现如下:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tushare as ts

token = 'e64cb91a984780f85fad6e90b410e80eda93b238fba887f02f18e71e'
pro = ts.pro_api(token=token)
df = pro.daily(ts_code='000007.SZ', start_date='20160309', end_date='20200309')
df.to_csv('./data_of_trade')
df = pd.read_csv('./data_of_trade')
df = df.drop(['Unnamed: 0'], axis=1)
df = df.drop(['ts_code'], axis=1)
for i in range(654):
    df.iloc[i, 0] = str(df.iloc[i, 0])
df['trade_date'] = pd.to_datetime(df['trade_date'])
df = df.set_index(df['trade_date'])
df = df.drop(['trade_date'], axis=1)
# 1/
up_df = (df.loc[df['open'] < df['close']]).index
print(up_df)
down_df = (df.loc[df['open'] > df['close']]).index
print(down_df)
# 2/
time_list = list(df.index)
high_price_list = list(df['high'])
plt.figure(figsize=(200, 300), dpi=25)
plt.scatter(time_list, high_price_list, c='red', s=25, label='high_price')
plt.xticks(time_list, rotation=90, size=10)
plt.yticks(high_price_list, size=10)
plt.xlabel("x", fontdict={
    
    'size': 50})
plt.ylabel("y", fontdict={
    
    'size': 50})
plt.title("Chart", fontdict={
    
    'size': 50})
plt.legend(loc='best')
plt.show()


运行结果展示:
在这里插入图片描述

DatetimeIndex(['2020-03-09', '2020-03-06', '2020-03-05', '2020-03-04',
               '2020-03-03', '2020-03-02', '2020-02-28', '2020-02-25',
               '2020-02-24', '2020-02-18',
               ...
               '2016-08-15', '2016-08-12', '2016-08-10', '2016-08-08',
               '2016-08-03', '2016-08-01', '2016-07-29', '2016-07-26',
               '2016-07-25', '2016-07-20'],
              dtype='datetime64[ns]', name='trade_date', length=298, freq=None)
DatetimeIndex(['2020-02-27', '2020-02-26', '2020-02-21', '2020-02-20',
               '2020-02-19', '2020-02-14', '2020-02-11', '2020-01-23',
               '2020-01-22', '2020-01-21',
               ...
               '2016-08-11', '2016-08-09', '2016-08-05', '2016-08-04',
               '2016-08-02', '2016-07-28', '2016-07-27', '2016-07-22',
               '2016-07-21', '2016-07-19'],
              dtype='datetime64[ns]', name='trade_date', length=321, freq=None)

以及:
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_54218263/article/details/114575733