Beispiel #1
0
                if Strategy:
                    print("Strategy %s descripted on settings but not found on strat folder."\
                          % Strategy)
                Strategy = choice(list(settings['strategies'].keys()))
                print("> %s" % Strategy)

        elif options.strategy:
            Strategy = options.strategy
        else:
            exit("No strategy specified! Use --strat or go --help")
        EvaluationMode = Strategy
        TargetParameters = getSettings()['strategies'][Strategy]

    for s in range(options.repeater):
        gekko_generations(TargetParameters,
                          GenerationMethod,
                          EvaluationMode,
                          web=APP)

elif options.bayesian_optimization:
    import evolution_bayes

    for s in range(options.repeater):
        evolution_bayes.gekko_bayesian(options.strategy)

deltatime = datetime.datetime.now() - markzero_time
print("Running took %i seconds." % deltatime.seconds)

if options.spawn_web:
    print('Statistics info server still runs...')
Beispiel #2
0
def launchJaponicus():
    if not options.genetic_algorithm and not options.bayesian_optimization:
        exit("Aborted: No operation specified.")
    if not os.path.isfile(settings['Global']['gekkoPath'] + '/gekko.js'):
        exit("Aborted: gekko.js not found on path specified @Settings.py;")

    gekko_server = launchGekkoChildProcess() if options.spawn_gekko else None
    web_server = launchWebEvolutionaryInfo() if options.spawn_web else None
    sleep(1)
    markzero_time = datetime.datetime.now()
    showTitleDisclaimer()
    # --SELECT STRATEGY;
    if options.random_strategy:
        Strategy = ""
        GekkoStrategyFolder = listdir(settings['Global']['gekkoPath'] +
                                      '/strategies')
        while Strategy + '.js' not in GekkoStrategyFolder:
            if Strategy:
                print(
                    "Strategy %s descripted on settings but not found on strat folder."
                    % Strategy)
            Strategy = choice(list(settings['strategies'].keys()))
            print("> %s" % Strategy)
    elif options.strategy:
        Strategy = options.strategy
    elif not options.skeleton:
        exit("No strategy specified! Use --strat or go --help")
    # --LAUNCH GENETIC ALGORITHM;
    if options.genetic_algorithm:
        GenerationMethod = 'chromosome' if options.chromosome_mode else 'oldschool'
        if options.skeleton:
            EvaluationMode = 'indicator'
            AllIndicators = getSettings()['indicators']
            TargetParameters = getSettings()['skeletons'][options.skeleton]
            for K in AllIndicators.keys():
                if type(AllIndicators[K]) != dict:
                    TargetParameters[K] = AllIndicators[K]
                elif AllIndicators[K]['active']:
                    TargetParameters[K] = AllIndicators[K]
                    TargetParameters[K]['active'] = (0, 1)
            if not TargetParameters:
                exit("Bad configIndicators!")
        else:
            EvaluationMode = Strategy
            try:
                TargetParameters = getSettings()['strategies'][Strategy]
            # -- Yeah, nested exceptions;
            except KeyError:
                try:
                    TOMLData = TOMLutils.preprocessTOMLFile(
                        "strategy_parameters/%s.toml" % Strategy)
                except FileNotFoundError:
                    TOMLData = TOMLutils.preprocessTOMLFile(
                        "%s/config/strategies/%s.toml" % (GekkoDir, Strategy))
                TargetParameters = TOMLutils.TOMLToParameters(TOMLData)
        for s in range(options.repeater):
            gekko_generations(TargetParameters,
                              GenerationMethod,
                              EvaluationMode,
                              web=web_server)
    # --LAUNCH BAYESIAN OPTIMIZATION;
    elif options.bayesian_optimization:
        import evolution_bayes

        for s in range(options.repeater):
            evolution_bayes.gekko_bayesian(Strategy)
    deltatime = datetime.datetime.now() - markzero_time
    print("Run took %i seconds." % deltatime.seconds)
    if options.spawn_web:
        print('Statistics info server still runs...')
