Do you want to get informed about new posts via Email?

Use inputs from several securities in Monte Carlo visualizer

Author: lkirsch

Creation Date: 1/25/2016 8:30 AM

My reading of the documentation on Monte Carlo in visualizer is that it uses the results

of a strategy (trades) for its basis. How do I get it to use inputs from several securities

to be randomized, and then have the Monte Carlo use them.

of a strategy (trades) for its basis. How do I get it to use inputs from several securities

to be randomized, and then have the Monte Carlo use them.

I have a strategy that uses securities A, B, and C to determine whether I have a buy or sell.

I then buy/sell securities D,E

I then buy/sell securities D,E

QUOTE:

How do I get it to use inputs from several securities to be randomized, and then have the Monte Carlo use them.

Here's a step-by-step quick start guide:

1. In Preferences (F12) > Performance Visualizers > Check

2. Open your Strategy (Visualizers must be selected before opening the window)

3. Select Portfolio Simulation Sizing mode, for example, Percent of Equity Sizing.

4. Highlight your DataSet containing all your symbols

5. Execute the backtest

6. In the Monte Carlo view, configure the Settings. Depending on what you want to model, this takes a little know-how. See the User Guide.

7. Click Go and wait.

8. When complete, view the Analysis and Probabilities tabs.

Your procedure won't work for the test I want.

I select securities A,B,C using "SetContext.

I then manipulate the prices to determine whether I should buy/sell securities D,E.

What I want the Monte Carlo to do is to run the strategy many times withe variations

on the prices of A,B,C to determine the impact on the strategy.

Can the visualizer do this, or does one have to surround the program with code that

can make multiple runs of the strategy?

PS-I think Wealthlab is a great program, and I would hate having to write Python code from

scratch to accomplish this.

I select securities A,B,C using "SetContext.

I then manipulate the prices to determine whether I should buy/sell securities D,E.

What I want the Monte Carlo to do is to run the strategy many times withe variations

on the prices of A,B,C to determine the impact on the strategy.

Can the visualizer do this, or does one have to surround the program with code that

can make multiple runs of the strategy?

PS-I think Wealthlab is a great program, and I would hate having to write Python code from

scratch to accomplish this.

Eugene,

I think that another example of the question that lkirsch is asking can be described as follows:

Suppose that the algorithm is to own 2 stocks (ie. AMZN, NFLX) when the SPY is above its 200 day MA and to own a different 2 stocks (ie. CLX, JNJ) when the SPY is below its 200 day MA. In order to accomplish this, the Monte Carlo routine would need to randomize the SPY values as well as the purchased stocks (AMZN, NFLX, CLX, JNJ).

The question would then be “Can the Monte Carlo algorithm be set up to randomize the signal equity (SPY) as well as the traded equities?”

I think that another example of the question that lkirsch is asking can be described as follows:

Suppose that the algorithm is to own 2 stocks (ie. AMZN, NFLX) when the SPY is above its 200 day MA and to own a different 2 stocks (ie. CLX, JNJ) when the SPY is below its 200 day MA. In order to accomplish this, the Monte Carlo routine would need to randomize the SPY values as well as the purchased stocks (AMZN, NFLX, CLX, JNJ).

The question would then be “Can the Monte Carlo algorithm be set up to randomize the signal equity (SPY) as well as the traded equities?”

Thanks Lloyd. That's much clear as the original question doesn't make sense to me.

The MC Lab does not "know" about your so called "signal equity". For MCL it's just another DataSeries and it will not attempt to randomize it. Consequently, it's entirely up to your Strategy to randomize the external series if you wish. You could, for example, randomize the OHLC of SPY's GetExternalSymbol object in your Strategy.

The MC Lab does not "know" about your so called "signal equity". For MCL it's just another DataSeries and it will not attempt to randomize it. Consequently, it's entirely up to your Strategy to randomize the external series if you wish. You could, for example, randomize the OHLC of SPY's GetExternalSymbol object in your Strategy.

Eugene,

One of the big benefits of MCL is that it analyzes a run of 500+ simulations. However, if the randomization of the SPY’s OHLC dataseries is done in the WealthLab program, then I suspect that the randomization of the SPY dataseries would be done only once for every run.

Is this a correct assumption?

