d-找出結算日在陣列中的位置
import talib
import numpy as np
import tushare as ts
import matplotlib.pyplot as plt
import mpl_finance as mpf
import pandas as pd
#data = ts.get_k_data('399300', index=True, start='2017-01-01', end='2017-06-31')
data=pd.read_csv('2017_tx.csv',usecols=['date','open','close','high','low','volume'])
data=data.head(60)
#TA-lib wants numpy arrays of "double" floats as inputs. You want to convert it to double float data.-->np.array(data['close'],dtype=float)
fig = plt.figure(figsize=(17, 10))
'''
listA=['ab','23','yu','ki','ug'] #所有的成交日
listB=['ab','yu' ] #摩台結算日
retA = [listA.index(i) for i in listA if i in listB]
data_x = pd.read_csv("E:/Tianchi/result/features.csv",usecols=[2,3,4])#pd.dataframe
data_y = pd.read_csv("E:/Tianchi/result/features.csv",usecols=[5])
train_data = np.array(data_x)#np.ndarray()
train_x_list=train_data.tolist()#list
'''
#--------算出結算日在 日期陣列裡的位置 ------------
deadline_data = pd.read_csv('deadline_day.csv',usecols=['MTX']) #讀取摩台指 結算日之資料
test3 = np.array(deadline_data['MTX']).tolist()
test2 = np.array(data['date']).tolist() #首先使用np.array()函数把DataFrame转化为np.ndarray(),再利用tolist()函数把np.ndarray()转为list
#for j in test2
# print(j)
retA = [test2.index(i) for i in test2 if i in test3] #retA 結算日在 日期陣列裡的位置
print(retA)
#--------END OF 算出結算日在 日期陣列裡的位置 ------------
ax = fig.add_axes([0,0.2,1,0.5])
#------劃直線------------
fruits =retA
for x2 in fruits:
plt.axvline(x=x2, ymin=0, ymax = 20, linewidth=2, color='B')
#------劃直線------------
ax2 = fig.add_axes([0,0,1,0.2])
mpf.candlestick2_ochl(ax, data['open'], data['close'], data['high'], data['low'],
width=0.5, colorup='r', colordown='g', alpha=0.6)
ax.set_xticks(range(0, len(data['date']), 10))
ax.plot(sma_10, label='10 日均线')
ax.plot(sma_30, label='30 日均线')
ax.legend(loc='upper left')
ax.grid(True)
mpf.volume_overlay(ax2, data['open'], data['close'], data['volume'], colorup='r', colordown='g', width=0.5, alpha=0.8)
ax2.set_xticks(range(0, len(data['date']), 10))
ax2.set_xticklabels(data['date'][::10], rotation=30)
ax2.grid(True)
#plt.show()
plt.show()