Beispiel #3
0
def launchJaponicus(settings, options):
    # ABORT WHEN ILLEGAL OPTIONS ARE SET;
    if not options.genetic_algorithm and not options.bayesian_optimization:
        exit("Aborted: No operation specified.")
    if not os.path.isfile(settings['global']['gekkoPath'] + '/gekko.js'):
        exit("Aborted: gekko.js not found on path specified @Settings.py;")

    # ADDITIONAL MODES;
    gekko_server = launchGekkoChildProcess(settings)\
        if options.spawn_gekko else None
    web_server = launchWebEvolutionaryInfo()\
        if options.spawn_web else None
    sleep(1)
    markzero_time = datetime.datetime.now()
    showTitleDisclaimer(settings['backtest'])

    print()

    # LOCATE & VALIDATE RUNNING GEKKO INSTANCES FROM CONFIG URLs;
    possibleInstances = settings['global']['GekkoURLs']
    validatedInstances = []
    for instance in possibleInstances:
        Response = evaluation.gekko.API.checkInstance(instance)
        if Response:
            validatedInstances.append(instance)
            print("found gekko @ %s" % instance)
        else:
            print("unable to locate %s" % instance)

    if validatedInstances:
        settings['global']['GekkoURLs'] = validatedInstances
    else:
        exit("Aborted: No running gekko instances found.")

    # --SELECT STRATEGY;
    if options.random_strategy:
        Strategy = ""
        GekkoStrategyFolder = os.listdir(settings['global']['gekkoPath'] + '/strategies')
        while Strategy + '.js' not in GekkoStrategyFolder:
            if Strategy:
                print(
                    "Strategy %s descripted on settings but not found on strat folder." %
                    Strategy
                )
            Strategy = choice(list(settings['strategies'].keys()))
            print("> %s" % Strategy)
    elif options.strategy:
        Strategy = options.strategy
    elif not options.skeleton:
        exit("No strategy specified! Use --strat or go --help")

    # --LAUNCH GENETIC ALGORITHM;
    if options.genetic_algorithm:
        GenerationMethod = 'chromosome' if options.chromosome_mode else 'oldschool'
        if options.skeleton:
            EvaluationMode = 'indicator'
            AllIndicators = getSettings()['indicators']
            TargetParameters = getSettings()['skeletons'][options.skeleton]
            for K in AllIndicators.keys():
                if type(AllIndicators[K]) != dict:
                    TargetParameters[K] = AllIndicators[K]
                elif AllIndicators[K]['active']:
                    TargetParameters[K] = AllIndicators[K]
                    TargetParameters[K]['active'] = (0, 1)
            if not TargetParameters:
                exit("Bad configIndicators!")
        else:
            EvaluationMode = Strategy

            # READ STRATEGY PARAMETER RANGES FROM TOML;
            try:
                TOMLData = TOMLutils.preprocessTOMLFile(
                    "strategy_parameters/%s.toml" % Strategy
                )
            except FileNotFoundError:
                print("Failure to find strategy parameter rules for " +
                      "%s at ./strategy_parameters" % Strategy)
                gekkoParameterPath = "%s/config/strategies/%s.toml" %\
                                     (settings['global']['GekkoDir'], Strategy)
                print("Trying to locate gekko parameters at %s" %
                      gekkoParameterPath)
                TOMLData = TOMLutils.preprocessTOMLFile(gekkoParameterPath)

            TargetParameters = TOMLutils.TOMLToParameters(TOMLData)
        # RUN ONE EQUAL INSTANCE PER REPEATER NUMBER SETTINGS, SEQUENTIALLY;
        for s in range(options.repeater):
            gekko_generations(
                TargetParameters, GenerationMethod,
                EvaluationMode, settings, options, web=web_server
            )

    # --LAUNCH BAYESIAN OPTIMIZATION;
    elif options.bayesian_optimization:
        import evolution_bayes

        for s in range(options.repeater):
            evolution_bayes.gekko_bayesian(Strategy)
    deltatime = datetime.datetime.now() - markzero_time
    print("Run took %i seconds." % deltatime.seconds)
    if options.spawn_web:
        print('Statistics info server still runs...')
   #web_server = Popen(web_args, stdin=PIPE, stdout=PIPE)
   print("WEBSERVER MODE")
   APP = web.run_server()
   P = Thread(target=APP.server.run, kwargs={'debug':False, 'host':'0.0.0.0'})
   P.start()

   sleep(2)
