python-双均线预测能力检验2

简介: python-双均线预测能力检验2
# -*- coding: utf-8 -*-  
""" 
Created on Thu May 25 08:55:12 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 random
import matplotlib.pyplot as plt
import seaborn as sns
#获取数据  
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()  
value=[]  
for i in range(5,6):  
    for j in range(20,21):  
        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()  
        s=[i,j,target]  
        ts=time.strftime('%Y-%m-%d %X', time.localtime() )  
        value.append(s)  
        print('当前时间:{}短期参数:{},长期参数:{}优化完毕,净利润{}'.format(ts,i,j,s)) 
#基于蒙特卡洛模拟评估双均线的预测能力
data=df[['ret','cross']].fillna(0)
target_value=[]
for i in range(5000):
    li=list(data['ret'])
    random.shuffle(li)
    profit=(li*data['cross']).sum()
    print(profit)   
    target_value.append(profit)
target_value
plt.hist(target_value)
jianyan_profit=(data['ret']*data['cross']).sum()
jianyan_profit

20170608101941907.png

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

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