One of the big benefits of MCL is that it analyzes a run of 500+ simulations. However, if the randomization of the SPY’s OHLC dataseries is done in the WealthLab program, then I suspect that the randomization of the SPY dataseries would be done only once for every run.

Is this a correct assumption?

I haven't tried it but having taken a quick look at the code I would say that's a reasonable assumption.

MC-Lab does not randomize DataSeries of specific instruments under test. The scramble modes are discussed in the User Guide: Monte Carlo-Lab > Monte Carlo Settings, but the idea is that it uses the *raw trades data from a strategy backtest*. There is also an equity curve scramble that doesn't use the raw trades.

(Side note: I almost exclusively use "Same Date Scramble" to show the distribution of system results had trades occurred in a different order on days in which you don't have enough cash to purchase all trade candidates. Other Trade Randomization methods tend to smooth out the equity curve unrealistically by distributing raw trades somewhat evenly over the entire test period.)

*On to lkirsch's question...*

The answer is no. You cannot use MCL in the way you suggested. As I just discussed, MCL randomizes the raw trades that are generated by the backtest. You, however, want the strategy to create different results based on a parameter set. You can accomplish that using the**Optimizer**.

Here's a framework with your example as a basis. It might more basic than what you're asking, but it selects the "control" stock from a list using a strategy parameter as an index. The crossovers of the moving averages from this stock are used to decide when to buy and sell another stock, which is selected from a different list.

**Set up: (WLP 6.9.15 is required to run this example)**

1. Put all instruments in the same DataSet

2. To run the script, click on the symbol with the longest history

3a. Change parameters to see different results, or,

3b. Click Optimize and run an Exhaustive optimization to compare results in tables and graphically.

(Side note: I almost exclusively use "Same Date Scramble" to show the distribution of system results had trades occurred in a different order on days in which you don't have enough cash to purchase all trade candidates. Other Trade Randomization methods tend to smooth out the equity curve unrealistically by distributing raw trades somewhat evenly over the entire test period.)

The answer is no. You cannot use MCL in the way you suggested. As I just discussed, MCL randomizes the raw trades that are generated by the backtest. You, however, want the strategy to create different results based on a parameter set. You can accomplish that using the

Here's a framework with your example as a basis. It might more basic than what you're asking, but it selects the "control" stock from a list using a strategy parameter as an index. The crossovers of the moving averages from this stock are used to decide when to buy and sell another stock, which is selected from a different list.

1. Put all instruments in the same DataSet

2. To run the script, click on the symbol with the longest history

3a. Change parameters to see different results, or,

3b. Click Optimize and run an Exhaustive optimization to compare results in tables and graphically.

CODE:

Please log in to see this code.

What about the following approach to varying the "control" stock.

Suppose there is only one control stock (say SPY).

Each time you enter the strategy you vary the DataSeries of SPY in the following way;

SPY(varied)= SPY(true)+R*variance(SPY)

where R is a random number between -1 and +1. Hence the mean change in the

price series is zero.

One introduces a parameter which ranges from 1 to 1000 with step size 1 and

then run an exhaustive search on this parameter. The optimization results

then gives you the behavior of the strategy based on the variation of the

control stock.

Suppose there is only one control stock (say SPY).

Each time you enter the strategy you vary the DataSeries of SPY in the following way;

SPY(varied)= SPY(true)+R*variance(SPY)

where R is a random number between -1 and +1. Hence the mean change in the

price series is zero.

One introduces a parameter which ranges from 1 to 1000 with step size 1 and

then run an exhaustive search on this parameter. The optimization results

then gives you the behavior of the strategy based on the variation of the

control stock.

That's a pretty simple modification. Now just click on SPY or any other control symbol to run it.

CODE:

Please log in to see this code.

Thanks very much for your code.

There are some problems with it, which I'll try to address below:

1) R has a range from 0 to 1 whereas for the MC calculation it should be from -1 to 1

2) The variation, I believe should go as the SD not SD*SD

3) A different R should be used at each step in the DataSeries generation.

So the code should look like:

There are some problems with it, which I'll try to address below:

1) R has a range from 0 to 1 whereas for the MC calculation it should be from -1 to 1

2) The variation, I believe should go as the SD not SD*SD

3) A different R should be used at each step in the DataSeries generation.

So the code should look like:

CODE:

Please log in to see this code.