markzero_time = datetime.datetime.now()
print("The profits reported here are in relation to market price change;\n"+\
      "\ti.e shown profit = { backtest profit } - { market profit in evaluated candlestick period };")
if options.genetic_algorithm:
   GenerationMethod = 'chromosome' if options.chromosome_mode else 'oldschool'


   for s in range(options.repeater):
      gekko_generations(options.strategy, GenerationMethod)

elif options.bayesian_optimization:
    import evolution_bayes
    if options.strat:
       settings['bayesian']['Strategy'] = strat
    for s in range(options.repeater):
       evolution_bayes.gekko_bayesian(strat)

deltatime = datetime.datetime.now() - markzero_time
print("Running took %i seconds." % deltatime.seconds)

if options.spawn_web:
    print('Statistics info server still runs...')

Beispiel #5
0
def launchJaponicus(parser):

    settings = getSettings()

    # PARSE GENCONF & DATASET COMMANDLINE ARGUMENTS;
    settingSubsets = ['generations', 'dataset', 'backtest', 'evalbreak']
    for settingSubset in settingSubsets:
        parser = promoterz.metaPromoterz.generateCommandLineArguments(
            parser, settings[settingSubset])

    options, args = parser.parse_args()
    for settingSubset in settingSubsets:
        settings[
            settingSubset] = promoterz.metaPromoterz.applyCommandLineOptionsToSettings(
                options, settings[settingSubset])

    # ABORT WHEN ILLEGAL OPTIONS ARE SET;
    if not options.genetic_algorithm and not options.bayesian_optimization:
        exit("Aborted: No operation specified.")
    if not os.path.isfile(settings['Global']['gekkoPath'] + '/gekko.js'):
        exit("Aborted: gekko.js not found on path specified @Settings.py;")

    # ADDITIONAL MODES;
    gekko_server = launchGekkoChildProcess() if options.spawn_gekko else None
    web_server = launchWebEvolutionaryInfo() if options.spawn_web else None
    sleep(1)
    markzero_time = datetime.datetime.now()
    showTitleDisclaimer(settings['backtest'])

    # --SELECT STRATEGY;
    if options.random_strategy:
        Strategy = ""
        GekkoStrategyFolder = listdir(settings['Global']['gekkoPath'] +
                                      '/strategies')
        while Strategy + '.js' not in GekkoStrategyFolder:
            if Strategy:
                print(
                    "Strategy %s descripted on settings but not found on strat folder."
                    % Strategy)
            Strategy = choice(list(settings['strategies'].keys()))
            print("> %s" % Strategy)
    elif options.strategy:
        Strategy = options.strategy
    elif not options.skeleton:
        exit("No strategy specified! Use --strat or go --help")

    # --LAUNCH GENETIC ALGORITHM;
    if options.genetic_algorithm:
        GenerationMethod = 'chromosome' if options.chromosome_mode else 'oldschool'
        if options.skeleton:
            EvaluationMode = 'indicator'
            AllIndicators = getSettings()['indicators']
            TargetParameters = getSettings()['skeletons'][options.skeleton]
            for K in AllIndicators.keys():
                if type(AllIndicators[K]) != dict:
                    TargetParameters[K] = AllIndicators[K]
                elif AllIndicators[K]['active']:
                    TargetParameters[K] = AllIndicators[K]
                    TargetParameters[K]['active'] = (0, 1)
            if not TargetParameters:
                exit("Bad configIndicators!")
        else:
            EvaluationMode = Strategy

            # READ STRATEGY PARAMETER RANGES FROM TOML;
            try:
                TOMLData = TOMLutils.preprocessTOMLFile(
                    "strategy_parameters/%s.toml" % Strategy)
            except FileNotFoundError:
                print("Failure to find strategy parameter rules for" %
                      (Strategy) + "%s at ./strategy_parameters" % Strategy)
                gekkoParameterPath = "%s/config/strategies/%s.toml" %\
                                     (settings['global']['GekkoDir'], Strategy)
                print("Trying to locate gekko parameters at %s" %
                      gekkoParameterPath)
                TOMLData = TOMLutils.preprocessTOMLFile(gekkoParameterPath)

            TargetParameters = TOMLutils.TOMLToParameters(TOMLData)
        # RUN ONE EQUAL INSTANCE PER REPEATER NUMBER SETTINGS, SEQUENTIALLY;
        for s in range(options.repeater):
            gekko_generations(TargetParameters,
                              GenerationMethod,
                              EvaluationMode,
                              settings,
                              options,
                              web=web_server)
    # --LAUNCH BAYESIAN OPTIMIZATION;
    elif options.bayesian_optimization:
        import evolution_bayes

        for s in range(options.repeater):
            evolution_bayes.gekko_bayesian(Strategy)
    deltatime = datetime.datetime.now() - markzero_time
    print("Run took %i seconds." % deltatime.seconds)
    if options.spawn_web:
        print('Statistics info server still runs...')
