Liu Optimizer

@amor71
3 min readJun 24, 2021

--

Photo by Damir Kopezhanov on Unsplash

I wrote LiuAlgoTrader so I can trade using my long-earned development skill-set. Consistent winning is not easy.

That’s when back-testing enters:a tool that lets you test-drive your strategies, compressing months of potential trading into minutes of calculations.

Almost every strategy that I wrote has some configuration parameters. These parameters are the number of equities in your portfolio, EMA thresholds, length of the rolling window for volatility calculations, etc.

These parameters needs to be optimized to tune your strategy.

Enter Hyperparameters

In machine learning, a hyperparameter is a parameter whose value is used to control the learning process. By contrast, the values of other parameters are derived via training.

In other words, hyper-parameters span the configuration space of strategies, selecting the optimal values can drastically improve strategies performance.

With release 0.3.11, LiuAlgoTrader has a new tool: optimizer . This unique application allows running, parallel back-testing of strategies while generating all possible combinations for hyper-parameters and storing these results to the database.

Once the optimization session ends,use a Jupyter Notebook to load all the back-test results and compare how the different configurations affect total returns, Sharpe ratio, and volatility.

It is now up to you to select your desired parameters by taking these three data points (or add a few of your own).

Let us see an example: you’re running a ‘Trend Following’ strategy with an account with $10,000 and wish to select the number of different equities that should make up your algo traded.

Your `tradeplan. toml` file looks something like this:

Sample trade-plan

But is ‘10’ really the best selection forstock_count? Enter optimizer :

Adding these lines to the configuration files instructs the optimizer application to run back-test sessions in the first half of 2021. The hyper-parameter is “stock_count,” with values ranging from 5 to 15. The optimizer can receive several hyper-parameters and create and iterate through the entire configuration space.

Contrary to the hyper-parameter, the ”parameters” depict how to calculate and over-ride the strategy configuration parameter for “portfolio_id.” For each execution of the back-test iteration, a new portfolio is generated with $10,000 and a credit line of $1,000.

Running the optimizer is as simple as typing:

optimizer

The optimizer may run for a while, producing an output:

Sample `optimizer` run

Make sure to copy and optimizer session-id -> you will need it later for your analysis.

Once completed, use the dedicated Notebook to view the collection of back-test sessions:

The Notebook loads all portfolio's transactions and analyzes them to produce the answer:

So it’s not “10” but rather “11” that yields the best returns and best Sharpe ratio for the strategy!

For further reading check LiuAlgoTrader optimizer documentation.

Questions? Issues? Feel free to post a question on the LiuAlgoTrader Gitter page or open an issue on GitHub or email me directly.

--

--

@amor71

Software as a form of Art, Father, Cat Herder & Algo-Trader