def gekko_generations(TargetParameters, GenerationMethod,
                      EvaluationMode, NB_LOCALE=2, web=None):

    Logger = promoterz.logger.Logger()
    GenerationMethod = promoterz.functions.selectRepresentationMethod(GenerationMethod)

    genconf=getSettings('generations')
    globalconf = getSettings('Global')
    datasetconf = getSettings('dataset')
    indicatorconf = getSettings()['indicators']
    if EvaluationMode == 'indicator':
        #global StrategyFileManager
        StrategyFileManager = stratego.gekko_strategy.StrategyFileManager(
            globalconf.gekkoPath, indicatorconf)
        Evaluate = partial(aEvaluate, StrategyFileManager)
        Strategy = None

    # --for standard methods;
    else:
        Evaluate = bEvaluate
        Strategy = EvaluationMode

    Logger.log("Evolving %s strategy;\n" % Strategy)

    print("evaluated parameters ranges:")

    TargetParameters = promoterz.parameterOperations.flattenParameters(TargetParameters)
    TargetParameters = promoterz.parameterOperations.parameterValuesToRangeOfValues(
        TargetParameters,
        genconf.parameter_spread)

    GlobalTools = GenerationMethod.getToolbox(Strategy, genconf, TargetParameters)

    RemoteHosts = promoterz.evaluation.gekko.loadHostsFile(globalconf.RemoteAWS)
    globalconf.GekkoURLs += RemoteHosts

    if RemoteHosts:
        print("Connected Remote Hosts:\n%s" % ('\n').join(RemoteHosts))
        if EvaluationMode == 'indicator':
            exit('Indicator mode is yet not compatible with multiple hosts.')

    for k in TargetParameters.keys():
        Logger.log( "%s%s%s" % (k, " " * (30-len(k)), TargetParameters[k]) )

    # --GRAB PRIMARY (EVOLUTION) DATASET
    D = promoterz.evaluation.gekko.selectCandlestickData(
            exchange_source=datasetconf.dataset_source)
    evolutionDataset = CandlestickDataset(*D)
    evolutionDataset.restrain(datasetconf.dataset_span)
    # --GRAB SECONDARY (EVALUATION) DATASET
    try:
        D = promoterz.evaluation.gekko.selectCandlestickData(
        exchange_source = datasetconf.eval_dataset_source,
        avoidCurrency = evolutionDataset.specifications['asset'] )
        evaluationDataset = CandlestickDataset(*D)
        evaluationDataset.restrain(datasetconf.eval_dataset_span)
    except RuntimeError:
        evaluationDataset = None
        print("Evaluation dataset not found.")



    # --SHOW DATASET INFO;
    interface.showDatasetInfo("evolution",
                              evolutionDataset)

    if evaluationDataset:
        interface.showDatasetInfo("evaluation",
                                  evaluationDataset)

    # --INITIALIZE WORLD WITH CANDLESTICK DATASET INFO;
    GlobalTools.register('Evaluate', Evaluate,
                         GlobalTools.constructPhenotype, genconf )


    loops = [ promoterz.sequence.standard_loop.standard_loop ]
    World = promoterz.world.World(GlobalTools, loops,
                                  genconf, globalconf, TargetParameters, NB_LOCALE,
                                  EnvironmentParameters=[ evolutionDataset,
                                                          evaluationDataset ], web=web)
    World.logger = Logger
    # --RUN EPOCHES;
    while World.EPOCH < World.genconf.NBEPOCH:
        World.runEPOCH()
        if genconf.evaluateSettingsPeriodically:
            if not World.EPOCH % genconf.evaluateSettingsPeriodically:
                resultInterface.showResults(World)

    # RUN ENDS. SELECT INDIVIDUE, LOG AND PRINT STUFF;
    # FinalBestScores.append(Stats['max'])
    print(World.EnvironmentParameters)
    # After running EPOCHs, select best candidates;
    resultInterface.showResults(World)



    print("")
    print("\t\t.RUN ENDS.")
