Price transfer function TA-Lib provided four modules, mainly for calculating the mean between the opening price, closing price, high, low, particularly in the following table.
AVGPRICE: average Price, average price function: ta.AVGPRICE (open, high, low, close)
MEDPRICE: Median Price, Median Price: ta.MEDPRICE (high, low)
TYPPRICE: Typical Price, Representative Price: ta.TYPPRICE (high, low, close)
WCLPRICE:Weighted Close Price, 加权收盘价:ta.WCLPRICE(high,low,close)
import pandas as pd import numpy as np import matplotlib.pyplot as plt import talib as ta import tushare as ts plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False def get_data(code, start='2015-01-01'): df = ts.get_k_data(code, start) df.index = pd.to_datetime(df.date) df =df.sort_index () return DF DF = get_Data ( ' SH ' ) [[ ' Open ' , ' Close ' , ' High ' , ' Low ' ]] # open, high, low, close, mean DF [ ' Average ' ] = ta.AVGPRICE (df.open, df.high, df.low, df.close) # high, low median DF [ ' median ' ] = ta.MEDPRICE (df.high, DF .low) # high, low, closing price mean DF [ ' Typical' ] = Ta.TYPPRICE (df.high, df.low, df.close) # high, low, closing price weighted DF [ ' weight ' ] = ta.WCLPRICE (df.high, df.low, DF .close) df.head () df.loc [ ' 2019-01-01 ' :, [ ' Close ' , ' Average ' , ' Median ' , ' Typical ' , ' weight ' ] ] .plot (figsize = (12 is ,. 6 )) AX = plt.gca () ax.spines [ 'right'] .set_color ( ' none ' ) ax.spines [ ' Top ' ] .set_color ( ' none ' ) plt.title ( ' Shanghai index and conversion price ' , fontSize = 15 ) plt.xlabel ( '' ) plt.show ()