def test_optimizer2(): optimizer = Optimizer() run_id = 0 ## set population size optimizer.size = 40 optimizer.max_generations = 5 ## if not given: outfile will default to using the strategy name ## optimizer.outfile ='retrace_optimized.xls' ## parameter space to search over ## momentum = entry momentum crossover ## average = moving average filter ## duration = trade holding period param_list = [ dict(name='momentum', min_val=10, max_val=100, steps=32, converter=int), dict(name='average', min_val=20, max_val=200, steps=32, converter=int), dict(name='duration', min_val=10, max_val=50, steps=16, converter=int) ] optimizer.add_parameters(param_list) while not optimizer.converged(): params_set = optimizer.generate_set() for strategy_params in params_set: log.debug('Testing: %s' % pprint.pformat(strategy_params)) sim_stats = test_retrace_strategy(strategy_params, run_id) optimizer.score(sim_stats, run_id) run_id += 1 optimizer.dump() optimizer.write()
def test_optimizer3(): optimizer = Optimizer() run_id = 0 ## set population size optimizer.size = 40 optimizer.max_generations = 5 optimizer.outfile = 'triple_optimized.xls' ## parameter space to search over ## mo1 = short term momentum crossover ## mo2 = medium term mo filter ## mo3 = long term mo filter ## duration = trade holding period param_list = [ dict(name='mo1', min_val=5, max_val=50, steps=32, converter=int), dict(name='mo2', min_val=60, max_val=100, steps=32, converter=int), dict(name='mo3', min_val=110, max_val=200, steps=32, converter=int), dict(name='duration', min_val=10, max_val=50, steps=16, converter=int) ] optimizer.add_parameters(param_list) while not optimizer.converged(): params_set = optimizer.generate_set() for strategy_params in params_set: log.debug('Testing: %s' % pprint.pformat(strategy_params)) sim_stats = test_triple_strategy(strategy_params, run_id) optimizer.score(sim_stats, run_id) run_id += 1 optimizer.dump() optimizer.write()
def optimize(): optimizer = Optimizer() optimizer.strategy_class = RSIStrategy #optimizer.data_feed = DataFeedList(['20081210.SPY.1m.csv','20081211.SPY.1min.csv','20081212.SPY.1min.csv'],data_type='B') #optimizer.data_feed = DataFeedList(['20081210.SPY.30s.csv','20081211.SPY.30s.csv','20081212.SPY.30s.csv'],data_type='I') optimizer.data_feed = DataFeedList(['SPY.csv'], data_type='D') ## set population size optimizer.size = 40 optimizer.max_generations = 50 optimizer.outfile = '%s_%s.xls' % (__file__[:-3], datetime.now().strftime("%Y%m%d")) optimizer.tolerance = 0.01 #optimizer.reset_on_EOD = False ## parameter space to search over ## rsi = rsi length ## top/btm = rsi buy sell thresholds ## average(optional) trend filter ## duration = trade duration optimizer.add_parameter( dict(name='rsi', min_val=10, max_val=40, steps=16, converter=int)) optimizer.add_parameter( dict(name='top', min_val=60, max_val=80, steps=4, converter=int)) optimizer.add_parameter( dict(name='btm', min_val=20, max_val=40, steps=4, converter=int)) optimizer.add_parameter( dict(name='average', min_val=20, max_val=200, steps=64, converter=int)) optimizer.add_parameter( dict(name='duration', min_val=5, max_val=20, steps=8, converter=int)) optimizer.run()
from RetraceStrategy import RetraceStrategy from DataFeed import DataFeedDaily from Optimizer import Optimizer if __name__ == '__main__': optimizer = Optimizer() optimizer.strategy_class = RetraceStrategy # optimizer.data_feed = DataFeedDaily('daily.SPY.csv') optimizer.data_feed = DataFeedDaily('SPY.csv') ## set population size optimizer.size = 40 optimizer.max_generations = 50 optimizer.outfile = 'optimize_retrace3.xls' optimizer.reset_on_EOD = True ## parameter space to search over ## strategy_params for RetraceStrategy = dict(average,momentum,duration) ## momentum = entry momentum crossover ## average = moving average filter ## duration = trade holding period param_list = [ dict(name='momentum', min_val=30, max_val=50, steps=16, converter=int), dict(name='average', min_val=70, max_val=120, steps=32, converter=int), dict(name='duration', min_val=10, max_val=20, steps=8, converter=int) ] for p in param_list: optimizer.add_parameter(p)