# -*- coding: utf-8 -*- """ Created on Wed Jun 7 10:22:18 2017 @author: yunjinqi E-mail:yunjinqi@qq.com Differentiate yourself in the world from anyone else. """ import pandas as pd import numpy as np import datetime import time import math import matplotlib.pyplot as plt import random #获取数据 df=pd.read_csv('C:/Users/HXWD/Desktop/rb000.csv',encoding='gbk') df.head() df.columns=['date','open','high','low','close','volume','amt'] df.head() ###########################原始数据 i=5 j=20 df['ma5']=df['close'].rolling(i).mean() df['ma20']=df['close'].rolling(j).mean() df.ix[df['ma5']>df['ma20'],'cross']=1 df.ix[df['ma5']<=df['ma20'],'cross']=-1 #df[['close','ma5','ma20']][-200:].plot() df['ret']=(df['close']-df['close'].shift(1))/df['close'].shift(1) df['profit']=df['ret']*df['cross'] #df['profit'].plot() #target=df['profit'].sum() target=df['profit'].dropna() plt.hist(target,bins=100) ######怀特真实检验,自举法 #从里面抽出来ll个数据作为一组,计算平均收益,抽取5000组进行计算 target=df['profit'].dropna() ll=len(target) ss=target.mean() target.sum() new_target=target-ll*[ss] new_target=pd.Series(list(new_target)) all_target=[] j=0 while j<5000: all_value=[] i=0 while i<len(new_target): value=new_target[random.randint(0,len(new_target)-1)] #print(value) all_value.append(value) i=i+1 all_value=pd.Series(all_value) all_target.append(all_value.sum()) j=j+1 print(j) plt.hist(all_target) jianyan_profit=df['profit'].sum() jianyan_profit
jianyan_profit Out[91]: 4.864976648275746
#基于随机的收益与策略的收益差距非常大,我们有理由相信,策略是具有预测能力的。