This is a trading item or a component that was created using QuantShare by one of our members.
This item can be downloaded and used by QuantShare Trading Software.
Trading items are of different types. There are data downloaders, trading indicators, trading systems, watchlists, composites/indices...
You can use this item and hundreds of others for free by downloading QuantShare.
Top Reasons Why You Should Use QuantShare:
Works with US and international markets (stock, forex, options, futures, ETF...)
Offers you the tools that will help you become a profitable trader
Allows you to implement any trading ideas
Exchange items and ideas with other QuantShare users
Our support team is very responsive and will answer any of your questions
We will implement any features you suggest
Very low price and much more features than the majority of other trading software
For Free - No Credit Card Required
Strategy Optimization on Random in-sample and out-of-sample Periods
The "RandomMonths" function picks months depending on a percentage value passed to this function. If you specify 100% then the function returns TRUE for all months, if you specify 50% then the function returns TRUE for half of the months and if you specify 0% then the function returns FALSE for all months.
The idea was brought by "mdmd" and it consists of creating random in-sample and out-of-sample periods for trading system or rules optimizations.
Here is a basic trading system formula:
Optimize("a", 30, 90, 10);
Optimize("b", 30, 90, 10);
buy = rsi(14) > a and close > 10 and close*sma(volume,5)>100000;
sell = rsi(14) < b;
Buy a stock if RSI is higher than "a" and sell it if RSI is lower than "b".
We could backtest/optimize this strategy for a specific period (let us say 2000-2006 <- This is our in-sample period). Select the best performing strategies and then perform the backtest on an out-of-sample period (for example, 2006-2011).
Or we could use the "RandomMonths" function to generate random in-sample and out-of-sample periods.
To use the technique, we should add the following lines just below the "sell" rule of the previous trading system:
pass = RandomMonths(70, 15245);
buy = buy and pass;
sell = sell or !pass;
The second parameter of the "RandomMonths" is called random seed and it is a number that initialize a pseudorandom number generator. In order to get different months on each execution, you should change the seed value. A unique in-sample period corresponds to each seed number.
In the above example, the in-sample period contains 70% of the months as specified by the first parameter of the "RandomMonths" function.
We instruct the trading system to buy only if "pass" is true (We are in the in-sample period) and to sell all positions if the "pass" variable becomes false (We are out of the in-sample period). Note that "pass" condition of the sell rule can be removed if you want to keep trades open and use only regular exit rules.
It is possible to optimize the strategy using different in-sample periods by creating an optimizable variable and then adding the variable value to the seed number.
To backtest the strategy during the out-of-sample period:
- Use the same seed number
- Add "!" operator (logical negation) just before the "RandomMonths" function