Beispiel #6
0
         GekkoStrategyFolder = listdir(settings['Global']['gekkoPath']+'/strategies')
         while Strategy+'.js' not in GekkoStrategyFolder:
            if Strategy:
               print("Strategy %s descripted on settings but not found on strat folder."\
                     % Strategy)
            Strategy = choice(list(settings['strategies'].keys()))
            print("> %s" % Strategy)

      elif options.strategy:
         Strategy = options.strategy
      else:
         exit("No strategy specified! Use --strat or go --help")
      EvaluationMode = Strategy
      TargetParameters = getSettings()['strategies'][Strategy]

   for s in range(options.repeater):
      gekko_generations(TargetParameters, GenerationMethod, EvaluationMode, web=APP)

elif options.bayesian_optimization:
   import evolution_bayes
   
   for s in range(options.repeater):
      evolution_bayes.gekko_bayesian(options.strategy)

deltatime = datetime.datetime.now() - markzero_time
print("Run took %i seconds." % deltatime.seconds)

if options.spawn_web:
    print('Statistics info server still runs...')

Beispiel #7
0
parser.add_option('-k', '--gekko', dest='SpawnGekko',
                  action='store_true', default=False)
parser.add_option('--repeat <X>', dest='Repeater',
                  type=int, default=1)
parser.add_option('--strat <strat>', dest='Strategy',
                  default=settings['generations']['Strategy'])
                  
options, args = parser.parse_args()

G=None
if options.SpawnGekko:
   if options.GeneticAlgorithm or options.BayesianOptimization:
        GekkoArgs = ['node',
                     '--max-old-space-size=8192',
                     settings['global']['gekkoPath']+'/web/server.js']

        G = Popen(GekkoArgs, stdin=PIPE, stdout=PIPE)
        sleep(2)
if options.GeneticAlgorithm:
    for S in range(options.Repeater):
        Strat = choice(settings['global']['Strategies'])\
                if options.Strategy == 'all'\
                else options.Strategy
        gekko_generations(Strat)
elif options.BayesianOptimization:
    import evolution_bayes
    evolution_bayes.gekko_bayesian()

if G:
    G.kill()