After inquiry , Monthly yield =( Closing price at the end of this month - The closing price at the end of last month )/ The closing price at the end of last month
NetEase Finance - ZTE data , It is comprehensive and supports downloading historical data
http://quotes.money.163.com/trade/lsjysj_000063.html?year=1997&season=4
As month end data is required , But there are Spring Festival holidays and 2 The end of the month may not be 31 and 30 Number , Then there are more months and years , So take python To solve the problem ! According to the year - Group by month , Then return the first value of the group ( Month end data )
""" author: wpc date: 2020-12-16 16:30 """
# Introduce modules
import pandas as pd
import numpy as np
# Reading data , The encoding format is used wps. It helped me become GBK
df = pd.read_csv('data/zx.csv',encoding='GBK')
# Sequence processing , And become 1997-11 This format
df.index = pd.to_datetime(df[' date '])
time_month = df.index.strftime('%Y-%m')
# Will be 1997-11 Format data
df.index = time_month
df.groupby(df.index)
# call groupby Of first Method , Returns the first value . That is, the value at the end of the month
data = df.groupby(df.index).first()
# export csv file
data.to_csv('monthpro.csv',index=False,encoding='utf-8')
print(df)
And then you can use it Excel Make a simple formula and calculate it !!
Then I deleted what I didn't want , Then take a look at the export results !