Exemplo n.º 2
0
def gekko_generations(TargetParameters,
                      GenerationMethod,
                      EvaluationMode,
                      NB_LOCALE=2,
                      web=None):

    # --LOAD SETTINGS;
    genconf = getSettings('generations')
    globalconf = getSettings('Global')
    datasetconf = getSettings('dataset')
    indicatorconf = getSettings()['indicators']

    # --APPLY COMMAND LINE GENCONF SETTINGS;
    for parameter in genconf.__dict__.keys():
        if parameter in options.__dict__.keys():
            if options.__dict__[parameter] != None:
                genconf.__dict__[parameter] = options.__dict__[parameter]

    GenerationMethod = promoterz.functions.selectRepresentationMethod(
        GenerationMethod)
    if EvaluationMode == 'indicator':
        #global StrategyFileManager
        StrategyFileManager = stratego.gekko_strategy.StrategyFileManager(
            globalconf.gekkoPath, indicatorconf)
        Evaluate = partial(aEvaluate, StrategyFileManager)
        Strategy = options.skeleton

    # --for standard methods;
    else:
        Evaluate = bEvaluate
        Strategy = EvaluationMode

    TargetParameters = promoterz.parameterOperations.flattenParameters(
        TargetParameters)
    TargetParameters = promoterz.parameterOperations.parameterValuesToRangeOfValues(
        TargetParameters, genconf.parameter_spread)

    GlobalTools = GenerationMethod.getToolbox(Strategy, genconf,
                                              TargetParameters)

    RemoteHosts = evaluation.gekko.API.loadHostsFile(globalconf.RemoteAWS)
    globalconf.GekkoURLs += RemoteHosts

    if RemoteHosts:
        print("Connected Remote Hosts:\n%s" % ('\n').join(RemoteHosts))
        if EvaluationMode == 'indicator':
            exit('Indicator mode is yet not compatible with multiple hosts.')

    # --GRAB PRIMARY (EVOLUTION) DATASET
    D = evaluation.gekko.dataset.selectCandlestickData(
        exchange_source=datasetconf.dataset_source)
    evolutionDataset = CandlestickDataset(*D)
    evolutionDataset.restrain(datasetconf.dataset_span)

    # --GRAB SECONDARY (EVALUATION) DATASET
    try:
        D = evaluation.gekko.dataset.selectCandlestickData(
            exchange_source=datasetconf.eval_dataset_source,
            avoidCurrency=evolutionDataset.specifications['asset'])
        evaluationDataset = CandlestickDataset(*D)
        evaluationDataset.restrain(datasetconf.eval_dataset_span)
    except RuntimeError:
        evaluationDataset = None
        print("Evaluation dataset not found.")

    # --INITIALIZE LOGGER;
    ds_specs = evolutionDataset.specifications

    logfilename = "%s-%s-%s-%s-%s" % (Strategy, ds_specs['exchange'],
                                      ds_specs['currency'], ds_specs['asset'],
                                      str(datetime.datetime.now())[-6:])

    Logger = promoterz.logger.Logger(logfilename)

    # --PRINT RUNTIME ARGS TO LOG HEADER;
    ARGS = '$python ' + ' '.join(sys.argv)
    Logger.log(ARGS, target='Header')

    # --SHOW PARAMETER INFO;
    if Strategy:
        Logger.log("Evolving %s strategy;\n" % Strategy)

    Logger.log("evaluated parameters ranges:", target="Header")

    for k in TargetParameters.keys():
        Logger.log("%s%s%s\n" % (k, " " * (30 - len(k)), TargetParameters[k]),
                   target="Header")

    # --LOG CONFIG INFO;
    configInfo = json.dumps(genconf.__dict__, indent=4)
    Logger.log(configInfo, target="Header", show=False)

    # --SHOW DATASET INFO;
    Logger.log(interface.parseDatasetInfo("evolution", evolutionDataset),
               target="Header")

    if evaluationDataset:
        Logger.log(interface.parseDatasetInfo("evaluation", evaluationDataset),
                   target="Header")

    # --INITIALIZE WORLD WITH CANDLESTICK DATASET INFO; HERE THE GA KICKS IN;
    GlobalTools.register('Evaluate', Evaluate, GlobalTools.constructPhenotype,
                         genconf)

    # --THIS LOADS A DATERANGE FOR A LOCALE;
    def onInitLocale(World, locale):
        locale.DateRange = getLocaleDateRange(World, locale)

    loops = [promoterz.sequence.standard_loop.standard_loop]
    World = promoterz.world.World(
        GlobalTools,
        loops,
        genconf,
        globalconf,
        TargetParameters,
        NB_LOCALE,
        EnvironmentParameters=[evolutionDataset, evaluationDataset],
        onInitLocale=onInitLocale,
        web=web)
    World.logger = Logger
    World.EvaluationStatistics = []
    World.logger.updateFile()

    # --RUN EPOCHES;
    while World.EPOCH < World.genconf.NBEPOCH:
        World.runEPOCH()
        if genconf.evaluateSettingsPeriodically:
            if not World.EPOCH % genconf.evaluateSettingsPeriodically:
                resultInterface.showResults(World)

    # RUN ENDS. SELECT INDIVIDUE, LOG AND PRINT STUFF;
    # FinalBestScores.append(Stats['max'])
    print(World.EnvironmentParameters)
    # After running EPOCHs, select best candidates;
    resultInterface.showResults(World)

    print("")
    print("\t\t.RUN ENDS.")
