Price Modulation
Previous  Top  Next

Back testing has one great pitfall - the data never changes. It has no surprises. You can add code to your strategy and modify your inputs until you have managed to handle the price series and generate a nice smooth equity curve. But then what? How can you know if it will work in the future? Even if you had the superhuman patience to paper-trade it for a year, how would you know it would continue to work after that? That, in strategy development, is the one million dollar question. There are no tools or calculations that you can use to tell you how much you have curve-fit your solution. At this point, it's mostly deduction based upon your testing skill balanced with a measure of gut instinct.

Some investors will use multiple stocks to test the same strategy, and that can help. But each stock, like each person, has it's own unique personality. A strategy that works on a volatile high-tech stock like KLAC would probably not be suitable for a low-volatility blue-chip stock like GM. To take the same approach to all stocks would be extremely difficult, and it doesn't help you at all to create strategies that exploit the unique characteristics of a stock to obtain maximum gains.

The biggest contributor to the problem is that when you are testing, the data never changes. How can you know what would happen if the data were just a little bit different, or even a whole lot different? And the biggest question is the most obvious: the market is always changing - why would you back test against static data?

Because, until now, you didn't have any choice. There were no tools that enabled you to test against changing data. And that is where price modulation comes in.

In Optimax, the price modulator modifies the price series dynamically during optimization. This is an radically new and powerful technique to stress-test your strategy and perform what-if scenarios all at the same time as you are optimizing! There has never been such a invaluable and time-saving feature like this available before for TradeStation.

You control price modulation on the Optimization Settings screen, as shown below.

pricemod1
These settings control the depth and character of the price series modulation.

Waveforms
The price modulator is composed of two low-frequency oscillators. Optimax uses the output of the oscillators to modulate two aspects of the series: the prices points and the range of the bars. On the left, in the Price Osc Type frame, you select the waveform you want an oscillator to produce. (The Noise Amplitude must be set to zero to see a pure waveform.) In the middle, under the Price Modulation and the Range Modulation tabs, you control the characteristics of each oscillator's waveform. On the right, you see two sample graphs: the left graph shows the pure output from an oscillator, and the right shows a sample bar chart with the waveform applied. When the Price Modulation tab is selected, the Price Osc Type controls the Price Modulation oscillator and the graphs display the output from it. When the Range Modulation tab is selected, the Price Osc Type applies to that oscillator, as do the sample graphs.

Oscillator Frequency
The internal resolution of the oscillator is 3600 bars. Another way to state this is that, at an output frequency of 1 Hz, one cycle will last for 3600 bars before repeating. At the oscillator's maximum output frequency of 10 Hz, each cycle lasts for 360 bars.

To calculate the effective duration of the modulation, divide the number of bars per day into 3600. For example, on 5-minute bars with a 1 Hz modulation frequency, one cycle of modulation will last for 3600 / 78 = 46.15 days. At 10 Hz, there will be 10 cycles in that same period and so one cycle will span 4.6 days.

To look at other examples, at 1 Hz on 1-minute bars, the modulation range is 3600 / 390 = 9.2 days; on daily bars, it's 3600 / 1 = 14 years.

Oscillator Amplitude
When the output amplitude of the oscillator is zero, the left-hand sample graph will show a flat line crossing at 0, and no modulation will occur. This is useful when you want to modulate only one aspect of the series: either price or range.

At 10%, Optimax will modulate the prices and/or bar ranges by a maximum of +/-10% at the peaks and valleys of the waveforms.

DC Bias
Using a non-zero DC bias (direct current bias) adds or subtracts a constant value to the prices and/or bar ranges. When used in conjunction with an amplitude less than 5%, you can create a pure increase or decrease in volatility.

Noise Amplitude
Setting a non-zero Noise Amplitude adds a random amount of modulation to the waveform, thus making it "noisy." Without noise, the price series will be statically modulated, meaning that the original, historical series will be modulated, but every trial during the optimization will see the same modulated price series. To use the full potential of price modulation, you must add noise to the modulation. This causes a varying, random amount of modulation to be added to the price series for each individual test, and thus every individual will see a different price series. The amount of difference each individual sees depends on the amount of noise you add to the signal. If you use the maximum noise amplitude of 10%, each individual will see the most difference possible for each test. Using less amplitude will cause each individual to see price series values that are more similar to each other.

