goodisme 发表于 2010-11-25 18:24

如何进行指标仿真交易和高频数据回测

我开发了一个针对股票、期货及期现套利的程序化交易程序,支持用Lua脚本语言进行策略编写,现在支持10几个策略,包括:MACD、CCI、OBV、RSI、SRV、单均线、双均线、克罗均线、海龟交易、网格交易、布林带区间突破、布林带震荡突破、时间价格突破等

1、MACD交易策略的核心函数
--策略逻辑从这里开始
function AutoTrade(indi, evalIndex, data, dataNumber,arg)
_IsDayTrade = false
    _CloseTime = 145500
    _AutoCancel = true
    _IsCheckQuantity = true

    -- the only time series data used in this indicator
    local data1 = data]
    local issueCode = data1.IssueCode
if not _QuantityTable then
      return
    end
local qty = _QuantityTable
indi.FastMA = indi.FastMA or {}--迭代计算快速MA用
indi.SlowMA = indi.SlowMA or {}--迭代计算慢速MA用
indi.Dea = indi.Dea or {}--迭代计算DEA用
indi.MACDDiff = indi.MACDDiff or {}--保存DIFF值用
indi.MACDDea = indi.MACDDea or {}--保存DEA值用
indi.MACD = indi.MACD or {}--保存MACD值用
--DIFF:EMA(CLOSE,SHORT) - EMA(CLOSE,LONG)
local diff = XAverage(indi.FastMA,evalIndex,data1.Close,spShort) - XAverage(indi.SlowMA,evalIndex,data1.Close,spLong)
indi.MACDDiff = diff
--DEA:EMA(DIFF,M)
local dea = XAverage(indi.Dea,evalIndex,indi.MACDDiff,spM)
indi.MACDDea = dea
--MACD: 2*(DIFF-DEA)
local macd = 2 * (diff - dea)
indi.MACD = macd

if diff then
_Ind1 = sys_format("%.02f", diff)
end
if dea then
_Ind2 = sys_format("%.02f", dea)
end
if macd then
_Ind3 = sys_format("%.02f", macd)
end

if indi.MACD < 0 and indi.MACD > 0 and _SubmitOrderFlag then--买入:MACD绿翻红(负转正)
if GetLongQty(issueCode) == 0 then
   EnterLong(issueCode, "", "Ask", "tic", 0, qty, "买进")
end
return
end
if indi.MACD > 0 and indi.MACD < 0 and _SubmitOrderFlag then--卖出:MACD红翻绿(正转负)
if GetAvailableLongQty(issueCode) > 0 and evalIndex > _BuyBarthen
   ExitLong(issueCode, "", "Bid", "tic", 0, GetAvailableLongQty(issueCode), "卖出")
end
return
end
end

2、MACD交易策略的启动参数
_DefineStrategyParameters
_String spBAMapID = "701-D-001"      //系统账户
_String spPeriodType = "d"               //d 日线,m 分钟线
_String spPeriodCount = "1"                //周期
_Number spDateBack = 25                // 向前追溯周期
_Number spInitFund = 100000            //账户资金
_String spMode = "A"--A:自动下单,M:手动下单
_Number spShort = 12
_Number spLong = 26
_Number spM = 9
_End

3、这策略用11月1日~3日的1分钟k线的回测结果如下,品种是IF1011,参数设置回测报告里面有的
http://bbs.macd.cn/attachments.php?aid=1893019&noupdate=yeshttp://bbs.macd.cn/images/D5/attachimg.gif


我可以帮助大家提供指标参数设置回测分析,并提供交易结果报表,数据周期是2009.10~2010.11,包括所有的股票、ETF、商品期货、股指期货的高频数据。有兴趣的可以联系我:
QQ:94544200,         msn:xc_wyn@hotmail.com

喜欢程序化交易,算法交易,金融工程的朋友,大家也可以做些交流,毕竟这是中国金融业发展趋势。


附件1:布林带区间突破交易策略的回测界面,测试数据为600000,时间为11月1日到11月25日,周期为1M K线。
http://bbs.macd.cn/attachments.php?aid=1893107&noupdate=yeshttp://bbs.macd.cn/images/D5/attachimg.gif