def gekko_generations(TargetParameters,
                      GenerationMethod,
                      EvaluationMode,
                      NB_LOCALE=2,
                      web=None):

    GenerationMethod = promoterz.functions.selectRepresentationMethod(
        GenerationMethod)

    genconf = getSettings('generations')
    globalconf = getSettings('Global')

    if EvaluationMode == 'indicator':
        #global StrategyFileManager
        StrategyFileManager = stratego.gekko_strategy.StrategyFileManager(
            globalconf.gekkoPath)
        Evaluate = partial(aEvaluate, StrategyFileManager)
        Strategy = None
    else:
        Evaluate = bEvaluate
        Strategy = EvaluationMode

    print("Evolving %s strategy;\n" % Strategy)

    print("evaluated parameters ranges:")

    TargetParameters = promoterz.utils.flattenParameters(TargetParameters)

    GlobalTools = GenerationMethod.getToolbox(Strategy, genconf,
                                              TargetParameters)

    RemoteHosts = promoterz.evaluation.gekko.loadHostsFile(
        globalconf.RemoteAWS)
    globalconf.GekkoURLs += RemoteHosts
    if RemoteHosts:
        print("Connected Remote Hosts:\n%s" % ('\n').join(RemoteHosts))
        if EvaluationMode == 'indicator':
            exit('Indicator mode is yet not compatible with multiple hosts.')

    for k in TargetParameters.keys():
        print("%s%s%s" % (k, " " * (30 - len(k)), TargetParameters[k]))

    datasetSpecifications, availableDataRange = promoterz.evaluation.gekko.getAvailableDataset(
        exchange_source=genconf.dataset_source)

    GlobalTools.register('Evaluate', Evaluate, GlobalTools.constructPhenotype,
                         genconf, datasetSpecifications)




    showdatadaterange = [ promoterz.evaluation.gekko.epochToString(availableDataRange[x])\
                    for x in ['from', 'to'] ]

    print()
    print("using candlestick dataset %s to %s" %
          (showdatadaterange[0], showdatadaterange[1]))

    print()

    loops = [promoterz.sequence.standard_loop.standard_loop]
    World = promoterz.world.World(GlobalTools,
                                  loops,
                                  genconf,
                                  globalconf,
                                  TargetParameters,
                                  NB_LOCALE,
                                  EnvironmentParameters=availableDataRange,
                                  web=web)

    while World.EPOCH < World.genconf.NBEPOCH:
        World.runEPOCH()
        if genconf.evaluateSettingsPeriodically:
            if not World.EPOCH % genconf.evaluateSettingsPeriodically:
                resultInterface.showResults(World)

    # RUN ENDS. SELECT INDIVIDUE, LOG ANDo PRINT STUFF;
    # FinalBestScores.append(Stats['max'])
    print(World.EnvironmentParameters)
    # After running EPOCHs, select best candidates;
    resultInterface.showResults(World)

    print("")
    print("\t\t.RUN ENDS.")
