重新温习pandas,优化了一下双均线系统之后,速度果然嗖嗖往上穿,和TB,文华这些有点可比性了。
# -*- 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 #获取数据 df=pd.read_csv('C:/Users/HXWD/Desktop/000001.csv',encoding='gbk') df.columns=['date','code','name','close','high','low','open','preclose', 'change','change_per','volume','amt'] df=df[['date','open','high','low','close','volume','amt']] df.head() value=[] for i in range(1,21): for j in range(21,121): 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['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=pd.DataFrame(value)
data.to_csv('参数优化.csv')