The pseudo-random function that Optimax uses is repeatable, meaning that for a given generation/individual number the pseudo-random values will always be the same. This enables Optimax to exactly recreate the price series if you repeat the test, or most importantly when you want to review the trades and/or view the price series in TradeStation the price series will be recreated exactly as it was during the test. Remember, it is not important that the function be truly random; rather, it is important to modify the series in such a way that each test within a single optimization is performed on a differing price series. The repeatable nature of the randomness function ensures that Optimax meets both objectives admirably.

Noise Frequency
The noise frequency setting determines how many bars within a cycle are modulated by noise. At 1%, one in 100 bars are modulated, at 10%, one in 10 are modulated, and at 100%, every bar is modulated. Not all bars need to be modulated in order to produce the desired effect of randomizing the price series. When this value is less than 100%, the modulation values is added to each bar's original prices. When the frequency is at 100%, then every bar is modulated by noise, the values are cumulative, and a random walk effect occurs. This means that the amount of noise modulation applied to each bar is additive, and the series begins to "walk" in random directions.

Modulation On

By selecting Modulation On, you enable price modulation for your optimization, and Optimax will use the output from both oscillators to modulate the price points and bar ranges. The right-hand sample graph displays a sample result of the modulation over one quarter of the effective length of the modulation. With Modulation On deselected, no price modulation is used during the optimization, and the right-hand graph shows an unmodulated sample price series.

The sample series is simply a static set of values used by Optimax for a sample display of the effect of the modulation. It is not real data.

Manual Price Modulation
When you are not optimizing, you can view the effects of your modulation settings directly within TradeStation using the Modulate Prices function.

pricemodbutton  

To use this function:
·In Optimax first turn Modulation On and then click the Modulate Prices button, shown above.  
·Within TradeStation, insert the same symbol into a chart for both datastreams one and two.  
·Within that chart, insert the OMX_PriceModX strategy.  

The price series on datastream 1 will then exhibit the modulation characteristics you specified in the optimization settings.

   

Quick Tip:  
Your reference datastream doesn't also have to be data2 - just change the StreamNum input on the OMX_PriceModX strategy to equal your reference datastream number. For example, if your chart already uses data1 through data4, insert the same symbol as data1 again into data5, and set the StreamNum input to 5.  
 
We use data2 in the documentation only as an example, making it easier to read.  



For example, here you see a price modulation applied to APOL in datastream one. Below it is the same datastream, unmodulated.

pricemodresult
Comparing a modulated with an unmodulated price series.

When you compare datastream one (modulated) with datastream two (unmodulated), you can precisely see the effects of the modulation. Most of the effects in this chart are subtle, but if you look closely you can see the differences. In the highlighted rectangles you can see some easily distinguishable modulation effects. The degree of these changes is entirely under your control - they can be as subtle or as violent as you choose; that depends solely on the settings you specify in the optimization settings window. You can adjust the settings until you achieve the effects you desire.

   

Important Note:  
When Optimax is in Price Modulation mode, each time you change the modulation settings, you need to toggle modulation mode off and back on again, and then toggle the OMX_PriceModX strategy off and on again in order to observe the effects of the change on the TradeStation chart.  



The settings shown below were the ones that we used to create the effect you see above.

pricemodset1
These price modulation settings created the effect shown above.

pricemodset2
These range modulation settings created the effect shown above.

After adjusting the modulation settings and verifying their effects using the above procedure, you can run the optimization with confidence that the price modulation will perform in a manner that you consider appropriate for your purposes.

When you turn the OMX_PriceModX strategy off (or remove it,) restore data1 to its' original state by reloading the chart in TradeStation using View, Refresh, Reload.

When you have performed an optimization with price modulation enabled and after the optimization is complete, you can view the effects of the price modulation for any single individual. To do this, simply enter the generation and individual number into the inputs for the strategy. The price series and trade series will be reconstructed within TradeStation and will display in datastream one. Optimax must be up and in the "optimization stopped" mode to accomplish this.

Refresh Timer On
When adding random noise, the modulation effect becomes different for every individual in an optimization. To get a feel for how the datastream will vary between individuals, select Refresh Timer On. The sample graphs will refresh continuously while varying the random elements of the modulation as they would from individual to individual during an optimization.

Sample Settings
Here are some sample settings for you to try.

clip0019

Summary
Now that it is available, price modulation should become an essential part of all of your back testing. Using static data during a back test is now considered archaic as it easily leads to curve-fitting and provides an unrealistically static test bed for basing your strategy evaluations on.