New Monte Carlo tests, Money management snippet and Custom blocks

In recent months, the sharing server and Strategy Quant X have both been updated with new snippets, which provides the ability to assess the robustness of strategies. We define “robustness” as the ablity of strategies to preserve their qualitative attributes over time.

We have included three new Monte Carlo tests and one Money Management snippet. We will now provide a concise description of each of them and how they can assist in the successful expansion of the equity curve of your strategies, thereby enabling you to successfully navigate the path of an algorithmic trader.

We have added the following new snippets:

  • Monte Carlo – Modified Randomize strategy parameters 
  • Monte Carlo – Randomize SWAP of a whole backtest  
  • Monte Carlo –  Randomize SWAP of a every trade 
  • Fixed proportional position sizing
  • New Custom blocks based on Is rising/ Is falling logic

 

This blog article will explain and detail these snippets and how to use them.

 

Monte Carlo – Customizable Randomize Strategy parameters

It is a modified Randomize Strategy parameter test.  For the default test, the parameters that are randomized are predetermined. The Trading options are randomized in practice, while the Shifts are not. Such a setup, in my opinion, prevents us from evaluating the start strategies in as much detail as we would need.

You can see the snippet’s setting in the example above.

 

Monte Carlo Modified Randomize Strategy parameters is a parameterizable snippet that allows you to randomize the parameters used in strategies. You can specify what you want to randomize.

  • Periods
  • Schicht
  • Constants
  • Other Params
  • Exit Used
  • Exit Unused
  • Boolesche
  • Trading Options

This test significantly improves your ability to test strategies and. My typical workflow includes several steps for using these tests.

  1. I randomize the periods of the indicators.
  2. I randomize the exit used – stop loss and profit targets.
  3. I randomize the constants. 
  4. ...

 

Most strategies include an indicator with a Period type parameter (for example, Moving Average  has a period of 20).This is the first one in which I determine whether the strategy is not overoptimized at the Period level. Then I randomize the parameters of a type: Exit Used (stop loss and profit targets). In the case of shifts, If you are testing Shift type parameter , use maximum change values of 100 or greater. The maximum change of 100 or more indicates that the shift can move down or up by 100% or more (from 1 to 2).

The symmetry of the parameters (the same parameters apply to both long and short trades) can also be set. By default, this parameter is set to True.

 

Monte Carlo Randomize SWAP of a whole backtest 

A SWAP is the interest fee or credit that is applied to a trader’s account when they hold a position overnight in forex or CFD trading. This fee is determined by the interest rate differential between the two currencies in a forex pair or the cost of maintaining a position in CFDs. It can be either positive (a credit) or negative (a debit) depending on the direction of the trade and the interest rate differential.

 

If we apply this Monte Carlo test, each backtest will contain swap values that are randomly generated within the range [-Range,Range].Simply said, by doing 500 (or a different number) backtests with randomly generated swaps, you can acquire a Monte Carlo analysis perspective on the altering of the Swaps. 

In this particular example, we have run 100 simulations with randomised SWAP for every trade.

 

This parameter in the snippet is a subject to randomization:

  • Range: the range within which the swap is selected.

A random number within the range of -20 to 20 is generated when Range = 20 is selected. The second random number will be negative if the first one is positive. This will ensure that we consistently specify both positive and negative spread.

The following parameters are fixed and not subject to randomization:

  • Swap Type – Method of swap calculation ( points, money, percentages) 
  • Tripple Swap The day when a triple swap is applied 
  • Hour during which the swap is counted

It is possible to modify each of the parameters that were previously mentioned.

 

Monte Carlo Randomize SWAP of every trade 

In this particular example, we have run 100 simulations with randomised SWAP for every trade.

 

This test differs from the previous one in that it randomizes each trade in the current backtest. The initial trade may involve a positive long swap and a negative short swap, while the subsequent trades may have swap combinations that are entirely distinct. Therefore, this test implements a random swap for each trade. If the number of Monte Varlo simulations is set to 500, there will be 500 existing backtests, each of which has a unique swap.

The performance of the strategy in the presence of changing interest rates that influence the size of swaps should be simulated by both of these tests.

 

Fixed proportional position sizing.

Fixed proportional position sizing is a money management snippet that enables you to connect the fixed size of lot contracts with a specific proportion of the balance. This enables a more effective adaptation to the balance’s increase or decrease during backtests.

The example above illustrates the increasing equity/balance curve and the increasing number of lots traded in each trade.

 

Example of Fixed Proportional Sizing in Futures

The strategy with Fixed Money proportional sizing trades one micro Nasdaq contract for every 2000 balance. If the balance is 4000, the strategy will trade two microcontracts.

Example of Fixed Proportional Sizing in Forex

I have a balance of 2000 and would like to trade every 500 0.01 lots. In this case, I’ll trade 0.04 lots and have between $2000 and $2500 in my account. If my balance reaches 2501, I’ll trade 0.05 lot.

Paramaters 

  • Order Size per per balance proportion
  • Proportion of the balance
  • Mininmum  Order Size

Money management is implemented for platforms Metatrader 4, Metatrader 5, Tradestation, and Multicharts.

 

Is Rising/Is Falling Custom Blocks 

Custom blocks are essential for optimizing the flexibility of algorithmic trading strategies in StrategyQuant X. They enable users to establish their own trading logic and rules in addition to the standard set of indicators or actions that are available on the platform.

Custom blocks can be employed to generate unique conditions, signals, or indicators that are suitable with particular trading strategies. For instance, it is possible to establish a custom block that determines whether the Relative Strength Index (RSI) remains above a predetermined threshold for a specified quantity of bars. This provides users with the ability to regulate the manner in which their strategies respond to specific market conditions over time 

Advanced logic, such as the detection of false breakouts, consecutive price movements, or customized conditions that involve multiple comparisons, can also be incorporated into custom blocks. These blocks can be configured in the Algo Wizard or utilized directly within StrategyQuant’s Builder or in the strategy template.

The isRising/isFalling custom block logic has enabled the possibility of customization.  These are more accurately parameterized than the defeault one -> You can set/optimize the duration of the rising or falling by more than 2 bars.

In this example we can see that custom block Is Rising BarRange can be optimized from 2 – 24 bars.

 There are  54 new custom blocks in total.

 

You can download all of the snippets in codebase hier.

 

 

clonex / Ivan Hudec

Ivan Hudec, known as “Clonex” on the forum, is an experienced algorithmic trader, consultant, and researcher who has been trading for 15 years and using StrategyQuant X (SQX) since 2014. He contributes to the SQX blog and enhances the software by adding new indicators, snippets, and incorporating Python programming for advanced data analysis, machine learning algorithms, and quantitative modeling. Ivan offers his expertise to help others accelerate their trading projects and approach them in innovative ways.

Abonnieren
Benachrichtigen Sie mich bei
1 Kommentar
Älteste
Neuestes Meistgewählt
Inline-Rückmeldungen
Alle Kommentare anzeigen
Chris G
Chris G
2. 10. 2024 2:59 am

This is incredible, the Montecarlo in detail is always needed!!!

Lesen Sie weiter