Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
def test_optimizer():
    optimizer = Optimizer()
    run_id = 0

    optimizer.outfile = 'optimizer_out.xls'

    ## parameter space to search over
    optimizer.add_parameter(
        dict(name='length', min_val=100, max_val=200, steps=32, converter=int))

    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_strategy(strategy_params, run_id)
            optimizer.score(sim_stats, run_id)
            run_id += 1
        optimizer.dump()

    optimizer.write()