Use inputs from several securities in Monte Carlo visualizer
Author: lkirsch
Creation Date: 1/25/2016 8:30 AM
profile picture

lkirsch

#1
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.
profile picture

Eugene

#2
Could you rephrase what are the "inputs from several securities", precisely?
profile picture

lkirsch

#3
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
profile picture

Eugene

#4
So what's the problem? Please don't hesitate to be verbose, it's not clear.
profile picture

Cone

#5
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 Monte Carlo
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.
profile picture

Eugene

#6
lkirsch, so the point is: there's no difference if you use external symbols or not.
profile picture

lkirsch

#7
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.
profile picture

Eugene

#8
"Manipulate the prices", "multiple runs"... Your description is cryptic again to be deciphered.
profile picture

LloydM

#9
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?”
profile picture

Eugene

#10
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.
profile picture

LloydM

#11
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?
profile picture

Eugene

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

Cone

#13
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.

CODE:
Please log in to see this code.





profile picture

lkirsch

#14
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.
profile picture

Cone

#15
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.
profile picture

lkirsch

#16
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:

CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).