def evaluate(self, results, risks): ''' Define score from raw cost function results ''' score = [risks['Returns'], risks['Sharpe.Ratio'], risks['Max.Drawdown'], risks['Volatility']] if score[0]: log.notice(risks) log.notice([results['portfolio_value'][-1], results['pnl'].cumsum()[-1], (results['returns'] + 1).cumprod()[-1]]) return 1 - score[0]
def evaluate(self, risks): ''' Define score from raw cost function results ''' score = [risks['Returns'], risks['Sharpe.Ratio'], risks['Max.Drawdown'], risks['Volatility']] # Debug purpose if score[0]: log.notice(risks) # Compute score from cummulative returns, return 1 - score[0]
default=0.5, required=False, help='Probability for a mutation to happen') parser.add_argument('-n', '--notify', action='store_true', help='Flag to send android notification') parser.add_argument('-r', '--remote', action='store_true', help='running mode, used for logging message endpoint') args = parser.parse_args() log_setup = (remote_setup if args.remote else color_setup) with log_setup.applicationbound(): #TODO manage float parameters #NOTE A dico might be more readable #FIXME Step is the same whatever the parameter, scale issue score, best_parameters = genetic_optimize([(100, 200), (3, 9), (0, 20)], Metric(), popsize=args.popsize, step=args.step, elite=args.elitism, maxiter=args.iteration, mutprob=args.mutation, notify_android=args.notify) log.notice('Best parameters evolved: {} -> {}'.format( best_parameters, score))
''' Quick and dirty interface for running genetic optimization process ''' parser = argparse.ArgumentParser(description='Trading strategie optimization through genetic algorithm') parser.add_argument('-v', '--version', action='version', version='%(prog)s v0.8.1 Licence rien du tout', help='Print program version') parser.add_argument('-p', '--popsize', type=int, action='store', default=10, required=False, help='number of chromosomes in a population') parser.add_argument('-e', '--elitism', type=float, action='store', default=0.2, required=False, help='% of best chromosomes kept as is for the next generation') parser.add_argument('-s', '--step', type=float, action='store', default=1.0, required=False, help='Mutation leverage') parser.add_argument('-i', '--iteration', type=int, action='store', default=20, required=False, help='Max number of evolution iteration') parser.add_argument('-m', '--mutation', type=float, action='store', default=0.5, required=False, help='Probability for a mutation to happen') parser.add_argument('-n', '--notify', action='store_true', help='Flag to send android notification') parser.add_argument('-r', '--remote', action='store_true', help='running mode, used for logging message endpoint') args = parser.parse_args() log_setup = (remote_setup if args.remote else color_setup) with log_setup.applicationbound(): #TODO manage float parameters #NOTE A dico might be more readable #FIXME Step is the same whatever the parameter, scale issue score, best_parameters = genetic_optimize([(100, 200), (3, 9), (0, 20)], Metric(), popsize = args.popsize, step = args.step, elite = args.elitism, maxiter = args.iteration, mutprob = args.mutation, notify_android=args.notify) log.notice('Best parameters evolved: {} -> {}'.format(best_parameters, score))