optimizer – Parallel optimizers

class pyalgotrade.optimizer.server.Results(parameters, result)

Bases: object

The results of the strategy executions.

getParameters()

Returns a sequence of parameter values.

getResult()

Returns the result for a given set of parameters.

pyalgotrade.optimizer.server.serve(barFeed, strategyParameters, address, port)

Executes a server that will provide bars and strategy parameters for workers to use.

Parameters:
  • barFeed (pyalgotrade.barfeed.BarFeed.) – The bar feed that each worker will use to backtest the strategy.
  • strategyParameters – The set of parameters to use for backtesting. An iterable object where each element is a tuple that holds parameter values.
  • address (string.) – The address to listen for incoming worker connections.
  • port (int.) – The port to listen for incoming worker connections.
Return type:

A Results instance with the best results found or None if no results were obtained.

pyalgotrade.optimizer.worker.run(strategyClass, address, port, workerCount=None, workerName=None)

Executes one or more worker processes that will run a strategy with the bars and parameters supplied by the server.

Parameters:
  • strategyClass – The strategy class.
  • address (string.) – The address of the server.
  • port (int.) – The port where the server is listening for incoming connections.
  • workerCount (int.) – The number of worker processes to run. If None then as many workers as CPUs are used.
  • workerName (string.) – A name for the worker. A name that identifies the worker. If None, the hostname is used.
pyalgotrade.optimizer.local.run(strategyClass, barFeed, strategyParameters, workerCount=None, logLevel=40)

Executes many instances of a strategy in parallel and finds the parameters that yield the best results.

Parameters:
  • strategyClass – The strategy class.
  • barFeed (pyalgotrade.barfeed.BarFeed.) – The bar feed to use to backtest the strategy.
  • strategyParameters – The set of parameters to use for backtesting. An iterable object where each element is a tuple that holds parameter values.
  • workerCount (int.) – The number of strategies to run in parallel. If None then as many workers as CPUs are used.
  • logLevel – The log level. Defaults to logging.ERROR.
Return type:

A Results instance with the best results found.

Note

  • The server component will split strategy executions in chunks which are distributed among the different workers. pyalgotrade.optimizer.server.Server.defaultBatchSize controls the chunk size.
  • The pyalgotrade.strategy.BaseStrategy.getResult() method is used to select the best strategy execution. You can override that method to rank executions using a different criteria.

Previous topic

plotter – Strategy plotter

Next topic

marketsession – Market sessions

This Page