python測試平臺數(shù)據(jù)轉(zhuǎn)換以及日志_實現(xiàn)_第1頁
python測試平臺數(shù)據(jù)轉(zhuǎn)換以及日志_實現(xiàn)_第2頁
python測試平臺數(shù)據(jù)轉(zhuǎn)換以及日志_實現(xiàn)_第3頁
python測試平臺數(shù)據(jù)轉(zhuǎn)換以及日志_實現(xiàn)_第4頁
python測試平臺數(shù)據(jù)轉(zhuǎn)換以及日志_實現(xiàn)_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、測試轉(zhuǎn)化以及內(nèi)置函數(shù)Sohca介紹:測試設(shè)計的數(shù)據(jù)量很大,相比于,相對于處理大數(shù)據(jù)更加有優(yōu)勢,而且py來說,并不是特別穩(wěn)固。thon的數(shù)據(jù)結(jié)構(gòu)導(dǎo)致了不太容易出錯,不過下面的是更新日志:15.8.151:index數(shù)據(jù),需要加上-SZ2:日線數(shù)據(jù) -DAY 分鐘數(shù)據(jù) -min3:運行的時候注意變量4:hdf存放到mat數(shù)據(jù)的根目錄之下15.8.171:解決了復(fù)權(quán)數(shù)據(jù)的問題2:把大部分的函數(shù)都放到一個自有模塊之中了3:規(guī)整化數(shù)據(jù)格式trade_info=pd.DataFrame(code:,datestr:,index_next_day_ret:,symbol_next_day_ret:),下一步

