Building a fully automated, algorithmic trading strategy can seem like a daunting task but can actually be broken down into a series of simple steps.
In this post, we’ll go through the three steps to building an algorithmic strategy: Idea, Test, and Trade, and break down what you need to know at each step.
1. Idea
Every strategy starts with an idea, or theory, about the market that you believe can be consistently exploited for profit.
However, before you can start acting on your ground-breaking idea, you need to answers a few questions first:
- What asset am I going to trade?
- What data am I going to use to build my strategy?
- What granularity of data do I need?
- Is this data clean and reliable?
- How much data do I need?
- How is the strategy going to be implemented?
- Are you going to trade on the spot market, explore futures, or maybe dive into options trading?
- Will it be fully automated or require human intervention?
- What broker will you use to actually execute the trades?
Most traders know the answers to these questions but putting them down on paper can help organize your thoughts and reduce headaches down the road.
Next, you need to decide what a successful strategy means to you. Without having a clear goal set out, there is no way to get there.
- What metric are you optimizing for?
- The Sharpe Ratio is a popular one but do you really want to compare to the risk-free rate of return or some other baseline? Do you see upside volatility as a negative aspect to your strategy?
- What is the maximum amount of risk you are willing to accept for the returns you are seeking?
- Trading with a small < $10,000 account is much different than a larger account that represents a significant portion of your account.
- As always, never trade with money you cannot afford to lose.
-
How often do you want to trade and how long do you want to hold those trades open?
- You may come up with a great strategy that maximizes your performance metric, but if it only trades once every 3 years is that okay with you?
Defining what success looks like to you is an important step that most traders pass over in search of the “Holy Grail” that they never seem to find. Approaching trading as a business, with clear profit targets and a growth plan, gives you an achievable goal that can drive the development of your strategy.
Okay, moving onto the fun part: the underlying idea of your strategy. You need to have some belief as to why you should be trading and why you will be successful. Whether you believe the market behaves in cyclical waves and you want to find a statistically significant pattern to exploit or you have a view about the underlying fundamentals of the asset that you believe are not reflected in the price, you need to have something driving you to get into the market. While your initial theory may not turn out to be correct, there must be a starting point for your journey into developing a strategy.
Your final task in this first step is research, another step that many traders skip.
- Who has attempted something similar to your strategy?
- What steps did they go through?
- Where were they successful?
- Where did they go wrong?
- What are you going to do different?
Chances are someone has attempted something similar to you and learning about their process can give you a huge jump start in your development. It is also important to look at other people’s work objectively. If someone did exactly what you were going to do and they just couldn’t make it work, you need a good reason why you will be successful.
Now that you have figured out the basics to your strategy, defined what a successful strategy means to you, and researched similar strategies, it’s time to actually build and test your idea!
2. Test
Testing your idea is the most important and difficult step to do correctly. It is also an area that will differ the most between strategies.
There are a couple of themes that should guide the testing of your strategy:
Out-of-sample, out-of-sample, out-of-sample
I cannot stress the importance of out-of-sample testing enough and while most traders think they are doing it correctly, it is very easy to have your biases creep in. I suggest breaking the available data into three different data sets:
- Training Set
-
This will be where you spend the majority of your time. This is where you optimize the parameters of your strategy (indicators, indicator periods, entry and exit signals, position sizing, etc.).
-
It should include a wide variety of different market conditions and I generally include about 60% of the data here.
- Test Set
- This is the first level where you test your strategy over new data and is used to compare strategies.
- For example, if you are trying to decide between two different breakout strategies that use different indicators, your test set will give you a more accurate measure of how they will perform moving forward.
- I usually include 20% of the data here.
- Validation Set
- This is used only once to add another layer of unbiased performance to the one strategy you selected from the test set. While the performance of the test set was different from the data used to build the strategy, by choosing from multiple strategies, you are implementing a “selection bias” when using the best performing strategy. The validation set, which includes the final 20% of the data, helps remove this bias by showing you how well the best strategy by itself does over new, unseen data.
- It is very important to use this set only once or it can very easily become “in-sample”. If you aren’t satisfied with the performance over the validation set, you need to start back at square one with a new idea or build your strategy from scratch with completely new Training, Test, and Validation Sets.
Importance of Risk and Money Management
The impact of your risk and money management approach on your strategy cannot be understated. Not only will it help you avoid blowing out your account but it can actually turn an unprofitable strategy into a profitable one.
There are a couple of important points to consider when approaching the risk and money management aspects:
- Portfolio-wide approach
-
While you are building a strategy for only a single asset at a time, you need to consider its relationship to other strategies you may be trading.
-
Strategies on correlated assets could leave your account highly exposed to sudden price movements. It’s important to consider both how correlated the asset are as well as how correlated the strategies are when building your portfolio of strategies.
- Position sizing
- Position sizing is another area where traders tend to take an overly simplified approach.
- Even using a fixed percentage over a fixed lot approach can grow your account much more quickly. However, you need to be conscious that larger position sizes can work for and against you and can lead to quicker losses.
- Using a fixed percentage while keeping the maximum drawdown in check is a great way to maximize the returns while limiting your downside.
- Catastrophic stops
- While you can never predict “Black Swan Events”, you need to prepare yourself as best as you can.
- Even though stop losses are not guaranteed to get filled, having a plan in place for what to do in case of huge adverse price movement, even if it is to stay in and wait for a rebound, can be the difference between surviving to trade another day and blowing out your account.
Testing your strategy is an incredibly important step and if you are looking for more resources on evaluating your strategy, I covered the topic in more detail here.
3. Trade
So you’ve tested your strategy to best of your ability, you feel confident in your risk and money management and you are ready to trade live; congratulations but your work is just beginning!
Monitoring your strategy and knowing when it has fallen out of sync with the market is more difficult than it sounds but is very important.
- Comparing test results and live results
-
Luckily by using a validation set, we have a good idea of how well our strategy should perform in live trading assuming that the same market conditions have held.
-
If you are seeing drastically different results between your testing performance and live performance, it is a sign that market conditions have changed and the underlying assumptions of your strategy are no longer valid. In this case, it is best to stop trading until you have figured out what’s going wrong.
- Knowing when to start and stop trading
- A valuable step in the testing stage is to classify under what market conditions the strategy trades well and what conditions it trades poorly. By implementing even a basic volatility or trend filter, like an ATR or ADX, respectively, you can “turn on” your strategy in favorable conditions and turn it off in unfavorable conditions.
- Keeping an eye on trading costs
- While your broker may advertise “average” spreads of 0.2 pips, you may notice that when you actually enter into trades, the spread balloons up to 5 or 10 pips or you may not be getting the displayed fills. Download some historical data to a CSV, see what your actual transaction costs were and calculate the mean, min and max. You may be surprised how high they can be in certain market conditions.
-
Tracking the true trading costs of your strategy when it begins live trading can give you a sense of what your return per trade needs to be to at least break even.
Many traders will trade their strategy on a demo account or smaller live account as another check before going live on their full account. Even one or two weeks of live performance can help spot any mistakes in your strategy’s development process.
Building an algorithmic trading strategy is not an easy task but by clearly defining your goals, following a rigorous testing process, and closely monitoring its live performance you can greatly increase your chances of success.
At Inovance, we are focused on the idea and testing stage of this process. TRAIDE allows you to leverage machine-learning algorithms to uncover actual patterns and unbiased signals in the asset, and by exporting and testing on your trading platform, you can greatly decrease the chances that your own biases will lead to a strategy that doesn’t perform as well in live trading.
Happy TRAIDING!