Algo Trading: Backtesting — Part 2
Hopefully, it was pretty cool writing your first algorithm strategy in Arcade, but now what? We need to backtest the strategy created in Part 1 of this series to see if we had any luck with other large-cap stocks.
So, let’s get started.
In the Strategy panel, find the strategy you created and click the button “Test” to be redirected to the backtesting page. (Note: you can also backtest patterns, which we will cover in another part of this series.)
Since it’s the first time you’re executing a test, you can’t copy the configuration from a previous test, so we’re going to create a new one. Just press “Ok” on the following popup:
Backtesting has a lot of available settings to ensure accuracy, but for our first run, we’re going to leave the defaults for pretty much all of them.
For our backtest, we need to change just a few things:
- In the Test Configuration area, type “1000” in the “Last X days from today” field in the Main Test Settings panel (the default is 60). Each year has about 252 trading days, so 1000 days is about 4 years of testing:
2. The “Max Investing per Trade” is the amount the robot will use to buy stocks for each trade. We can put a fixed amount of money in US$, an expression, or simply a percentage of the total amount available. For our test, let’s leave the default “5%”. Diversification is good, so we shouldn’t invest in 1 or a few stocks. Using 5% lets us invest in about 20 stocks at the same time.
3. Jump to the “Universe” section in the Strategy Detail Settings area. A Universe is just a set of stocks. You can have multiple universes like “Large Cap Stocks” which collects all the stocks with Market Cap > $200B or “Natural Gas” with some of the ETFs like UGAZ and DGAZ. Having pre-defined universes is useful because you don’t need to select every single symbol needed, just select the Universe.
Since this is our first time, let’s skip the creation of a Universe and handpick the stocks we’re interested in. In the Universe panel of the Strategy Settings, click on the “+” button on the right of the page to expand the universe panel:
Then you should see this:
Now click on the “+ Add More…” button and the symbol picker popup will open:
Enter “200,000,000,000” in the first Market Cap field and then click “Search”. All the symbols with a minimum market cap of $200B should be returned as a result:
Nice! Now click on the “Select all” button and then “+ Add & Close” to add all the selected stocks into the strategy settings. You should see all the selected symbols as below:
That’s it, we’re done setting up the testing. We’re going to leave all the other options untouched for now. Note the estimated cost of the test in Arcade Tokens. For every year of testing, at the “Day” level, the cost is only 1 Arcade Token. Example: 1000 days are about 4 years = 4 Arcade Tokens.
With all the subscriptions, there is a specific number of included tokens you can use that reset every week. With the Free subscription, you have 50 tokens per week which means you can test up to 50 years with a Day level test. Not bad, huh?
4. The last step is to kick off the backtest by clicking the red “Run” button.
You should see the notification that the test has been scheduled on the top right of your screen. Testing 4 years back should take less than 2 minutes. After clicking on “Run!” you’re redirected to the “Trading Record” tab that shows the summary of the results on the right, the chart with the profit on the left, and the table of the details at the bottom.
Check the backtest results
Check the results: $19K profit on $27K initial balance is the 70% cumulative profit (about 23%/year). Not bad for our first strategy, especially because for the same period, the S&P 500 made only 39.81%.
You can scroll the table with all the trading days, click on a particular day and you’ll see the details for the daily trading. This is the result of clicking on June 12th, 2020, which is the last day of the test when all the stocks are sold.
You can check all the details of the trade. Check out the column “Reason In” that contains the output of our strategy. Nice that we put the actual values of wma-150 and wma-200 in the beginTrading() function.
Also, in the profit column, you can see the minimum and maximum profit reached. The trade closed at +15.093%, but it reached a maximum of +28.158% on Feb 12, 2020! In this case, it was because of the crash after the COVID-19 pandemic-special-event (practically impossible to forecast), but the strategy could have sold these stocks during or right after the crash. This means that, perhaps, there is room for improving our strategy by selecting a better time to sell?
As an algo trader, this is the mentality you should always keep: develop, test, and maximize the results of your strategies.
If you click on the traded symbol, like “NVS”, you will see the entire trade on the candlestick chart:
That’s all folks for the 2nd part of the tutorial. We’ve learned the following things:
- How to backtest a strategy.
- How to read and research the results.
- Your first test of a strategy is just the beginning. There is always room for improvement.
On Part 3, we’re going to explore the other, more advanced, backtesting options before switching to Live Trading.
Have fun with algorithms,
The Arcade Team
Disclaimer: This article is for academic purposes only. The author is not suggesting using a particular strategy or providing any financial advice. For more information, check our risk disclaimer.