2、需要一個挑錯的東西def modify_index_m import time as tm import pandas as pdcurrent_list=y_pd):for cycle in range(len(my_pd.datenum):current_datestr=str(my_pd.datenumcycle)current_timestr=str(my_pd.timcycle)current_datetime_str=current_datestr+ +current_timestr pdatetime=tm.strptime(current_datetime_str,%Y%m%d

3、 %H%M) fdatetime= tm.strftime(%Y-%m-%d %H:%M, pdatetime)current_list.append(fdatetime)series=pd.DataFrame(datetime str:current_list)out=pd.merge(series,my_pd,left_index=True,right_index=True)out=out.drop(datenum,axis=1)out=out.drop(tim,axis=1)out.index=outdatetime str out=out.drop(datetime str,axis=

4、1)return(out)def modify_index_day(my_pd):import time as tm import pandas as pd current_list=for cycle in range(len(my_pd.datenum): current_datestr=str(my_pd.datenumcycle) current_datetime_str=current_datestr pdatetime=tm.strptime(current_datetime_str,%Y%m%d) fdatetime= tm.strftime(%Y-%m-%d, pdatetim

5、e)current_list.append(fdatetime)series=pd.DataFrame(date str:current_list)out=pd.merge(series,my_pd,left_index=True,right_index=True) out=out.drop(datenum,axis=1)out.index=outdate strout=out.drop(date str,axis=1) return(out)def conver_mat_to_pd_day(code_name,file_path): import scipy.io as sioimport

6、pandas as pd cur_file_name=code_name+.mat cur_data=sio.loadmat(file_path+cur_file_name) cur_dur_dataDAY_datacol_ss=(datenum,code_name+_pre_close,code_name+_open,code_name+_high,code_name+_low,code_name+_close,code_name+_vol)cur_pd=pd.DataFrame(cur_dolumns=col_ss)cur_pd=modify_index_day(cur_pd)#均線數(shù)據(jù)的

7、處理ma_list = 5, 10, 20,40,60#獲取均線參數(shù)for maa_list:cur_pdcode_name+_ma+ str(ma) = pd.rolling_mean(cur_pdcode_name+_close, ma)#均線數(shù)據(jù)的處理#當(dāng)日波動收益率和下一日波動收益率的處理 def day_ret(x):return (x-1-x-2)/x-2)cur_pdcode_name+_dayret=(pd.rolling_apply(cur_pdcode_name+_close, 2, lambdaday_ret(x)x:#這里獲取下一個交易的收益率 tmp_df=pd.Da

8、taFrame(code_name+_next_dayret:cur_pdcode_name+_dayret) tmp_df=tmp_df.drop(tmp_df.index0)append_df=(code_name+_next_dayret:0) tmp_df=tmp_df.append(append_df,ignore_index=True)tmp_df.index=cur_pd.index#我也是醉了,竟然是要求index相等的時候才能這么賦值 cur_pdcode_name+_next_dayret=tmp_df#這里獲取下一個交易日的收益率#當(dāng)日波動收益率和下一日波動收益率的處理c

9、ur_pd.to_hdf(file_path+hdf+code_name, df)#保存文件return(cur_pd)#def candle_my_pd(plot_pd,symbol_prf): from pylab import date2numimport matplotlib.pyplot as plt import datetimefrom matplotlib.dates import DateFormatterfrom matplotlib.finance import candlestick, plot_day_summary, candlestick2 import pand

10、as as pdimport numpy as npplot_pdtemp=pd.to_datetime(plot_pd.index,format=%Y-%m-%d)all_list=;for cycle in range(len(plot_pd.temp): temp_list=temp_list.append(date2num(plot_pd.tempcycle) temp_list.append(plot_pdsymbol_prf+opencycle) temp_list.append(plot_pdsymbol_prf+closecycle) temp_list.append(plot

11、_pdsymbol_prf+highcycle) temp_list.append(plot_pdsymbol_prf+lowcycle)all_list.append(temp_list)fig, ax = plt.subplots() fig.subplots_adjust(bottom=0.2) candlestick(ax, all_list, width=0.2) ax.xaxis_date() plt.title(symbol_prf0:6)plt.show()def candle_mysymbol(code,path): from pylab import date2num im

12、port matplotlib.pyplot as plt from datetime import datetimefrom matplotlib.dates import DateFormatterfrom matplotlib.finance import candlestick, plot_day_summary, candlestick2 import pandas as pdimport numpy as npsymbol_data=pd.read_hdf(path+code-DAY.replace(code,code), df)symbol_prf=code+-DAY_symbo

13、l_datatemp=pd.to_datetime(symbol_data.index,format=%Y-%m-%d)all_list=;for cycle in range(len(symbol_da temp_list=emp):temp_list.append(date2num(symbol_daempcycle)temp_list.append(symbol_datasymbol_prf+opencycle) temp_list.append(symbol_datasymbol_prf+closecycle) temp_list.append(symbol_datasymbol_pr

14、f+highcycle) temp_list.append(symbol_datasymbol_prf+lowcycle)all_list.append(temp_list)fig, ax = plt.subplots() fig.subplots_adjust(bottom=0.2) candlestick(ax, all_list, width=0.2) ax.xaxis_date()plt.title(code)plt.show()def disp_trade_result(trade_info): from scipy.ss import ttest_rel import matplo

15、tlib.pyplot as plt import numpy as nptrade_info.index=trade_infoentry_date_strtrade_info=trade_info.drop(entry_date_str,axis=1)#丟棄某一列注意這里的意思 trade_info=trade_info.sort_index(axis=0)#對df結(jié)構(gòu)進(jìn)行索引排序#pr pr prpr出來一些重要的參量(大盤單筆交易平均收益率:+str(trade_info.index_ret_ratio.mean() (個股單筆交易平均收益率:+str(trade_info.symbol

16、_ret_ratio.mean() (雙樣本Ttest檢驗:TVALUE和PVALUE)pr(ttest_rel(trade_info.index_ret_ratio,trade_info.symbol_ret_ratio)pr(樣本量:+str(len(trade_info)temp_len=len(trade_infotrade_info.symbol_ret_ratio=0)pr(的樣本的概率為:+str(temp_len/len(trade_info)temp_len2=len(trade_infotrade_info.spread_ret_ratio=0)pr(的樣本的概率為:+st

17、r(temp_len2/len(trade_info)之后相對#下面獲取當(dāng)天的平均alpha收益率 trade_infogroup_key=trade_info.indexgrouped_mean=trade_infospread_ret_ratio.groupby(trade_infogroup_key).mean()plotdata4=umsum(grouped_mean)plt.plot(plotdata4)plt.title(alpha curve) plt.show()#下面獲取當(dāng)天的平均日收益率 trade_infogroup_key=trade_info.indexgrouped

18、_mean=trade_infosymbol_ret_ratio.groupby(trade_infogroup_key).mean()grouped_mean=grouped_mean.sort_index(ascending=True)plotdata4=umsum(grouped_mean)plt.plot(plotdata4) plt.title(stock curve) plt.show()trade_info=trade_info.drop(group_key,axis=1) pr(平均單日收益率:)pr(plotdata4len(plotdata4)-1/len(plotdata4)def init_trade_info():#初始化交易的條件 im

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論