布林带区间突破交易策略的回测报告
http://bbs.macd.cn/attachments.php?aid=1893110&noupdate=yeshttp://bbs.macd.cn/images/D5/attachimg.gif

附件2:布林带振荡突破交易策略的回测界面,测试数据为600585,时间为11月1日到11月25日,周期为1M k线。
http://bbs.macd.cn/attachments.php?aid=1893121&noupdate=yeshttp://bbs.macd.cn/images/D5/attachimg.gif

布林带振荡突破交易策略的回测报告如下:
http://bbs.macd.cn/attachments.php?aid=1893122&noupdate=yeshttp://bbs.macd.cn/images/D5/attachimg.gif

附件3:双均线交易策略的回测界面,测试数据为600000,测试区间为11月1日到11月25日,周期为1M k线。
http://bbs.macd.cn/attachments.php?aid=1893219&noupdate=yeshttp://bbs.macd.cn/images/D5/attachimg.gif


双均线交易策略的回测报告如下:


http://bbs.macd.cn/attachments.php?aid=1893218&noupdate=yeshttp://bbs.macd.cn/images/D5/attachimg.gif


附件4:用于回测的高频数据格式如下:
期货
fu1103,4,4513,2,100616, ,2010/07/05 10:04:03.516,4513.000000,1,4484.000000,1,,,,,,,,,,,,,,,,,264.000000
IF1007,3,2510.2,2,100616, ,2010/07/05 10:04:03.559,2510.200000,6,2510.000000,11,,,,,,,,,,,,,,,,,27726.000000
SR1101,5,4915,16,100038, ,2010/07/05 10:04:03.568,4916.000000,50,4915.000000,901,,,,,,,,,,,,,,,,,679638.000000
指数
M000300,1,2500.095,14545,100607, ,2010/07/05 10:04:03.550,,,,,,,,,,,,,,,,,,,,,
深圳股票
000021,2,10.4,1000,100608, ,2010/07/05 10:04:03.735,10.390000,500,10.380000,6400,10.400000,23200,10.370000,11264,10.420000,3700,10.350000,2781,,,,,,,,,
000029,2,4.42,2400,100608, ,2010/07/05 10:04:03.739,4.450000,2300,4.420000,24600,4.460000,10100,4.410000,13500,4.470000,15900,4.400000,45600,4.480000,15200,4.390000,45102,4.490000,10900,4.380000,29300,
上海股票
600528,1,7.91,1000,101152, ,2010/07/05 10:09:46.870,7.910000,54400,7.900000,9707,7.920000,35300,7.890000,25400,7.930000,8700,7.880000,41865,,,,,,,,,
600530,1,7.79,100,101152, ,2010/07/05 10:09:46.874,7.790000,9143,7.780000,6600,,,,,,,,,,,,,,,,,

rypan1 发表于 2010-11-25 21:35

软件不错,策略太烂

杨太极 发表于 2010-11-26 07:49

以后会需要,呵呵

goodisme 发表于 2010-11-26 09:49

回复 #3 rypan1 的帖子

策略都是常用策略,可以通过代码修改来实现,其实策略好不好,和其适用性也有关系,比如一个简单的区间突破策略,从今年9月份到现在已经使资金量翻了2倍,同样的策略去年确亏的很厉害,所以也许是简单的MACD策略,如果适用性好,时间、参数、品种都符合,历史数据也能验证之,效果未必不好。

rypan1 发表于 2010-11-26 20:01

LZ准备把这个软件往哪个方面发展?

goodisme 发表于 2010-11-27 11:42

回复 #6 rypan1 的帖子

目前这个程序已经支持股票和期货的交易,对我而言,如何利用高频数据有效验证模型,后续主要目标是提升海量数据回测的性能,得出模型经过检验后的报告的精度,现实总是历史的翻版,规律总是在变的,唯有让思想系统化才能有迹可循。
页: [1]
查看完整版本: 如何进行指标仿真交易和高频数据回测