python双均线预测能力检验3

简介: python双均线预测能力检验3
# -*- 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

20170608105156265.png

jianyan_profit
Out[91]: 4.864976648275746

#基于随机的收益与策略的收益差距非常大,我们有理由相信,策略是具有预测能力的。

目录
相关文章
|
9月前
|
Python
使用Python实现股票均线策略
使用Python实现股票均线策略案例的简单示例
|
JSON 负载均衡 JavaScript
带你读《Elastic Stack 实战手册》之65:——3.5.19.1.Elasticsearch语言开发(Python)(上)
带你读《Elastic Stack 实战手册》之65:——3.5.19.1.Elasticsearch语言开发(Python)(上)
190 1
|
30天前
|
数据可视化 数据挖掘 Python
Python时间序列分析苹果股票数据:分解、平稳性检验、滤波器、滑动窗口平滑、移动平均、可视化(下)
Python时间序列分析苹果股票数据:分解、平稳性检验、滤波器、滑动窗口平滑、移动平均、可视化
|
30天前
|
数据可视化 API 开发者
Python时间序列分析苹果股票数据:分解、平稳性检验、滤波器、滑动窗口平滑、移动平均、可视化(上)
Python时间序列分析苹果股票数据:分解、平稳性检验、滤波器、滑动窗口平滑、移动平均、可视化
|
30天前
|
vr&ar Python
Python自激励阈值自回归(SETAR)、ARMA、BDS检验、预测分析太阳黑子时间序列数据
Python自激励阈值自回归(SETAR)、ARMA、BDS检验、预测分析太阳黑子时间序列数据
|
30天前
|
Python
python实现股票均线策略案例
此Python代码示例展示了如何运用均线策略进行股票交易模拟。它下载AAPL的股票历史数据,计算每日收益率,设置短期和长期移动平均线。当短期均线超过长期均线时,模拟买入;反之则卖出。代码遍历每一天,更新现金和股票余额,并最终计算总收益。请注意,实际交易需考虑更多因素如交易费用和风险管理。
31 2
|
30天前
|
存储 机器学习/深度学习 数据可视化
Python面板时间序列数据预测:格兰杰因果关系检验Granger causality test药品销售实例与可视化
Python面板时间序列数据预测:格兰杰因果关系检验Granger causality test药品销售实例与可视化
|
12月前
|
数据采集 数据挖掘 Python
python数据分析 - 卡方检验
python数据分析 - 卡方检验
241 0
|
12月前
|
数据挖掘 Python
python数据分析 - T检验与F检验:二组数据那个更好?(一)
python数据分析 - T检验与F检验:二组数据那个更好?(一)
184 0
|
存储 人工智能 运维
带你读《Elastic Stack 实战手册》之65:——3.5.19.1.Elasticsearch语言开发(Python)(下)
带你读《Elastic Stack 实战手册》之65:——3.5.19.1.Elasticsearch语言开发(Python)(下)
113 0