Building Trading Strategies Brute-Force Optimization

Brute-Force Optimization

One of Botmain's most powerful features is strategy optimization. Optimization involves finding the optimal parameters to minimize or maximize a particular outcome. The desired outcome could be anything, although its usually maximizing the profit or minimzing the drawdown. You can define custom fitness expressions based on your portfolio analytics and run hundreds or thousands of backtests simultaneously to find optimal fit.

Botmain also has features to gaurd against curve-fitting, which is a phenomenon when you over-optimize your strategy to a particular dataset, which can then yield worse-than-expected results on a new dataset (such as future data). To help with that Botmain provides Walk-Forward Optimization, which is a process of dynamic optimization and rebalancing where you partition the dataset into chunks of in-sample data (for training) and out-of-sample data (for trading)

You can add contraints to filter out outliers of bad performance and reduce results to the top fitting outcomes among thousands. Once your top strategies are selected, you can apply weighted portfolio optimization techniques to allocate different amounts of capital to strategies based on different criteria.

Running an optimization

  1. Define parameters or inject indicators into your strategy class:
  1. Open the Optimization Run Settings:
  1. Add an expression to optimize
  • You can select a predefined portfolio metric from the dropdown or define a custom one using code via the Reporting Engine.
  1. Set in-sample selection criteria
  • Define criteria for the selection of top fitting outcomes
  1. Add constraints to filter bad performance outliers
  • Use constraints to filter out experiments that don't pass desired risk and returns thresholds
  1. Define Walk-Forward Parameters
  • The prevent curve-fitting, you can optionally train your algorithm on a subset of the whole data, and then trade using a different subset of data.
  1. Define Optimization Weights
  • To apply weighted optimization to the allocation of capital to your strategy you can use some of the advanced options in this section

  • Volatility-based Weight Optimization - Capital is allocated to the strategy inverse proportionally to the volaility of its PnL curve.

  • Mean-Variance Optimization A classical Markowitz portfolio optimization for which we use average past returns and covariance metrics of returns as risk parameters.

  • Genetic Optimization Allows you to search for the optimal set of weights using a genetic algorithm.

  1. Run the Optimization
  • Analyze the top fittest results to determine which parameters performed best.