Exemplo n.º 4
0
def gekko_generations(TargetParameters, GenerationMethod,
                      EvaluationMode, NB_LOCALE=2, web=None):

    GenerationMethod = promoterz.functions.selectRepresentationMethod(GenerationMethod)

    genconf=getSettings('generations')
    globalconf = getSettings('Global')

    if EvaluationMode == 'indicator':
        #global StrategyFileManager
        StrategyFileManager = stratego.gekko_strategy.StrategyFileManager(globalconf.gekkoPath)
        Evaluate = partial(aEvaluate, StrategyFileManager)
        Strategy = None
    else:
        Evaluate = bEvaluate
        Strategy = EvaluationMode

    print("Evolving %s strategy;\n" % Strategy)

    print("evaluated parameters ranges:")

    TargetParameters = promoterz.utils.flattenParameters(TargetParameters)

    GlobalTools = GenerationMethod.getToolbox(Strategy, genconf, TargetParameters)


    RemoteHosts = promoterz.evaluation.gekko.loadHostsFile(globalconf.RemoteAWS)
    globalconf.GekkoURLs += RemoteHosts
    if RemoteHosts:
        print("Connected Remote Hosts:\n%s" % ('\n').join(RemoteHosts))
        if EvaluationMode == 'indicator':
            exit('Indicator mode is yet not compatible with multiple hosts.')

    for k in TargetParameters.keys():
        print( "%s%s%s" % (k, " " * (30-len(k)), TargetParameters[k]) )

    datasetSpecifications, availableDataRange = promoterz.evaluation.gekko.getAvailableDataset(
            exchange_source=genconf.dataset_source)




    GlobalTools.register('Evaluate', Evaluate,
                         GlobalTools.constructPhenotype, genconf, datasetSpecifications)




    showdatadaterange = [ promoterz.evaluation.gekko.epochToString(availableDataRange[x])\
                    for x in ['from', 'to'] ]

    print()
    print("using candlestick dataset %s to %s" %     (showdatadaterange[0],
                                                      showdatadaterange[1]))

    print()

    loops = [ promoterz.sequence.standard_loop.standard_loop ]
    World = promoterz.world.World(GlobalTools, loops,
                                  genconf, globalconf,  TargetParameters, NB_LOCALE,
                                  EnvironmentParameters=availableDataRange, web=web)

    while World.EPOCH < World.genconf.NBEPOCH:
        World.runEPOCH()
        if genconf.evaluateSettingsPeriodically:
            if not World.EPOCH % genconf.evaluateSettingsPeriodically:
                resultInterface.showResults(World)

    # RUN ENDS. SELECT INDIVIDUE, LOG ANDo PRINT STUFF;
    # FinalBestScores.append(Stats['max'])
    print(World.EnvironmentParameters)
    # After running EPOCHs, select best candidates;
    resultInterface.showResults(World)




    print("")
    print("\t\t.RUN ENDS.")
