def fitness(self, genes): ''' Cost function in the optimization process _________________________________________ Parameters genes: list(3) ordered parameters to optimize _________________________________________ Return score: float(1) Error of the cost function ran with this solution ''' # No evoluation in manager (Constant) configuration so reads it statically from file # We want here to optimize the algorithm parameters engine = Simulation() try: engine.configure(bt_cfg=self.bt_cfg, a_cfg={'long_window': genes[0], 'ma_rate': float(genes[1] / 10.0), 'threshold': genes[2]}, m_cfg=None) results = engine.run_backtest() risk_metrics = engine.overall_metrics() except: pdb.set_trace() log.error('Exception caught while running cost function') return 1 return self.evaluate(results, risk_metrics)
def fitness(self, genes): ''' Cost function in the optimization process _________________________________________ Parameters genes: list Parameters to optimize _________________________________________ Return score: float Error of the cost function ran with this solution So the algo tries to minimize it (i.e. 0 is the best score) ''' # No evoluation in manager (Constant) configuration # We try here to optimize the algorithm parameters strategie = { 'manager': { 'name': 'Xavier Bruhiere', 'load_backup': 0, 'max_weight': 0.4, 'buy_amount': 200, 'sell_amount': 100, 'connected': 0 }, 'algorithm': { 'long_window': int(genes[0]), 'ma_rate': float(genes[1] / 10.0), 'threshold': genes[2] } } try: # Run backtest with all configuration dictionnaries analyzes = self.engine.run(self.data, self.configuration, strategie, self.context) # Get back summary performance dictionnary risk_metrics = analyzes.overall_metrics() except: import ipdb ipdb.set_trace() log.error('Exception caught while running cost function') # Return worst result possible return 1 return self.evaluate(risk_metrics)
def fitness(self, genes): ''' Cost function in the optimization process _________________________________________ Parameters genes: list Parameters to optimize _________________________________________ Return score: float Error of the cost function ran with this solution So the algo tries to minimize it (i.e. 0 is the best score) ''' # No evoluation in manager (Constant) configuration # We try here to optimize the algorithm parameters strategie = {'manager': {'name': 'Xavier Bruhiere', 'load_backup': 0, 'max_weight': 0.4, 'buy_amount': 200, 'sell_amount': 100, 'connected': 0}, 'algorithm': {'long_window': int(genes[0]), 'ma_rate': float(genes[1] / 10.0), 'threshold': genes[2]} } try: # Run backtest with all configuration dictionnaries analyzes = self.engine.run(self.data, self.configuration, strategie, self.context) # Get back summary performance dictionnary risk_metrics = analyzes.overall_metrics() except: import ipdb; ipdb.set_trace() log.error('Exception caught while running cost function') # Return worst result possible return 1 return self.evaluate(risk_metrics)