在量化交易中,策略参数的选择直接影响其表现 —— 同一策略在不同参数下可能呈现截然不同的收益特征。然而,盲目测试参数组合不仅效率低下,还可能因 “过度拟合” 导致策略在实盘失效。本文将解析一段基于 R 语言quantstrat包的 MACD 策略参数优化代码,展示如何系统地测试参数范围、施加合理约束,并通过统计指标验证参数有效性,为策略稳健性提供科学依据。
代码实现与核心注释
以下是完整的 MACD 参数优化代码,包含详细注释以说明各环节的功能与逻辑:
# Parameter demo for MACD
###############################################################################
# 加载必要的包:foreach支持并行迭代,iterators用于迭代控制,quantstrat用于量化策略开发
require(foreach, quietly=TRUE)
require(iterators)
require(quantstrat)
# 运行内置的MACD策略演示,初始化策略环境(包含策略定义、交易标的、账户等基础设置)
demo('macd', ask=FALSE)
##
##
## demo(macd)
## ---- ~~~~
##
## > # Simple MACD strategy
## > #
## > # MACD may be used in many ways, this will demonstrate a trend indicator.
## > #
## > # traditionally, when the MACD signal crosses zero, this indicated a establishment of a positive trend
## > #
## > # we'll buy on positive treshold crossover of the 'signal' column, and sell on negative threshold crossover
## > #
## > # Author: brian
## > ###############################################################################
## >
## >
## > require(quantstrat)
##
## > suppressWarnings(rm("order_book.macd",pos=.strategy))
##
## > suppressWarnings(rm("account.macd","portfolio.macd",pos=.blotter))
##
## > suppressWarnings(rm("account.st","portfolio.st","stock.str","stratMACD","startDate","initEq",'start_t','end_t'))
##
## > #correct for TZ issues if they crop up
## > oldtz<-Sys.getenv('TZ')
##
## > if(oldtz=='') {
## + Sys.setenv(TZ="GMT")
## + }
##
## > stock.str='AAPL' # what are we trying it on
##
## > #MA parameters for MACD
## > fastMA = 12
##
## > slowMA = 26
##
## > signalMA = 9
##
## > maType="EMA"
##
## > currency('USD')
## [1] "USD"
##
## > stock(stock.str,currency='USD',multiplier=1)
## [1] "AAPL"
##
## > #or use fake data
## > #stock.str='sample_matrix' # what are we trying it on
## > #data(sample_matrix) # data included in package xts
## > #sample_matrix<-as.xts(sample_matrix)
## >
## > startDate='2006-12-31'
##
## > initEq=1000000
##
## > portfolio.st='macd'
##
## > account.st='macd'
##
## > initPortf(portfolio.st,symbols=stock.str)
## [1] "macd"
##
## > initAcct(account.st,portfolios=portfolio.st)
## [1] "macd"
##
## > initOrders(portfolio=portfolio.st)
##
## > strat.st<-portfolio.st
##
## > # define the strategy
## > strategy(strat.st, store=TRUE)
##
## > #one indicator
## > add.indicator(strat.st, name = "MACD",
## + arguments = list(x=quote(Cl(mktdata)),
## + nFast=fastMA,
## + nSlow=slowMA),
## + label='_'
## + )
## [1] "macd"
##
## > #two signals
## > add.signal(strat.st,name="sigThreshold",
## + arguments = list(column="signal._",
## + relationship="gt",
## + threshold=0,
## + cross=TRUE),
## + label="signal.gt.zero"
## + )
## [1] "macd"
##
## > add.signal(strat.st,name="sigThreshold",
## + arguments = list(column="signal._",
## + relationship="lt",
## + threshold=0,
## + cross=TRUE),
## + label="signal.lt.zero"
## + )
## [1] "macd"
##
## > ####
## > # add rules
## >
## > # entry
## > add.rule(strat.st,name='ruleSignal',
## + arguments = list(sigcol="signal.gt.zero",
## + sigval=TRUE,
## + orderqty=100,
## + ordertype='market',
## + orderside='long',
## + threshold=NULL),
## + type='enter',
## + label='enter',
## + storefun=FALSE
## + )
## [1] "macd"
##
## > #alternatives for risk stops:
## > # simple stoplimit order, with threshold multiplier
## > #add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty='all', ordertype='stoplimit', orderside='long', threshold=-.05,tmult=TRUE, orderset='exit2'),type='chain', parent='enter', label='risk',storefun=FALSE)
## > # alternately, use a trailing order, also with a threshold multiplier
## > #add.rule(strat.st,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty='all', ordertype='stoptrailing', orderside='long', threshold=-1,tmult=FALSE, orderset='exit2'), type='chain', parent='enter', label='trailingexit')
## >
## > # exit
## > add.rule(strat.st,name='ruleSignal',
## + arguments = list(sigcol="signal.lt.zero",
## + sigval=TRUE,
## + orderqty='all',
## + ordertype='market',
## + orderside='long',
## + threshold=NULL,
## + orderset='exit2'),
## + type='exit',
## + label='exit'
## + )
## [1] "macd"
##
## > #end rules
## > ####
## >
## > getSymbols(stock.str,from=startDate, to='2014-06-01', src='yahoo')
## [1] "AAPL"
##
## > start_t<-Sys.time()
##
## > out<-applyStrategy(strat.st , portfolios=portfolio.st,parameters=list(nFast=fastMA, nSlow=slowMA, nSig=signalMA,maType=maType),verbose=TRUE)
## [1] "2007-03-16 00:00:00 AAPL 100 @ 3.19964289665222"
## [1] "2007-08-17 00:00:00 AAPL -100 @ 4.35928583145142"
## [1] "2007-09-05 00:00:00 AAPL 100 @ 4.88428592681885"
## [1] "2008-01-16 00:00:00 AAPL -100 @ 5.70142889022827"
## [1] "2008-03-31 00:00:00 AAPL 100 @ 5.125"
## [1] "2008-06-26 00:00:00 AAPL -100 @ 6.00928592681885"
## [1] "2008-08-20 00:00:00 AAPL 100 @ 6.28000020980835"
## [1] "2008-09-09 00:00:00 AAPL -100 @ 5.41714286804199"
## [1] "2009-02-06 00:00:00 AAPL 100 @ 3.56142902374268"
## [1] "2009-03-04 00:00:00 AAPL -100 @ 3.25607109069824"
## [1] "2009-03-19 00:00:00 AAPL 100 @ 3.62928605079651"
## [1] "2009-12-15 00:00:00 AAPL -100 @ 6.93464279174805"
## [1] "2009-12-29 00:00:00 AAPL 100 @ 7.46785688400269"
## [1] "2010-02-03 00:00:00 AAPL -100 @ 7.11535692214966"
## [1] "2010-03-04 00:00:00 AAPL 100 @ 7.52535676956177"
## [1] "2010-07-16 00:00:00 AAPL -100 @ 8.92500019073486"
## [1] "2010-08-03 00:00:00 AAPL 100 @ 9.35464286804199"
## [1] "2010-08-17 00:00:00 AAPL -100 @ 8.99892902374268"
## [1] "2010-09-15 00:00:00 AAPL 100 @ 9.65071392059326"
## [1] "2011-03-22 00:00:00 AAPL -100 @ 12.1857137680054"
## [1] "2011-05-03 00:00:00 AAPL 100 @ 12.4357137680054"
## [1] "2011-05-23 00:00:00 AAPL -100 @ 11.9428567886353"
## [1] "2011-07-11 00:00:00 AAPL 100 @ 12.6428565979004"
## [1] "2011-11-16 00:00:00 AAPL -100 @ 13.7417860031128"
## [1] "2011-12-27 00:00:00 AAPL 100 @ 14.518928527832"
## [1] "2012-05-09 00:00:00 AAPL -100 @ 20.3278560638428"
## [1] "2012-06-20 00:00:00 AAPL 100 @ 20.9192867279053"
## [1] "2012-10-12 00:00:00 AAPL -100 @ 22.4896430969238"
## [1] "2013-05-09 00:00:00 AAPL 100 @ 16.3132133483887"
## [1] "2013-06-19 00:00:00 AAPL -100 @ 15.1071434020996"
## [1] "2013-07-26 00:00:00 AAPL 100 @ 15.7496433258057"
## [1] "2014-01-22 00:00:00 AAPL -100 @ 19.6967868804932"
## [1] "2014-01-24 00:00:00 AAPL 100 @ 19.5025005340576"
## [1] "2014-01-29 00:00:00 AAPL -100 @ 17.8839282989502"
## [1] "2014-03-26 00:00:00 AAPL 100 @ 19.2778568267822"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
##
## > end_t<-Sys.time()
##
## > print(end_t-start_t)
## Time difference of 0.437279 secs
##
## > start_t<-Sys.time()
##
## > updatePortf(Portfolio=portfolio.st,Dates=paste('::',as.Date(Sys.time()),sep=''))
## [1] "macd"
##
## > end_t<-Sys.time()
##
## > print("trade blotter portfolio update:")
## [1] "trade blotter portfolio update:"
##
## > print(end_t-start_t)
## Time difference of 0.05017185 secs
##
## > chart.Posn(Portfolio=portfolio.st,Symbol=stock.str)
##
## > plot(add_MACD(fast=fastMA, slow=slowMA, signal=signalMA,maType="EMA"))
##
## > #look at the order book
## > obook<-getOrderBook('macd')
##
## > # set tz as it was before the demo
## > Sys.setenv(TZ=oldtz)
##
## > ###############################################################################
## > # R (http://r-project.org/) Quantitative Strategy Model Framework
## > #
## > # Copyright (c) 2009-2012
## > # Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich
## > #
## > # This library is distributed under the terms of the GNU Public License (GPL)
## > # for full details see the file COPYING
## > #
## > # $Id$
## > #
## > ##############################################################################
# 并行计算初始化(可选):启用后可加速参数组合测试,适合大规模参数搜索
# 推荐使用doParallel、doMC等包,默认使用物理核心数-1的线程提升效率
# require(doParallel)
# registerDoParallel()
# 从环境中获取MACD策略对象(内置demo中已定义并存储策略,label为'macd')
strategy.st <- 'macd'
### 设置参数搜索范围
.FastMA = (1:20) # MACD快速EMA周期候选值(1到20日):反映短期价格动量
.SlowMA = (30:80) # MACD慢速EMA周期候选值(30到80日):反映中长期价格趋势
.nsamples = 30 # 随机抽样的参数组合数量:减少全量测试的计算成本,同时覆盖关键组合
### 定义参数分布与约束
# 为策略添加快速EMA周期的参数分布
add.distribution(
strategy.st, # 目标策略名称
paramset.label = 'MA', # 参数集标签(用于标识该组参数)
component.type = 'indicator', # 组件类型:指标(此处为MACD的快速EMA)
component.label = '_', # 指标在策略中的标识(对应MACD指标的默认标签)
variable = list(n = .FastMA), # 待测试的参数:快速EMA周期,取值范围1-20
label = 'nFAST' # 参数标签(用于后续约束与结果识别)
)
## [1] "macd"
# 为策略添加慢速EMA周期的参数分布
add.distribution(
strategy.st,
paramset.label = 'MA',
component.type = 'indicator',
component.label = '_',
variable = list(n = .SlowMA), # 待测试的参数:慢速EMA周期,取值范围30-80
label = 'nSLOW' # 参数标签
)
## [1] "macd"
# 添加参数约束:确保快速EMA周期小于慢速EMA周期(MACD指标的核心逻辑要求)
add.distribution.constraint(
strategy.st,
paramset.label = 'MA',
distribution.label.1 = 'nFAST', # 第一个参数:快速EMA周期
distribution.label.2 = 'nSLOW', # 第二个参数:慢速EMA周期
operator = '<', # 约束关系:nFAST < nSLOW
label = 'MA' # 约束标签
)
## [1] "macd"
### 执行参数优化并分析结果
.audit <- new.env() # 创建环境存储审计信息,用于后续有效性验证
# 应用参数集测试策略表现
results <- apply.paramset(
strategy.st, # 策略名称
paramset.label = 'MA', # 使用的参数集标签
portfolio.st = portfolio.st, # 组合名称(来自内置MACD演示)
account.st = account.st, # 账户名称(来自内置MACD演示)
nsamples = .nsamples, # 随机抽样的参数组合数量(30组)
audit = .audit, # 存储审计数据的环境
store = TRUE, # 保存结果到策略环境
verbose = TRUE # 输出详细过程信息
)
## evaluation # 1:
## $param.combo
## nFAST nSLOW
## 441 1 52
##
## [1] "2008-04-22 00:00:00 AAPL 100 @ 5.72142887115479"
## [1] "2008-07-30 00:00:00 AAPL -100 @ 5.71000003814697"
## [1] "2008-09-02 00:00:00 AAPL 100 @ 5.93535709381104"
## [1] "2008-09-09 00:00:00 AAPL -100 @ 5.41714286804199"
## [1] "2009-03-26 00:00:00 AAPL 100 @ 3.92392897605896"
## [1] "2010-08-30 00:00:00 AAPL -100 @ 8.6607141494751"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-05-27 00:00:00 AAPL -100 @ 12.0503568649292"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-12-01 00:00:00 AAPL -100 @ 13.854642868042"
## [1] "2011-12-29 00:00:00 AAPL 100 @ 14.4685707092285"
## [1] "2012-11-05 00:00:00 AAPL -100 @ 20.8792858123779"
## [1] "2013-08-07 00:00:00 AAPL 100 @ 16.6064281463623"
## [1] "2014-02-11 00:00:00 AAPL -100 @ 19.141429901123"
## [1] "2014-04-02 00:00:00 AAPL 100 @ 19.3767852783203"
## [1] "2014-04-16 00:00:00 AAPL -100 @ 18.5360717773438"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b1c696b0>
## got results for task 1
## numValues: 1, numResults: 1, stopped: FALSE
## returning status FALSE
## evaluation # 2:
## $param.combo
## nFAST nSLOW
## 243 3 42
##
## [1] "2008-04-16 00:00:00 AAPL 100 @ 5.48928594589233"
## [1] "2008-07-25 00:00:00 AAPL -100 @ 5.78999996185303"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-03-24 00:00:00 AAPL 100 @ 3.80357098579407"
## [1] "2010-02-24 00:00:00 AAPL -100 @ 7.16642904281616"
## [1] "2010-03-03 00:00:00 AAPL 100 @ 7.47607088088989"
## [1] "2010-08-26 00:00:00 AAPL -100 @ 8.58142852783203"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-04-18 00:00:00 AAPL -100 @ 11.85178565979"
## [1] "2011-05-05 00:00:00 AAPL 100 @ 12.3839292526245"
## [1] "2011-05-25 00:00:00 AAPL -100 @ 12.0278568267822"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-29 00:00:00 AAPL -100 @ 13.3285713195801"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-10-31 00:00:00 AAPL -100 @ 21.2614288330078"
## [1] "2013-06-07 00:00:00 AAPL 100 @ 15.7789287567139"
## [1] "2013-06-19 00:00:00 AAPL -100 @ 15.1071434020996"
## [1] "2013-08-06 00:00:00 AAPL 100 @ 16.6160717010498"
## [1] "2014-02-07 00:00:00 AAPL -100 @ 18.5599994659424"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b1c69790>
## got results for task 2
## numValues: 2, numResults: 2, stopped: FALSE
## returning status FALSE
## evaluation # 3:
## $param.combo
## nFAST nSLOW
## 343 3 47
##
## [1] "2008-04-18 00:00:00 AAPL 100 @ 5.75142908096313"
## [1] "2008-07-29 00:00:00 AAPL -100 @ 5.6100001335144"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-03-25 00:00:00 AAPL 100 @ 3.80321407318115"
## [1] "2010-08-27 00:00:00 AAPL -100 @ 8.62928581237793"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-04-20 00:00:00 AAPL -100 @ 12.228928565979"
## [1] "2011-05-03 00:00:00 AAPL 100 @ 12.4357137680054"
## [1] "2011-05-26 00:00:00 AAPL -100 @ 11.9642858505249"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-11-30 00:00:00 AAPL -100 @ 13.6499996185303"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-11-02 00:00:00 AAPL -100 @ 20.6000003814697"
## [1] "2013-08-07 00:00:00 AAPL 100 @ 16.6064281463623"
## [1] "2014-02-10 00:00:00 AAPL -100 @ 18.8924999237061"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b43aa028>
## got results for task 3
## numValues: 3, numResults: 3, stopped: FALSE
## returning status FALSE
## evaluation # 4:
## $param.combo
## nFAST nSLOW
## 184 4 39
##
## [1] "2008-04-15 00:00:00 AAPL 100 @ 5.29928588867188"
## [1] "2008-07-24 00:00:00 AAPL -100 @ 5.67964315414429"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-03-23 00:00:00 AAPL 100 @ 3.84500002861023"
## [1] "2010-02-19 00:00:00 AAPL -100 @ 7.2024998664856"
## [1] "2010-03-04 00:00:00 AAPL 100 @ 7.52535676956177"
## [1] "2010-08-25 00:00:00 AAPL -100 @ 8.67464256286621"
## [1] "2010-09-20 00:00:00 AAPL 100 @ 10.1153573989868"
## [1] "2011-04-15 00:00:00 AAPL -100 @ 11.6949996948242"
## [1] "2011-05-06 00:00:00 AAPL 100 @ 12.3807144165039"
## [1] "2011-05-25 00:00:00 AAPL -100 @ 12.0278568267822"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-28 00:00:00 AAPL -100 @ 13.4328565597534"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-06-06 00:00:00 AAPL -100 @ 20.4092864990234"
## [1] "2012-06-20 00:00:00 AAPL 100 @ 20.9192867279053"
## [1] "2012-10-31 00:00:00 AAPL -100 @ 21.2614288330078"
## [1] "2013-06-05 00:00:00 AAPL 100 @ 15.896785736084"
## [1] "2013-06-20 00:00:00 AAPL -100 @ 14.8871431350708"
## [1] "2013-08-06 00:00:00 AAPL 100 @ 16.6160717010498"
## [1] "2014-02-06 00:00:00 AAPL -100 @ 18.3039283752441"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b37266a0>
## got results for task 4
## numValues: 4, numResults: 4, stopped: FALSE
## returning status FALSE
## evaluation # 5:
## $param.combo
## nFAST nSLOW
## 604 4 60
##
## [1] "2008-04-23 00:00:00 AAPL 100 @ 5.81750011444092"
## [1] "2008-08-01 00:00:00 AAPL -100 @ 5.59499979019165"
## [1] "2008-08-28 00:00:00 AAPL 100 @ 6.20499992370605"
## [1] "2008-09-10 00:00:00 AAPL -100 @ 5.41464281082153"
## [1] "2009-03-27 00:00:00 AAPL 100 @ 3.81607103347778"
## [1] "2010-09-01 00:00:00 AAPL -100 @ 8.94035720825195"
## [1] "2010-09-16 00:00:00 AAPL 100 @ 9.8774995803833"
## [1] "2011-06-07 00:00:00 AAPL -100 @ 11.8585710525513"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-12-06 00:00:00 AAPL -100 @ 13.9624996185303"
## [1] "2011-12-28 00:00:00 AAPL 100 @ 14.3800001144409"
## [1] "2012-11-06 00:00:00 AAPL -100 @ 20.8160705566406"
## [1] "2013-08-08 00:00:00 AAPL 100 @ 16.4646434783936"
## [1] "2014-02-26 00:00:00 AAPL -100 @ 18.47678565979"
## [1] "2014-03-31 00:00:00 AAPL 100 @ 19.1692867279053"
## [1] "2014-04-17 00:00:00 AAPL -100 @ 18.7478561401367"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b0218098>
## got results for task 5
## numValues: 5, numResults: 5, stopped: FALSE
## returning status FALSE
## evaluation # 6:
## $param.combo
## nFAST nSLOW
## 525 5 56
##
## [1] "2008-04-22 00:00:00 AAPL 100 @ 5.72142887115479"
## [1] "2008-07-31 00:00:00 AAPL -100 @ 5.67678594589233"
## [1] "2008-08-29 00:00:00 AAPL 100 @ 6.05464315414429"
## [1] "2008-09-09 00:00:00 AAPL -100 @ 5.41714286804199"
## [1] "2009-03-26 00:00:00 AAPL 100 @ 3.92392897605896"
## [1] "2010-08-31 00:00:00 AAPL -100 @ 8.68214321136475"
## [1] "2010-09-16 00:00:00 AAPL 100 @ 9.8774995803833"
## [1] "2011-05-31 00:00:00 AAPL -100 @ 12.4224996566772"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-12-02 00:00:00 AAPL -100 @ 13.917857170105"
## [1] "2011-12-29 00:00:00 AAPL 100 @ 14.4685707092285"
## [1] "2012-11-05 00:00:00 AAPL -100 @ 20.8792858123779"
## [1] "2013-08-08 00:00:00 AAPL 100 @ 16.4646434783936"
## [1] "2014-02-13 00:00:00 AAPL -100 @ 19.4439296722412"
## [1] "2014-04-01 00:00:00 AAPL 100 @ 19.3446426391602"
## [1] "2014-04-16 00:00:00 AAPL -100 @ 18.5360717773438"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b3650aa0>
## got results for task 6
## numValues: 6, numResults: 6, stopped: FALSE
## returning status FALSE
## evaluation # 7:
## $param.combo
## nFAST nSLOW
## 765 5 68
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-04 00:00:00 AAPL -100 @ 5.47249984741211"
## [1] "2008-08-27 00:00:00 AAPL 100 @ 6.23821401596069"
## [1] "2008-09-10 00:00:00 AAPL -100 @ 5.41464281082153"
## [1] "2009-03-31 00:00:00 AAPL 100 @ 3.75428605079651"
## [1] "2010-09-03 00:00:00 AAPL -100 @ 9.24178600311279"
## [1] "2010-09-13 00:00:00 AAPL 100 @ 9.53714275360107"
## [1] "2011-06-13 00:00:00 AAPL -100 @ 11.66428565979"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2012-11-07 00:00:00 AAPL -100 @ 19.9285717010498"
## [1] "2013-08-12 00:00:00 AAPL 100 @ 16.6914291381836"
## [1] "2014-04-21 00:00:00 AAPL -100 @ 18.9703578948975"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b3648c98>
## got results for task 7
## numValues: 7, numResults: 7, stopped: FALSE
## returning status FALSE
## evaluation # 8:
## $param.combo
## nFAST nSLOW
## 985 5 79
##
## [1] "2008-04-28 00:00:00 AAPL 100 @ 6.15142917633057"
## [1] "2008-08-06 00:00:00 AAPL -100 @ 5.86392879486084"
## [1] "2008-08-25 00:00:00 AAPL 100 @ 6.16249990463257"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-02 00:00:00 AAPL 100 @ 4.02535676956177"
## [1] "2011-06-16 00:00:00 AAPL -100 @ 11.6128568649292"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2012-11-09 00:00:00 AAPL -100 @ 19.5378570556641"
## [1] "2013-08-14 00:00:00 AAPL 100 @ 17.8035717010498"
## result of evaluating expression:
## <environment: 0x7fa4b08b4e18>
## got results for task 8
## numValues: 8, numResults: 8, stopped: FALSE
## returning status FALSE
## evaluation # 9:
## $param.combo
## nFAST nSLOW
## 626 6 61
##
## [1] "2008-04-23 00:00:00 AAPL 100 @ 5.81750011444092"
## [1] "2008-08-01 00:00:00 AAPL -100 @ 5.59499979019165"
## [1] "2008-08-28 00:00:00 AAPL 100 @ 6.20499992370605"
## [1] "2008-09-10 00:00:00 AAPL -100 @ 5.41464281082153"
## [1] "2009-03-27 00:00:00 AAPL 100 @ 3.81607103347778"
## [1] "2010-09-01 00:00:00 AAPL -100 @ 8.94035720825195"
## [1] "2010-09-15 00:00:00 AAPL 100 @ 9.65071392059326"
## [1] "2011-06-08 00:00:00 AAPL -100 @ 11.8657140731812"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-12-06 00:00:00 AAPL -100 @ 13.9624996185303"
## [1] "2011-12-28 00:00:00 AAPL 100 @ 14.3800001144409"
## [1] "2012-11-06 00:00:00 AAPL -100 @ 20.8160705566406"
## [1] "2013-08-09 00:00:00 AAPL 100 @ 16.2303562164307"
## [1] "2014-02-27 00:00:00 AAPL -100 @ 18.8453578948975"
## [1] "2014-03-31 00:00:00 AAPL 100 @ 19.1692867279053"
## [1] "2014-04-17 00:00:00 AAPL -100 @ 18.7478561401367"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4aaac46a0>
## got results for task 9
## numValues: 9, numResults: 9, stopped: FALSE
## returning status FALSE
## evaluation # 10:
## $param.combo
## nFAST nSLOW
## 167 7 38
##
## [1] "2008-04-15 00:00:00 AAPL 100 @ 5.29928588867188"
## [1] "2008-07-24 00:00:00 AAPL -100 @ 5.67964315414429"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-02-23 00:00:00 AAPL 100 @ 3.1053569316864"
## [1] "2009-03-02 00:00:00 AAPL -100 @ 3.14071393013"
## [1] "2009-03-23 00:00:00 AAPL 100 @ 3.84500002861023"
## [1] "2010-02-18 00:00:00 AAPL -100 @ 7.24749994277954"
## [1] "2010-03-05 00:00:00 AAPL 100 @ 7.81964302062988"
## [1] "2010-08-25 00:00:00 AAPL -100 @ 8.67464256286621"
## [1] "2010-09-20 00:00:00 AAPL 100 @ 10.1153573989868"
## [1] "2011-04-15 00:00:00 AAPL -100 @ 11.6949996948242"
## [1] "2011-05-06 00:00:00 AAPL 100 @ 12.3807144165039"
## [1] "2011-05-25 00:00:00 AAPL -100 @ 12.0278568267822"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-28 00:00:00 AAPL -100 @ 13.4328565597534"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-06-05 00:00:00 AAPL -100 @ 20.1010704040527"
## [1] "2012-06-21 00:00:00 AAPL 100 @ 20.6310710906982"
## [1] "2012-10-26 00:00:00 AAPL -100 @ 21.5714282989502"
## [1] "2013-06-04 00:00:00 AAPL 100 @ 16.0467853546143"
## [1] "2013-06-21 00:00:00 AAPL -100 @ 14.7678565979004"
## [1] "2013-08-05 00:00:00 AAPL 100 @ 16.7660713195801"
## [1] "2014-02-06 00:00:00 AAPL -100 @ 18.3039283752441"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4aaabc898>
## got results for task 10
## numValues: 10, numResults: 10, stopped: FALSE
## returning status FALSE
## evaluation # 11:
## $param.combo
## nFAST nSLOW
## 927 7 76
##
## [1] "2008-04-28 00:00:00 AAPL 100 @ 6.15142917633057"
## [1] "2008-08-05 00:00:00 AAPL -100 @ 5.73714303970337"
## [1] "2008-08-25 00:00:00 AAPL 100 @ 6.16249990463257"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-02 00:00:00 AAPL 100 @ 4.02535676956177"
## [1] "2011-06-15 00:00:00 AAPL -100 @ 11.6696434020996"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2012-11-09 00:00:00 AAPL -100 @ 19.5378570556641"
## [1] "2013-08-13 00:00:00 AAPL 100 @ 17.4846439361572"
## [1] "2014-04-24 00:00:00 AAPL -100 @ 20.2775001525879"
## [1] "2014-04-25 00:00:00 AAPL 100 @ 20.4264297485352"
## result of evaluating expression:
## <environment: 0x7fa4b4e404a0>
## got results for task 11
## numValues: 11, numResults: 11, stopped: FALSE
## returning status FALSE
## evaluation # 12:
## $param.combo
## nFAST nSLOW
## 488 8 54
##
## [1] "2008-04-22 00:00:00 AAPL 100 @ 5.72142887115479"
## [1] "2008-07-30 00:00:00 AAPL -100 @ 5.71000003814697"
## [1] "2008-08-29 00:00:00 AAPL 100 @ 6.05464315414429"
## [1] "2008-09-09 00:00:00 AAPL -100 @ 5.41714286804199"
## [1] "2009-03-26 00:00:00 AAPL 100 @ 3.92392897605896"
## [1] "2010-08-30 00:00:00 AAPL -100 @ 8.6607141494751"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-05-31 00:00:00 AAPL -100 @ 12.4224996566772"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-12-02 00:00:00 AAPL -100 @ 13.917857170105"
## [1] "2011-12-29 00:00:00 AAPL 100 @ 14.4685707092285"
## [1] "2012-11-05 00:00:00 AAPL -100 @ 20.8792858123779"
## [1] "2013-08-08 00:00:00 AAPL 100 @ 16.4646434783936"
## [1] "2014-02-12 00:00:00 AAPL -100 @ 19.1399993896484"
## [1] "2014-04-02 00:00:00 AAPL 100 @ 19.3767852783203"
## [1] "2014-04-16 00:00:00 AAPL -100 @ 18.5360717773438"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b4e38698>
## got results for task 12
## numValues: 12, numResults: 12, stopped: FALSE
## returning status FALSE
## evaluation # 13:
## $param.combo
## nFAST nSLOW
## 868 8 73
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-05 00:00:00 AAPL -100 @ 5.73714303970337"
## [1] "2008-08-26 00:00:00 AAPL 100 @ 6.20142889022827"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-01 00:00:00 AAPL 100 @ 3.88178610801697"
## [1] "2011-06-14 00:00:00 AAPL -100 @ 11.872857093811"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2012-11-08 00:00:00 AAPL -100 @ 19.2053565979004"
## [1] "2013-08-13 00:00:00 AAPL 100 @ 17.4846439361572"
## [1] "2014-04-23 00:00:00 AAPL -100 @ 18.7410717010498"
## [1] "2014-04-28 00:00:00 AAPL 100 @ 21.2175006866455"
## result of evaluating expression:
## <environment: 0x7fa4b112baa0>
## got results for task 13
## numValues: 13, numResults: 13, stopped: FALSE
## returning status FALSE
## evaluation # 14:
## $param.combo
## nFAST nSLOW
## 489 9 54
##
## [1] "2008-04-22 00:00:00 AAPL 100 @ 5.72142887115479"
## [1] "2008-07-30 00:00:00 AAPL -100 @ 5.71000003814697"
## [1] "2008-08-29 00:00:00 AAPL 100 @ 6.05464315414429"
## [1] "2008-09-09 00:00:00 AAPL -100 @ 5.41714286804199"
## [1] "2009-03-26 00:00:00 AAPL 100 @ 3.92392897605896"
## [1] "2010-08-30 00:00:00 AAPL -100 @ 8.6607141494751"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-05-31 00:00:00 AAPL -100 @ 12.4224996566772"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-12-02 00:00:00 AAPL -100 @ 13.917857170105"
## [1] "2011-12-29 00:00:00 AAPL 100 @ 14.4685707092285"
## [1] "2012-11-05 00:00:00 AAPL -100 @ 20.8792858123779"
## [1] "2013-08-08 00:00:00 AAPL 100 @ 16.4646434783936"
## [1] "2014-02-12 00:00:00 AAPL -100 @ 19.1399993896484"
## [1] "2014-04-02 00:00:00 AAPL 100 @ 19.3767852783203"
## [1] "2014-04-16 00:00:00 AAPL -100 @ 18.5360717773438"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b31a2ea0>
## got results for task 14
## numValues: 14, numResults: 14, stopped: FALSE
## returning status FALSE
## evaluation # 15:
## $param.combo
## nFAST nSLOW
## 331 11 46
##
## [1] "2008-04-18 00:00:00 AAPL 100 @ 5.75142908096313"
## [1] "2008-07-29 00:00:00 AAPL -100 @ 5.6100001335144"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-03-24 00:00:00 AAPL 100 @ 3.80357098579407"
## [1] "2010-08-26 00:00:00 AAPL -100 @ 8.58142852783203"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-04-19 00:00:00 AAPL -100 @ 12.0664291381836"
## [1] "2011-05-03 00:00:00 AAPL 100 @ 12.4357137680054"
## [1] "2011-05-26 00:00:00 AAPL -100 @ 11.9642858505249"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-30 00:00:00 AAPL -100 @ 13.6499996185303"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-11-01 00:00:00 AAPL -100 @ 21.3050003051758"
## [1] "2013-08-06 00:00:00 AAPL 100 @ 16.6160717010498"
## [1] "2014-02-10 00:00:00 AAPL -100 @ 18.8924999237061"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b319b098>
## got results for task 15
## numValues: 15, numResults: 15, stopped: FALSE
## returning status FALSE
## evaluation # 16:
## $param.combo
## nFAST nSLOW
## 771 11 68
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-04 00:00:00 AAPL -100 @ 5.47249984741211"
## [1] "2008-08-27 00:00:00 AAPL 100 @ 6.23821401596069"
## [1] "2008-09-10 00:00:00 AAPL -100 @ 5.41464281082153"
## [1] "2009-03-31 00:00:00 AAPL 100 @ 3.75428605079651"
## [1] "2010-09-03 00:00:00 AAPL -100 @ 9.24178600311279"
## [1] "2010-09-13 00:00:00 AAPL 100 @ 9.53714275360107"
## [1] "2011-06-13 00:00:00 AAPL -100 @ 11.66428565979"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2012-11-07 00:00:00 AAPL -100 @ 19.9285717010498"
## [1] "2013-08-12 00:00:00 AAPL 100 @ 16.6914291381836"
## [1] "2014-04-21 00:00:00 AAPL -100 @ 18.9703578948975"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4af6404a0>
## got results for task 16
## numValues: 16, numResults: 16, stopped: FALSE
## returning status FALSE
## evaluation # 17:
## $param.combo
## nFAST nSLOW
## 332 12 46
##
## [1] "2008-04-18 00:00:00 AAPL 100 @ 5.75142908096313"
## [1] "2008-07-29 00:00:00 AAPL -100 @ 5.6100001335144"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-03-24 00:00:00 AAPL 100 @ 3.80357098579407"
## [1] "2010-08-26 00:00:00 AAPL -100 @ 8.58142852783203"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-04-19 00:00:00 AAPL -100 @ 12.0664291381836"
## [1] "2011-05-03 00:00:00 AAPL 100 @ 12.4357137680054"
## [1] "2011-05-26 00:00:00 AAPL -100 @ 11.9642858505249"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-30 00:00:00 AAPL -100 @ 13.6499996185303"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-11-01 00:00:00 AAPL -100 @ 21.3050003051758"
## [1] "2013-08-06 00:00:00 AAPL 100 @ 16.6160717010498"
## [1] "2014-02-10 00:00:00 AAPL -100 @ 18.8924999237061"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b08dbe98>
## got results for task 17
## numValues: 17, numResults: 17, stopped: FALSE
## returning status FALSE
## evaluation # 18:
## $param.combo
## nFAST nSLOW
## 892 12 74
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-05 00:00:00 AAPL -100 @ 5.73714303970337"
## [1] "2008-08-26 00:00:00 AAPL 100 @ 6.20142889022827"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-01 00:00:00 AAPL 100 @ 3.88178610801697"
## [1] "2011-06-15 00:00:00 AAPL -100 @ 11.6696434020996"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2012-11-08 00:00:00 AAPL -100 @ 19.2053565979004"
## [1] "2013-08-13 00:00:00 AAPL 100 @ 17.4846439361572"
## [1] "2014-04-24 00:00:00 AAPL -100 @ 20.2775001525879"
## [1] "2014-04-28 00:00:00 AAPL 100 @ 21.2175006866455"
## result of evaluating expression:
## <environment: 0x7fa4ae7698a0>
## got results for task 18
## numValues: 18, numResults: 18, stopped: FALSE
## returning status FALSE
## evaluation # 19:
## $param.combo
## nFAST nSLOW
## 912 12 75
##
## [1] "2008-04-28 00:00:00 AAPL 100 @ 6.15142917633057"
## [1] "2008-08-05 00:00:00 AAPL -100 @ 5.73714303970337"
## [1] "2008-08-25 00:00:00 AAPL 100 @ 6.16249990463257"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-01 00:00:00 AAPL 100 @ 3.88178610801697"
## [1] "2011-06-15 00:00:00 AAPL -100 @ 11.6696434020996"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2012-11-09 00:00:00 AAPL -100 @ 19.5378570556641"
## [1] "2013-08-13 00:00:00 AAPL 100 @ 17.4846439361572"
## [1] "2014-04-24 00:00:00 AAPL -100 @ 20.2775001525879"
## [1] "2014-04-25 00:00:00 AAPL 100 @ 20.4264297485352"
## result of evaluating expression:
## <environment: 0x7fa4aaab6898>
## got results for task 19
## numValues: 19, numResults: 19, stopped: FALSE
## returning status FALSE
## evaluation # 20:
## $param.combo
## nFAST nSLOW
## 153 13 37
##
## [1] "2007-04-04 00:00:00 AAPL 100 @ 3.36678600311279"
## [1] "2008-01-25 00:00:00 AAPL -100 @ 4.64321422576904"
## [1] "2008-04-15 00:00:00 AAPL 100 @ 5.29928588867188"
## [1] "2008-07-24 00:00:00 AAPL -100 @ 5.67964315414429"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-02-20 00:00:00 AAPL 100 @ 3.25714302062988"
## [1] "2009-03-03 00:00:00 AAPL -100 @ 3.15607094764709"
## [1] "2009-03-23 00:00:00 AAPL 100 @ 3.84500002861023"
## [1] "2010-02-17 00:00:00 AAPL -100 @ 7.23392915725708"
## [1] "2010-03-05 00:00:00 AAPL 100 @ 7.81964302062988"
## [1] "2010-08-24 00:00:00 AAPL -100 @ 8.56892871856689"
## [1] "2010-09-20 00:00:00 AAPL 100 @ 10.1153573989868"
## [1] "2011-04-15 00:00:00 AAPL -100 @ 11.6949996948242"
## [1] "2011-05-09 00:00:00 AAPL 100 @ 12.41428565979"
## [1] "2011-05-24 00:00:00 AAPL -100 @ 11.8639287948608"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-28 00:00:00 AAPL -100 @ 13.4328565597534"
## [1] "2012-01-03 00:00:00 AAPL 100 @ 14.686785697937"
## [1] "2012-06-01 00:00:00 AAPL -100 @ 20.0353565216064"
## [1] "2012-06-21 00:00:00 AAPL 100 @ 20.6310710906982"
## [1] "2012-10-26 00:00:00 AAPL -100 @ 21.5714282989502"
## [1] "2013-06-04 00:00:00 AAPL 100 @ 16.0467853546143"
## [1] "2013-06-21 00:00:00 AAPL -100 @ 14.7678565979004"
## [1] "2013-08-05 00:00:00 AAPL 100 @ 16.7660713195801"
## [1] "2014-02-06 00:00:00 AAPL -100 @ 18.3039283752441"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4aaab6908>
## got results for task 20
## numValues: 20, numResults: 20, stopped: FALSE
## returning status FALSE
## evaluation # 21:
## $param.combo
## nFAST nSLOW
## 854 14 72
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-05 00:00:00 AAPL -100 @ 5.73714303970337"
## [1] "2008-08-26 00:00:00 AAPL 100 @ 6.20142889022827"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-01 00:00:00 AAPL 100 @ 3.88178610801697"
## [1] "2011-06-14 00:00:00 AAPL -100 @ 11.872857093811"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2012-11-08 00:00:00 AAPL -100 @ 19.2053565979004"
## [1] "2013-08-12 00:00:00 AAPL 100 @ 16.6914291381836"
## [1] "2014-04-23 00:00:00 AAPL -100 @ 18.7410717010498"
## [1] "2014-04-28 00:00:00 AAPL 100 @ 21.2175006866455"
## result of evaluating expression:
## <environment: 0x7fa4ae77f8a0>
## got results for task 21
## numValues: 21, numResults: 21, stopped: FALSE
## returning status FALSE
## evaluation # 22:
## $param.combo
## nFAST nSLOW
## 235 15 41
##
## [1] "2008-04-16 00:00:00 AAPL 100 @ 5.48928594589233"
## [1] "2008-07-25 00:00:00 AAPL -100 @ 5.78999996185303"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-03-24 00:00:00 AAPL 100 @ 3.80357098579407"
## [1] "2010-02-23 00:00:00 AAPL -100 @ 7.03785705566406"
## [1] "2010-03-04 00:00:00 AAPL 100 @ 7.52535676956177"
## [1] "2010-08-25 00:00:00 AAPL -100 @ 8.67464256286621"
## [1] "2010-09-17 00:00:00 AAPL 100 @ 9.83464336395264"
## [1] "2011-04-18 00:00:00 AAPL -100 @ 11.85178565979"
## [1] "2011-05-05 00:00:00 AAPL 100 @ 12.3839292526245"
## [1] "2011-05-25 00:00:00 AAPL -100 @ 12.0278568267822"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-29 00:00:00 AAPL -100 @ 13.3285713195801"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-10-31 00:00:00 AAPL -100 @ 21.2614288330078"
## [1] "2013-06-06 00:00:00 AAPL 100 @ 15.6592855453491"
## [1] "2013-06-19 00:00:00 AAPL -100 @ 15.1071434020996"
## [1] "2013-08-06 00:00:00 AAPL 100 @ 16.6160717010498"
## [1] "2014-02-07 00:00:00 AAPL -100 @ 18.5599994659424"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b175ca98>
## got results for task 22
## numValues: 22, numResults: 22, stopped: FALSE
## returning status FALSE
## evaluation # 23:
## $param.combo
## nFAST nSLOW
## 855 15 72
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-05 00:00:00 AAPL -100 @ 5.73714303970337"
## [1] "2008-08-26 00:00:00 AAPL 100 @ 6.20142889022827"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-01 00:00:00 AAPL 100 @ 3.88178610801697"
## [1] "2011-06-14 00:00:00 AAPL -100 @ 11.872857093811"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2012-11-08 00:00:00 AAPL -100 @ 19.2053565979004"
## [1] "2013-08-12 00:00:00 AAPL 100 @ 16.6914291381836"
## [1] "2014-04-23 00:00:00 AAPL -100 @ 18.7410717010498"
## [1] "2014-04-28 00:00:00 AAPL 100 @ 21.2175006866455"
## result of evaluating expression:
## <environment: 0x7fa4b4e6e4a0>
## got results for task 23
## numValues: 23, numResults: 23, stopped: FALSE
## returning status FALSE
## evaluation # 24:
## $param.combo
## nFAST nSLOW
## 76 16 33
##
## [1] "2007-04-02 00:00:00 AAPL 100 @ 3.34464311599731"
## [1] "2008-01-25 00:00:00 AAPL -100 @ 4.64321422576904"
## [1] "2008-04-11 00:00:00 AAPL 100 @ 5.25500011444092"
## [1] "2008-07-22 00:00:00 AAPL -100 @ 5.78642892837524"
## [1] "2008-09-02 00:00:00 AAPL 100 @ 5.93535709381104"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-02-18 00:00:00 AAPL 100 @ 3.37035703659058"
## [1] "2009-03-06 00:00:00 AAPL -100 @ 3.0464289188385"
## [1] "2009-03-20 00:00:00 AAPL 100 @ 3.62821388244629"
## [1] "2010-02-16 00:00:00 AAPL -100 @ 7.26428604125977"
## [1] "2010-03-08 00:00:00 AAPL 100 @ 7.82428598403931"
## [1] "2010-08-24 00:00:00 AAPL -100 @ 8.56892871856689"
## [1] "2010-09-20 00:00:00 AAPL 100 @ 10.1153573989868"
## [1] "2011-04-13 00:00:00 AAPL -100 @ 12.0046434402466"
## [1] "2011-05-09 00:00:00 AAPL 100 @ 12.41428565979"
## [1] "2011-05-24 00:00:00 AAPL -100 @ 11.8639287948608"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-25 00:00:00 AAPL -100 @ 12.9846429824829"
## [1] "2011-12-30 00:00:00 AAPL 100 @ 14.4642858505249"
## [1] "2012-05-25 00:00:00 AAPL -100 @ 20.0817852020264"
## [1] "2012-06-26 00:00:00 AAPL 100 @ 20.4296436309814"
## [1] "2012-10-25 00:00:00 AAPL -100 @ 21.7692852020264"
## [1] "2013-05-29 00:00:00 AAPL 100 @ 15.8910713195801"
## [1] "2013-06-21 00:00:00 AAPL -100 @ 14.7678565979004"
## [1] "2013-08-05 00:00:00 AAPL 100 @ 16.7660713195801"
## [1] "2014-02-05 00:00:00 AAPL -100 @ 18.3067855834961"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b4e66698>
## got results for task 24
## numValues: 24, numResults: 24, stopped: FALSE
## returning status FALSE
## evaluation # 25:
## $param.combo
## nFAST nSLOW
## 137 17 36
##
## [1] "2007-04-03 00:00:00 AAPL 100 @ 3.375"
## [1] "2008-01-25 00:00:00 AAPL -100 @ 4.64321422576904"
## [1] "2008-04-14 00:00:00 AAPL 100 @ 5.27785682678223"
## [1] "2008-07-23 00:00:00 AAPL -100 @ 5.93785715103149"
## [1] "2008-09-02 00:00:00 AAPL 100 @ 5.93535709381104"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-02-20 00:00:00 AAPL 100 @ 3.25714302062988"
## [1] "2009-03-04 00:00:00 AAPL -100 @ 3.25607109069824"
## [1] "2009-03-23 00:00:00 AAPL 100 @ 3.84500002861023"
## [1] "2010-02-17 00:00:00 AAPL -100 @ 7.23392915725708"
## [1] "2010-03-05 00:00:00 AAPL 100 @ 7.81964302062988"
## [1] "2010-08-24 00:00:00 AAPL -100 @ 8.56892871856689"
## [1] "2010-09-20 00:00:00 AAPL 100 @ 10.1153573989868"
## [1] "2011-04-14 00:00:00 AAPL -100 @ 11.872142791748"
## [1] "2011-05-09 00:00:00 AAPL 100 @ 12.41428565979"
## [1] "2011-05-24 00:00:00 AAPL -100 @ 11.8639287948608"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-28 00:00:00 AAPL -100 @ 13.4328565597534"
## [1] "2012-01-03 00:00:00 AAPL 100 @ 14.686785697937"
## [1] "2012-05-31 00:00:00 AAPL -100 @ 20.6332149505615"
## [1] "2012-06-22 00:00:00 AAPL 100 @ 20.78928565979"
## [1] "2012-10-26 00:00:00 AAPL -100 @ 21.5714282989502"
## [1] "2013-06-03 00:00:00 AAPL 100 @ 16.0971431732178"
## [1] "2013-06-21 00:00:00 AAPL -100 @ 14.7678565979004"
## [1] "2013-08-05 00:00:00 AAPL 100 @ 16.7660713195801"
## [1] "2014-02-05 00:00:00 AAPL -100 @ 18.3067855834961"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b4e6e5b8>
## got results for task 25
## numValues: 25, numResults: 25, stopped: FALSE
## returning status FALSE
## evaluation # 26:
## $param.combo
## nFAST nSLOW
## 157 17 37
##
## [1] "2007-04-04 00:00:00 AAPL 100 @ 3.36678600311279"
## [1] "2008-01-25 00:00:00 AAPL -100 @ 4.64321422576904"
## [1] "2008-04-15 00:00:00 AAPL 100 @ 5.29928588867188"
## [1] "2008-07-24 00:00:00 AAPL -100 @ 5.67964315414429"
## [1] "2008-09-03 00:00:00 AAPL 100 @ 5.96285676956177"
## [1] "2008-09-08 00:00:00 AAPL -100 @ 5.6399998664856"
## [1] "2009-02-20 00:00:00 AAPL 100 @ 3.25714302062988"
## [1] "2009-03-03 00:00:00 AAPL -100 @ 3.15607094764709"
## [1] "2009-03-23 00:00:00 AAPL 100 @ 3.84500002861023"
## [1] "2010-02-17 00:00:00 AAPL -100 @ 7.23392915725708"
## [1] "2010-03-05 00:00:00 AAPL 100 @ 7.81964302062988"
## [1] "2010-08-24 00:00:00 AAPL -100 @ 8.56892871856689"
## [1] "2010-09-20 00:00:00 AAPL 100 @ 10.1153573989868"
## [1] "2011-04-15 00:00:00 AAPL -100 @ 11.6949996948242"
## [1] "2011-05-09 00:00:00 AAPL 100 @ 12.41428565979"
## [1] "2011-05-24 00:00:00 AAPL -100 @ 11.8639287948608"
## [1] "2011-07-15 00:00:00 AAPL 100 @ 13.0328569412231"
## [1] "2011-11-28 00:00:00 AAPL -100 @ 13.4328565597534"
## [1] "2012-01-03 00:00:00 AAPL 100 @ 14.686785697937"
## [1] "2012-06-01 00:00:00 AAPL -100 @ 20.0353565216064"
## [1] "2012-06-21 00:00:00 AAPL 100 @ 20.6310710906982"
## [1] "2012-10-26 00:00:00 AAPL -100 @ 21.5714282989502"
## [1] "2013-06-04 00:00:00 AAPL 100 @ 16.0467853546143"
## [1] "2013-06-21 00:00:00 AAPL -100 @ 14.7678565979004"
## [1] "2013-08-05 00:00:00 AAPL 100 @ 16.7660713195801"
## [1] "2014-02-06 00:00:00 AAPL -100 @ 18.3039283752441"
## [1] "2014-04-03 00:00:00 AAPL 100 @ 19.2425003051758"
## [1] "2014-04-15 00:00:00 AAPL -100 @ 18.498571395874"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4adf10aa0>
## got results for task 26
## numValues: 26, numResults: 26, stopped: FALSE
## returning status FALSE
## evaluation # 27:
## $param.combo
## nFAST nSLOW
## 637 17 61
##
## [1] "2008-04-23 00:00:00 AAPL 100 @ 5.81750011444092"
## [1] "2008-08-01 00:00:00 AAPL -100 @ 5.59499979019165"
## [1] "2008-08-28 00:00:00 AAPL 100 @ 6.20499992370605"
## [1] "2008-09-10 00:00:00 AAPL -100 @ 5.41464281082153"
## [1] "2009-03-27 00:00:00 AAPL 100 @ 3.81607103347778"
## [1] "2010-09-01 00:00:00 AAPL -100 @ 8.94035720825195"
## [1] "2010-09-15 00:00:00 AAPL 100 @ 9.65071392059326"
## [1] "2011-06-08 00:00:00 AAPL -100 @ 11.8657140731812"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2011-12-06 00:00:00 AAPL -100 @ 13.9624996185303"
## [1] "2011-12-28 00:00:00 AAPL 100 @ 14.3800001144409"
## [1] "2012-11-06 00:00:00 AAPL -100 @ 20.8160705566406"
## [1] "2013-08-09 00:00:00 AAPL 100 @ 16.2303562164307"
## [1] "2014-02-27 00:00:00 AAPL -100 @ 18.8453578948975"
## [1] "2014-03-31 00:00:00 AAPL 100 @ 19.1692867279053"
## [1] "2014-04-17 00:00:00 AAPL -100 @ 18.7478561401367"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4ade2ae98>
## got results for task 27
## numValues: 27, numResults: 27, stopped: FALSE
## returning status FALSE
## evaluation # 28:
## $param.combo
## nFAST nSLOW
## 797 17 69
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-04 00:00:00 AAPL -100 @ 5.47249984741211"
## [1] "2008-08-27 00:00:00 AAPL 100 @ 6.23821401596069"
## [1] "2008-09-10 00:00:00 AAPL -100 @ 5.41464281082153"
## [1] "2009-03-31 00:00:00 AAPL 100 @ 3.75428605079651"
## [1] "2010-09-07 00:00:00 AAPL -100 @ 9.20750045776367"
## [1] "2010-09-13 00:00:00 AAPL 100 @ 9.53714275360107"
## [1] "2011-06-13 00:00:00 AAPL -100 @ 11.66428565979"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2012-11-08 00:00:00 AAPL -100 @ 19.2053565979004"
## [1] "2013-08-12 00:00:00 AAPL 100 @ 16.6914291381836"
## [1] "2014-04-22 00:00:00 AAPL -100 @ 18.9892864227295"
## [1] "2014-04-28 00:00:00 AAPL 100 @ 21.2175006866455"
## result of evaluating expression:
## <environment: 0x7fa4b4c168a0>
## got results for task 28
## numValues: 28, numResults: 28, stopped: FALSE
## returning status FALSE
## evaluation # 29:
## $param.combo
## nFAST nSLOW
## 859 19 72
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-05 00:00:00 AAPL -100 @ 5.73714303970337"
## [1] "2008-08-26 00:00:00 AAPL 100 @ 6.20142889022827"
## [1] "2008-09-11 00:00:00 AAPL -100 @ 5.45178604125977"
## [1] "2009-04-01 00:00:00 AAPL 100 @ 3.88178610801697"
## [1] "2011-06-14 00:00:00 AAPL -100 @ 11.872857093811"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2012-11-08 00:00:00 AAPL -100 @ 19.2053565979004"
## [1] "2013-08-12 00:00:00 AAPL 100 @ 16.6914291381836"
## [1] "2014-04-23 00:00:00 AAPL -100 @ 18.7410717010498"
## [1] "2014-04-28 00:00:00 AAPL 100 @ 21.2175006866455"
## result of evaluating expression:
## <environment: 0x7fa4b4c10a98>
## got results for task 29
## numValues: 29, numResults: 29, stopped: FALSE
## returning status FALSE
## evaluation # 30:
## $param.combo
## nFAST nSLOW
## 780 20 68
##
## [1] "2008-04-25 00:00:00 AAPL 100 @ 6.06178617477417"
## [1] "2008-08-04 00:00:00 AAPL -100 @ 5.47249984741211"
## [1] "2008-08-27 00:00:00 AAPL 100 @ 6.23821401596069"
## [1] "2008-09-10 00:00:00 AAPL -100 @ 5.41464281082153"
## [1] "2009-03-31 00:00:00 AAPL 100 @ 3.75428605079651"
## [1] "2010-09-03 00:00:00 AAPL -100 @ 9.24178600311279"
## [1] "2010-09-13 00:00:00 AAPL 100 @ 9.53714275360107"
## [1] "2011-06-13 00:00:00 AAPL -100 @ 11.66428565979"
## [1] "2011-07-18 00:00:00 AAPL 100 @ 13.3500003814697"
## [1] "2012-11-07 00:00:00 AAPL -100 @ 19.9285717010498"
## [1] "2013-08-12 00:00:00 AAPL 100 @ 16.6914291381836"
## [1] "2014-04-21 00:00:00 AAPL -100 @ 18.9703578948975"
## [1] "2014-04-29 00:00:00 AAPL 100 @ 21.1546421051025"
## result of evaluating expression:
## <environment: 0x7fa4b4c10b08>
## got results for task 30
## numValues: 30, numResults: 30, stopped: FALSE
## first call to combine function
## evaluating call object to combine results:
## fun(result.1, result.2, result.3, result.4, result.5, result.6,
## result.7, result.8, result.9, result.10, result.11, result.12,
## result.13, result.14, result.15, result.16, result.17, result.18,
## result.19, result.20, result.21, result.22, result.23, result.24,
## result.25, result.26, result.27, result.28, result.29, result.30)
## returning status FALSE
## numValues: 30, numResults: 30, stopped: TRUE
# 提取关键统计结果
df <- degrees.of.freedom('macd', 'macd') # 计算策略的自由度(评估过拟合风险)
tstats <- results$tradeStats # 交易统计数据(胜率、盈亏比等)
defSR <- SharpeRatio.deflated('macd', strategy='macd', audit=.audit) # 修正后的夏普比率(考虑过拟合)
hcSR <- SharpeRatio.haircut('macd', strategy='macd', audit=.audit) # 调整后的夏普比率(降低过拟合影响)
# 打印结果
print(tstats) # 输出交易统计
## nFAST nSLOW Portfolio Symbol Num.Txns Num.Trades Net.Trading.PL
## 441 1 52 macd.train.441 AAPL 17 8 1648.500
## 243 3 42 macd.train.243 AAPL 23 11 1518.071
## 343 3 47 macd.train.343 AAPL 19 9 1571.500
## 184 4 39 macd.train.184 AAPL 25 12 1386.500
## 604 4 60 macd.train.604 AAPL 17 8 1618.428
## 525 5 56 macd.train.525 AAPL 17 8 1722.286
## 765 5 68 macd.train.765 AAPL 13 6 1651.179
## 985 5 79 macd.train.985 AAPL 9 4 1789.786
## 626 6 61 macd.train.626 AAPL 17 8 1702.107
## 167 7 38 macd.train.167 AAPL 27 13 1352.178
## 927 7 76 macd.train.927 AAPL 11 5 1799.786
## 488 8 54 macd.train.488 AAPL 17 8 1694.143
## 868 8 73 macd.train.868 AAPL 11 5 1573.536
## 489 9 54 macd.train.489 AAPL 17 8 1694.143
## 331 11 46 macd.train.331 AAPL 19 9 1651.679
## 771 11 68 macd.train.771 AAPL 13 6 1651.179
## 332 12 46 macd.train.332 AAPL 19 9 1651.679
## 892 12 74 macd.train.892 AAPL 11 5 1706.857
## 912 12 75 macd.train.912 AAPL 11 5 1814.143
## 153 13 37 macd.train.153 AAPL 29 14 1405.679
## 854 14 72 macd.train.854 AAPL 11 5 1621.143
## 235 15 41 macd.train.235 AAPL 23 11 1521.571
## 855 15 72 macd.train.855 AAPL 11 5 1621.143
## 76 16 33 macd.train.76 AAPL 29 14 1496.536
## 137 17 36 macd.train.137 AAPL 29 14 1502.500
## 157 17 37 macd.train.157 AAPL 29 14 1405.679
## 637 17 61 macd.train.637 AAPL 17 8 1702.107
## 797 17 69 macd.train.797 AAPL 13 6 1571.036
## 859 19 72 macd.train.859 AAPL 11 5 1621.143
## 780 20 68 macd.train.780 AAPL 13 6 1651.179
## Avg.Trade.PL Med.Trade.PL Largest.Winner Largest.Loser Gross.Profits
## 441 187.90627 136.01780 641.0715 -84.07135 1640.286
## 243 124.80194 30.07140 679.7143 -74.39289 1582.286
## 343 158.47222 29.99992 613.5715 -74.39289 1594.214
## 184 103.43749 39.01784 594.5001 -100.96426 1484.178
## 604 184.14727 129.67854 643.6070 -79.03571 1616.607
## 525 197.12948 155.64284 641.0715 -80.85709 1726.107
## 765 250.98809 220.30358 657.8571 -82.35712 1647.214
## 985 327.35715 310.87499 758.7500 -71.07139 1409.250
## 626 194.60712 141.37497 643.6070 -79.03571 1700.286
## 167 92.84063 39.99996 563.6785 -127.89288 1476.785
## 927 316.34286 279.28562 764.4287 -71.07139 1694.214
## 488 193.61158 157.78565 641.0715 -84.07135 1697.857
## 868 286.91425 125.64278 799.1071 -74.96428 1542.000
## 489 193.61158 157.78565 641.0715 -84.07135 1697.857
## 331 167.38096 61.71427 684.0714 -74.39289 1674.393
## 771 250.98809 220.30358 657.8571 -82.35712 1647.214
## 332 167.38096 61.71427 684.0714 -74.39289 1674.393
## 892 313.57854 279.28562 778.7857 -74.96428 1675.321
## 912 319.21427 279.28562 778.7857 -71.07139 1708.571
## 153 90.03060 57.46427 534.8571 -127.89288 1560.143
## 854 296.43568 204.96426 799.1071 -74.96428 1589.607
## 235 125.12012 30.07140 679.7143 -74.39289 1573.821
## 855 296.43568 204.96426 799.1071 -74.96428 1589.607
## 76 96.52040 63.80358 561.7499 -112.32147 1659.786
## 137 96.94642 70.46430 594.6429 -132.92866 1649.250
## 157 90.03060 57.46427 534.8571 -127.89288 1560.143
## 637 194.60712 141.37497 643.6070 -79.03571 1700.286
## 797 238.67855 221.25001 585.5356 -82.35712 1573.357
## 859 296.43568 204.96426 799.1071 -74.96428 1589.607
## 780 250.98809 220.30358 657.8571 -82.35712 1647.214
## Gross.Losses Std.Dev.Trade.PL Std.Err.Trade.PL Percent.Positive
## 441 -137.03566 261.4606 92.44028 62.50000
## 243 -209.46436 225.5217 67.99736 63.63636
## 343 -167.96427 250.7102 83.57008 55.55556
## 184 -242.92860 196.9424 56.85237 66.66667
## 604 -143.42880 266.6014 94.25784 62.50000
## 525 -149.07141 265.6197 93.91073 62.50000
## 765 -141.28575 304.4241 124.28063 66.66667
## 985 -99.82142 438.2080 219.10400 50.00000
## 626 -143.42880 268.2088 94.82611 62.50000
## 167 -269.85722 185.6172 51.48094 69.23077
## 927 -112.50000 384.6769 172.03275 60.00000
## 488 -148.96426 264.1330 93.38512 62.50000
## 868 -107.42860 396.9982 177.54301 60.00000
## 489 -148.96426 264.1330 93.38512 62.50000
## 331 -167.96427 264.2260 88.07535 55.55556
## 771 -141.28575 304.4241 124.28063 66.66667
## 332 -167.96427 264.2260 88.07535 55.55556
## 892 -107.42860 380.9597 170.37037 60.00000
## 912 -112.50000 388.8884 173.91616 60.00000
## 153 -299.71435 174.5118 46.64025 64.28571
## 854 -107.42860 384.2972 171.86295 60.00000
## 235 -197.50004 223.3315 67.33699 63.63636
## 855 -107.42860 384.2972 171.86295 60.00000
## 76 -308.49998 184.6163 49.34077 57.14286
## 137 -292.00015 186.5365 49.85397 64.28571
## 157 -299.71435 174.5118 46.64025 64.28571
## 637 -143.42880 268.2088 94.82611 62.50000
## 797 -141.28575 285.2111 116.43694 66.66667
## 859 -107.42860 384.2972 171.86295 60.00000
## 780 -141.28575 304.4241 124.28063 66.66667
## Percent.Negative Profit.Factor Avg.Win.Trade Med.Win.Trade Avg.Losing.Trade
## 441 37.50000 11.969774 328.0572 253.50018 -45.67855
## 243 36.36364 7.553962 226.0408 194.39278 -52.36609
## 343 44.44444 9.491389 318.8428 239.42852 -41.99107
## 184 33.33333 6.109525 185.5223 136.44640 -60.73215
## 604 37.50000 11.271146 323.3214 201.21422 -47.80960
## 525 37.50000 11.579063 345.2214 297.92862 -49.69047
## 765 33.33333 11.658743 411.8036 388.32144 -70.64288
## 985 50.00000 14.117711 704.6250 704.62501 -49.91071
## 626 37.50000 11.854563 340.0572 261.50017 -47.80960
## 167 30.76923 5.472470 164.0873 94.03572 -67.46430
## 927 40.00000 15.059683 564.7381 650.50001 -56.25000
## 488 37.50000 11.397747 339.5714 267.53559 -49.65475
## 868 40.00000 14.353718 513.9999 617.24997 -53.71430
## 489 37.50000 11.397747 339.5714 267.53559 -49.65475
## 331 44.44444 9.968744 334.8786 227.64282 -41.99107
## 771 33.33333 11.658743 411.8036 388.32144 -70.64288
## 332 44.44444 9.968744 334.8786 227.64282 -41.99107
## 892 40.00000 15.594742 558.4404 617.24997 -53.71430
## 912 40.00000 15.187301 569.5238 650.50001 -56.25000
## 153 35.71429 5.205432 173.3492 127.64282 -59.94287
## 854 40.00000 14.796870 529.8690 585.53562 -53.71430
## 235 36.36364 7.968714 224.8316 194.39278 -49.37501
## 855 40.00000 14.796870 529.8690 585.53562 -53.71430
## 76 42.85714 5.380181 207.4732 144.01779 -51.41666
## 137 35.71429 5.648114 183.2500 126.82142 -58.40003
## 157 35.71429 5.205432 173.3492 127.64282 -59.94287
## 637 37.50000 11.854563 340.0572 261.50017 -47.80960
## 797 33.33333 11.135992 393.3393 387.55358 -70.64288
## 859 40.00000 14.796870 529.8690 585.53562 -53.71430
## 780 33.33333 11.658743 411.8036 388.32144 -70.64288
## Med.Losing.Trade Avg.Daily.PL Med.Daily.PL Std.Dev.Daily.PL
## 441 -51.82142 187.90627 136.01780 261.4606
## 243 -51.39289 124.80194 30.07140 225.5217
## 343 -39.71424 158.47222 29.99992 250.7102
## 184 -54.83932 103.43749 39.01784 196.9424
## 604 -42.14306 184.14727 129.67854 266.6014
## 525 -63.75003 197.12948 155.64284 265.6197
## 765 -70.64288 250.98809 220.30358 304.4241
## 985 -49.91071 327.35715 310.87499 438.2080
## 626 -42.14306 194.60712 141.37497 268.2088
## 167 -54.83932 92.84063 39.99996 185.6172
## 927 -56.25000 316.34286 279.28562 384.6769
## 488 -63.75003 193.61158 157.78565 264.1330
## 868 -53.71430 286.91425 125.64278 396.9982
## 489 -63.75003 193.61158 157.78565 264.1330
## 331 -39.71424 167.38096 61.71427 264.2260
## 771 -70.64288 250.98809 220.30358 304.4241
## 332 -39.71424 167.38096 61.71427 264.2260
## 892 -53.71430 313.57854 279.28562 380.9597
## 912 -56.25000 319.21427 279.28562 388.8884
## 153 -55.03569 90.03060 57.46427 174.5118
## 854 -53.71430 296.43568 204.96426 384.2972
## 235 -45.41073 125.12012 30.07140 223.3315
## 855 -53.71430 296.43568 204.96426 384.2972
## 76 -43.71425 96.52040 63.80358 184.6163
## 137 -55.03569 96.94642 70.46430 186.5365
## 157 -55.03569 90.03060 57.46427 174.5118
## 637 -42.14306 194.60712 141.37497 268.2088
## 797 -70.64288 238.67855 221.25001 285.2111
## 859 -53.71430 296.43568 204.96426 384.2972
## 780 -70.64288 250.98809 220.30358 304.4241
## Std.Err.Daily.PL Ann.Sharpe Max.Drawdown Profit.To.Max.Draw
## 441 92.44028 11.408677 -472.6429 3.487835
## 243 67.99736 8.784827 -502.5715 3.020608
## 343 83.57008 10.034167 -500.5714 3.139412
## 184 56.85237 8.337561 -536.3572 2.585031
## 604 94.25784 10.964859 -464.7860 3.482094
## 525 93.91073 11.781257 -458.4644 3.756640
## 765 124.28063 13.088031 -576.2144 2.865563
## 985 219.10400 11.858829 -726.5001 2.463573
## 626 94.82611 11.518238 -447.5000 3.803591
## 167 51.48094 7.939995 -547.2858 2.470699
## 927 172.03275 13.054558 -694.6074 2.591084
## 488 93.38512 11.636140 -458.4644 3.695255
## 868 177.54301 11.472651 -727.8574 2.161873
## 489 93.38512 11.636140 -458.4644 3.695255
## 331 88.07535 10.056126 -431.0358 3.831883
## 771 124.28063 13.088031 -576.2144 2.865563
## 332 88.07535 10.056126 -431.0358 3.831883
## 892 170.37037 13.066749 -727.8574 2.345043
## 912 173.91616 13.030396 -694.6074 2.611753
## 153 46.64025 8.189654 -547.2858 2.568454
## 854 171.86295 12.245132 -648.5359 2.499696
## 235 67.33699 8.893595 -490.6072 3.101405
## 855 171.86295 12.245132 -648.5359 2.499696
## 76 49.34077 8.299452 -511.9287 2.923328
## 137 49.85397 8.250273 -552.3216 2.720335
## 157 46.64025 8.189654 -547.2858 2.568454
## 637 94.82611 11.518238 -447.5000 3.803591
## 797 116.43694 13.284562 -648.5359 2.422434
## 859 171.86295 12.245132 -648.5359 2.499696
## 780 124.28063 13.088031 -576.2144 2.865563
## Avg.WinLoss.Ratio Med.WinLoss.Ratio Max.Equity Min.Equity End.Equity
## 441 7.181864 4.891803 1753.393 -72.178602 1648.500
## 243 4.316549 3.782484 1701.357 -9.392786 1518.071
## 343 7.593111 6.028782 1719.536 -53.571391 1571.500
## 184 3.054763 2.488112 1629.179 -5.571365 1386.500
## 604 6.762688 4.774552 1740.000 -109.714246 1618.428
## 525 6.947438 4.673388 1779.536 -87.428617 1722.286
## 765 5.829372 5.496965 1792.679 -141.285753 1651.179
## 985 14.117711 14.117711 1863.143 -103.535748 1789.786
## 626 7.112738 6.205059 1763.393 -109.714246 1702.107
## 167 2.432209 1.714750 1605.786 -2.035666 1352.178
## 927 10.039788 11.564445 1856.143 -116.214323 1799.786
## 488 6.838648 4.196635 1785.000 -84.107208 1694.143
## 868 9.569146 11.491353 1895.893 -111.142921 1573.536
## 489 6.838648 4.196635 1785.000 -84.107208 1694.143
## 331 7.974996 5.732020 1730.179 -53.607082 1651.679
## 771 5.829372 5.496965 1792.679 -141.285753 1651.179
## 332 7.974996 5.732020 1730.179 -53.607082 1651.679
## 892 10.396495 11.491353 1875.572 -111.142921 1706.857
## 912 10.124867 11.564445 1870.500 -116.214323 1814.143
## 153 2.891907 2.319274 1659.286 -14.392900 1405.679
## 854 9.864580 10.900926 1864.179 -111.142921 1621.143
## 235 4.553551 4.280768 1692.893 -9.392786 1521.571
## 855 9.864580 10.900926 1864.179 -111.142921 1621.143
## 76 4.035135 3.294527 1714.500 -12.178612 1496.536
## 137 3.137841 2.304349 1760.857 -15.214300 1502.500
## 157 2.891907 2.319274 1659.286 -14.392900 1405.679
## 637 7.112738 6.205059 1763.393 -109.714246 1702.107
## 797 5.567996 5.486096 1789.250 -141.285753 1571.036
## 859 9.864580 10.900926 1864.179 -111.142921 1621.143
## 780 5.829372 5.496965 1792.679 -141.285753 1651.179
print(df) # 输出自由度
##
## Degrees of freedom report for strategy: macd
## Total market observations: 1865
## Degrees of freedom consumed by strategy: 257
## Total degrees of freedom remaining: 1608
## % Degrees of Freedom: 86.22 %
print(defSR) # 输出修正夏普比率
## obs.Sharpe max.Sharpe deflated.Sharpe p.value nTrials
## 1 1.1 2.169138 1.095209 0.00435539 38
print(hcSR) # 输出调整夏普比率
##
## Sharpe Ratio Haircut Report:
##
## Frequency = Daily
## Number of Observations = 1866
## Observed Sharpe Ratio: 1.1
## Autocorrelation: NaN
## Sharpe Ratio corrected for autocorrelation: 1.1
## Assumed number of tests: 38
## Assumed Average Correlation: 0.2
##
## Bonferroni Adjustment:
## Adjusted P-value = 0.5742251
## Haircut Sharpe Ratio = 0.2485153
## Percentage Haircut = 0.774077
##
## Holm Adjustment:
## Adjusted P-value = 0.483558
## Haircut Sharpe Ratio = 0.3101128
## Percentage Haircut = 0.7180793
##
## BHY Adjustment:
## Adjusted P-value = 0.3133459
## Haircut Sharpe Ratio = 0.4472566
## Percentage Haircut = 0.5934031
##
## Average Adjustment:
## Adjusted P-value = 0.457043
## Haircut Sharpe Ratio = 0.3292902
## Percentage Haircut = 0.7006452
策略核心思路解析
参数优化的必要性与逻辑
MACD 策略的表现高度依赖于快速 EMA(短期趋势)和慢速 EMA(长期趋势)的周期参数。例如,快速 EMA 过短可能导致信号频繁且噪音大,过长则可能滞后于趋势;慢速 EMA 同理。若仅凭经验选择参数(如默认的 12/26 日),可能错过更优组合,或因参数适配特定历史数据而在未来失效。
这段代码的核心是通过系统测试参数组合解决这一问题:首先定义合理的参数范围(快速 EMA 1-20 日、慢速 EMA 30-80 日),再通过add.distribution将参数引入策略,最后用apply.paramset批量测试不同组合的表现。这种方法避免了主观选择参数的盲目性,让数据决定最优解。
MACD 指标与参数约束的意义
MACD(移动平均收敛散度)的核心是通过短期与长期趋势的差异捕捉价格动量,其计算逻辑为: - MACD 线 = 快速 EMA - 慢速 EMA(反映短期与长期趋势的偏离) - 信号线 = MACD 线的 9 日 EMA(平滑波动,生成交易信号)
因此,快速 EMA 必须小于慢速 EMA—— 若快速周期大于慢速周期,MACD 线的物理意义将反转(变成长期减短期),无法正确反映趋势偏离。代码中add.distribution.constraint通过operator = ’<’强制这一约束,确保参数逻辑的合理性。
效率与有效性的平衡:随机抽样与统计验证
全量测试 1-20 日(20 种)与 30-80 日(51 种)的参数组合,会产生 20×51=1020 种可能,计算成本极高。代码通过nsamples = 30随机抽样 30 组参数,在效率与覆盖度间取得平衡 —— 既避免全量测试的冗余,又能覆盖大概率有效的组合。
更重要的是,代码引入了过拟合风险评估: degrees.of.freedom计算策略的自由度(参数数量与数据量的比值),自由度越高,过拟合风险越大; SharpeRatio.deflated和SharpeRatio.haircut对传统夏普比率进行修正,降低因过度优化导致的 “虚高收益” 影响,更真实反映策略的稳健性。
这些指标让交易者不仅关注 “哪个参数组合收益最高”,更能判断 “该组合的收益是否可靠”。
结果解读的核心价值
代码输出的tstats(交易统计)包含胜率、平均盈亏、最大回撤等指标,直观展示不同参数组合的表现;而修正后的夏普比率(defSR、hcSR)则提示哪些组合的收益是 “可复制的”,哪些可能是 “数据巧合”。 例如,若某参数组合的传统夏普比率极高,但修正后大幅下降,说明其可能过度拟合历史数据,实盘表现大概率不佳;反之,修正前后差异小的组合,更可能在未来保持稳健。
科学参数优化的意义
这段代码展示了量化交易中 “参数优化” 的标准化流程:从定义合理参数范围、施加逻辑约束,到高效抽样测试、统计验证有效性,每一步都围绕 “降低主观干扰、提升策略稳健性” 展开。
对交易者而言,这种方法的价值在于:它不仅能找到历史表现优异的参数,更能通过统计指标识别参数的可靠性,避免 “回测神话” 与实盘失效的鸿沟。在量化交易中,“能解释的收益” 比 “高收益” 更重要 —— 而科学的参数优化,正是通往可解释、可复制收益的关键一步。