Click here to Login








Strategy Optimization on Random in-sample and out-of-sample Periods

by QuantShare, 3044 days ago
Share |






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


Share This ->
Share |


You have to log in to bookmark this object
What is this?
Additional Information




Type: Trading Indicator

Object ID: 1011


Country:
All

Market: All

Style:
Technical Analysis

Reviews
You must log in first

Join now
and get instant access for free to the trading software, the Sharing server and the Social network website.
Click here


Related objects

Empty

Number of reviews
Click to add a review
Average rate
Click to rate this item
Number of times this object was downloaded
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object

Technical Analysis


Fundamental Analysis



Random Blog Posts

Compare stocks and securities by creating a relative performance chart

Buy the best/top rated stocks or how to create powerful rank based trading systems

Ranking stocks based on their correlation with the S&P 500 Index

Creating Stock & Market Short Interest Ratios using Historical Short Sale Data

Select the best ETFs combination to maximize your return and reduce your investment risk

How to turn any ordinary trading strategy into a very profitable one

Charting & Scripts - Manage stock charts using the global script

Trading System: Buy Stocks based on their Sharpe Ratio Rank

Show All

Number of reviews
Click to add a review
Average rate
Click to rate this item
Number of times this object was downloaded
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object






QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright 2019 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.