How to Backtest a Trading Strategy Even if You Can't Code
5 years, 11 months ago · 26855 views
Updated 5 September 2026 by PyInvesting. This revision reflects the current backtest builder.
You can backtest a trading strategy without writing code by specifying its universe, entry or ranking rule, portfolio size and rebalance schedule in a visual builder. The useful output is a record of how that rule behaved under stated assumptions, including its drawdowns and comparison with a benchmark.
This walkthrough uses PyInvesting's relative strength builder. You choose the rules in the browser; you do not need to install Python or supply code. Sign in to use the builder and check your plan's access before running.
Start with a rule you can explain
Here is an educational example to enter and review, not a tested recommendation: rank a small, fixed set of broad-market ETFs by their six-month return, allow only funds above a 200-day simple moving average, hold the top two eligible funds and rebalance monthly. A fixed list keeps the exercise understandable; it does not reproduce historical index membership.
| Input | Example |
|---|---|
| Universe | SPY, EFA, EEM, IWM and QQQ; verify each fund's identity and available history |
| Comparison benchmark | SPY, in USD |
| Moving average | Simple, 200 periods |
| Ranking signal | 6 Month Returns, Highest, weight 100; remove other signals |
| Number of stocks | 2 (the builder uses this label for the number of selected instruments) |
| Rebalance frequency | Monthly |
| Advanced settings | Leverage 1; record the rebalance band; leave Cash Allocation off for this exercise |
These settings are an input worksheet. This article does not claim a return, drawdown or successful execution for the example. The eligible history depends on data coverage and the current execution rules; record the actual start and end dates reported in your completed result.
Build the backtest in five steps
- Select the strategy universe. Open Select your instruments and search for each intended fund. Review the selected instruments and remove any defaults you do not want. Use the ETF directory or US stock directory to check instruments first.
- Set Comparison benchmarks. Choose a market reference that matches the question. The current builder accepts up to three. A different currency, geographic exposure or risk level can make an apparent comparison misleading.
- Define the screen and ranking. Set the moving average type and period, then the selected signals, ranking directions and weights. For this example retain only 6 Month Returns. The inputs describe different decisions: the moving average determines eligibility; the ranking orders eligible candidates.
- Review portfolio assumptions. Set the number of holdings, frequency, currency and a recognizable Backtest Name. Expand Advanced settings to inspect the rebalance band, leverage and cash-allocation option. Save the configuration before submitting.
- Run and wait for a completed result. Select Run Backtest once. Follow the result's progress and any actionable data or validation message. A queued, loading or failed result is not evidence that the strategy succeeded. Review the saved parameters alongside the completed result.
Read more than the headline return
Compare the strategy and benchmark over the same available dates. Examine the path of the portfolio, annual returns, volatility and maximum drawdown where shown. Maximum drawdown measures the largest peak-to-trough fall within the observed period; a later recovery does not remove that loss or the time needed to recover.
Look for concentration in one instrument, one market regime or one unusually good year. Check turnover and the trade record where available. A result that depends on a few dates deserves more scrutiny than a smooth summary statistic suggests.
Make costs and data limitations explicit
Do not assume a result includes your broker's commissions, bid–ask spread, slippage, taxes, fund expenses or cash interest. Check the assumptions the result actually reports. If a cost is not modeled, document it separately and test whether a reasonable allowance would change the conclusion. A 0.10% cost on $10,000 traded is $10 per trade leg; a sale followed by a purchase can involve two legs.
Price adjustment, dividends, currency conversion, missing observations and the start dates of funds affect comparisons. Selecting today's surviving stocks or funds can introduce survivorship and selection bias. Historical accounting signals also need information-availability dates to avoid using facts before investors could have known them.
Keep an untouched period for evaluation
Write down the rule before inspecting the result. Use one period to develop the idea and a separate, later period to evaluate it where the available workflow permits. If you compare many parameter combinations and keep only the winner, you have also selected for luck. Record the alternatives you tried, then check nearby reasonable settings without treating the best historical number as a forecast.
Save enough detail to reproduce the comparison
Keep the selected instruments, benchmark, signals and weights, moving-average settings, holdings limit, frequency, rebalance band, leverage, cash rule, currency, run date, actual result dates and all reported data/cost assumptions. Record later revisions as new experiments. This makes a backtest useful even when it rejects your original idea.
For a separate example of translating market breadth into a rule, read the worked breadth allocation example. To inspect the live breadth measure itself, open the PyInvesting Fear & Greed Index.