Exemplo n.º 5
0
def gekko_generations(TargetParameters,
                      GenerationMethod,
                      EvaluationMode,
                      settings,
                      options,
                      web=None):

    # --LOAD SETTINGS;
    genconf = makeSettings(settings['generations'])
    globalconf = makeSettings(settings['Global'])
    datasetconf = makeSettings(settings['dataset'])
    indicatorconf = makeSettings(settings['indicators'])
    backtestconf = makeSettings(settings['backtest'])
    evalbreakconf = makeSettings(settings['evalbreak'])

    # --APPLY COMMAND LINE GENCONF SETTINGS;
    for parameter in genconf.__dict__.keys():
        if parameter in options.__dict__.keys():
            if options.__dict__[parameter] != None:
                genconf.__dict__[parameter] = options.__dict__[parameter]
    GenerationMethod = promoterz.functions.selectRepresentationMethod(
        GenerationMethod)
    if EvaluationMode == 'indicator':
        # global StrategyFileManager
        StrategyFileManager = stratego.gekko_strategy.StrategyFileManager(
            globalconf.gekkoPath, indicatorconf)
        Evaluate = partial(indicatorEvaluate, StrategyFileManager)
        Strategy = options.skeleton
    # --for standard methods;
    else:
        Strategy = EvaluationMode
        if options.benchmarkMode:
            Evaluate = benchmarkEvaluate
            evolutionDatasets, evaluationDatasets = [], []
            genconf.minimumProfitFilter = None
        else:
            Evaluate = standardEvaluate
            evolutionDatasets, evaluationDatasets = grabDatasets(datasetconf)

    # -- PARSE TARGET PARAMETERS
    TargetParameters = promoterz.parameterOperations.flattenParameters(
        TargetParameters)
    TargetParameters = promoterz.parameterOperations.parameterValuesToRangeOfValues(
        TargetParameters, genconf.parameter_spread)
    GlobalTools = GenerationMethod.getToolbox(Strategy, genconf,
                                              TargetParameters)
    RemoteHosts = evaluation.gekko.API.loadHostsFile(globalconf.RemoteAWS)
    globalconf.GekkoURLs += RemoteHosts
    if RemoteHosts:
        print("Connected Remote Hosts:\n%s" % ('\n').join(RemoteHosts))
        if EvaluationMode == 'indicator':
            exit('Indicator mode is yet not compatible with multiple hosts.')

    # --INITIALIZE LOGGER;
    todayDate = time.strftime("%Y_%m_%d-%H.%M.%S", time.gmtime())
    if evolutionDatasets:
        ds_specs = evolutionDatasets[0].specifications
        logfilename = "%s-%s-%s-%s-%s" % (Strategy, ds_specs['exchange'],
                                          ds_specs['currency'],
                                          ds_specs['asset'], todayDate)
    else:
        logfilename = "benchmark%s" % todayDate
    Logger = promoterz.logger.Logger(logfilename)

    # --PRINT RUNTIME ARGS TO LOG HEADER;
    ARGS = ' '.join(sys.argv)
    Logger.log(ARGS, target='Header')

    # --SHOW PARAMETER INFO;
    if Strategy:
        Logger.log("Evolving %s strategy;\n" % Strategy)
    Logger.log("evaluated parameters ranges:", target="Header")
    for k in TargetParameters.keys():
        Logger.log("%s%s%s\n" % (k, " " * (30 - len(k)), TargetParameters[k]),
                   target="Header")

    # --LOG CONFIG INFO;
    configInfo = json.dumps(genconf.__dict__, indent=4)
    Logger.log(configInfo, target="Header", show=False)

    # --SHOW DATASET INFO;
    for evolutionDataset in evolutionDatasets:
        Logger.log(interface.parseDatasetInfo("evolution", evolutionDataset),
                   target="Header")
    if evaluationDatasets:
        for evaluationDataset in evaluationDatasets:
            Logger.log(interface.parseDatasetInfo("evaluation",
                                                  evaluationDataset),
                       target="Header")

    # --INITIALIZE WORLD WITH CANDLESTICK DATASET INFO; HERE THE GA KICKS IN;
    GlobalTools.register('Evaluate', Evaluate, GlobalTools.constructPhenotype,
                         backtestconf)

    # --THIS LOADS A DATERANGE FOR A LOCALE;
    if options.benchmarkMode:

        def onInitLocale(World, locale):
            locale.Dataset = [CandlestickDataset({}, {'from': 0, 'to': 0})]
    else:

        def onInitLocale(World, locale):
            locale.Dataset = getLocaleDataset(World, locale)

    loops = [promoterz.sequence.standard_loop.standard_loop]
    World = promoterz.world.World(
        GlobalTools,
        loops,
        genconf,
        TargetParameters,
        EnvironmentParameters={
            'evolution': evolutionDatasets,
            'evaluation': evaluationDatasets
        },
        onInitLocale=onInitLocale,
        web=web,
    )
    World.logger = Logger
    World.EvaluationStatistics = []

    World.backtestconf = backtestconf
    World.evalbreakconf = evalbreakconf
    World.globalconf = globalconf
    World.logger.updateFile()

    # INITALIZE EVALUATION PROCESSING POOL
    World.parallel = promoterz.evaluationPool.EvaluationPool(
        World.tools.Evaluate,
        globalconf.GekkoURLs,
        backtestconf.ParallelBacktests,
        genconf.showIndividualEvaluationInfo,
    )

    # --GENERATE INITIAL LOCALES;
    for l in range(genconf.NBLOCALE):
        World.generateLocale()

    # --RUN EPOCHES;
    while World.EPOCH < World.genconf.NBEPOCH:
        World.runEPOCH()
        if evalbreakconf.evaluateSettingsPeriodically and not options.benchmarkMode:
            if not World.EPOCH % evalbreakconf.evaluateSettingsPeriodically:
                resultInterface.showResults(World)
        if not World.EPOCH % 10:
            print("Total Evaluations: %i" % World.totalEvaluations)

    # RUN ENDS. SELECT INDIVIDUE, LOG AND PRINT STUFF;
    # FinalBestScores.append(Stats['max'])
    print(World.EnvironmentParameters)
    # After running EPOCHs, select best candidates;
    if not options.benchmarkMode:
        resultInterface.showResults(World)
    print("")
    print("\t\t.RUN ENDS.")