# Backtest

#### Introduction¶

Backtesting is the process of applying a set of rules to historical data to assess the strategy's effectiveness before risking any actual capital in the market.

Streak has the most powerful backtesting engine in the world that generates performance metrics for multiple stocks in a single click.

The backtest results include Profit and Loss(PnL) curve, maximum gains/losses, avg gain per winning trade, avg loss per losing trade, maximum drawdown (Max DD) and much more. These metrics give you a comprehensive idea of your algo’s performance before you deploy it in the market.

After you create an algo and click on run backtest, the system starts checking for all the signals that got generated during the selected time period for that algo

#### Backtest Parameters¶

• Initial capital represents the hypothetical maximum capital allocated for the backtest of each equity/crypto pair/future contract. This capital does not represent any capital held by the user and is used for backtest purposes only. Initial capital acts as the maximum capital that will be used by the algo during the backtest.
• Quantity represents the trading quantity to be used by the algo. Quantity is a positive integer with defined absolute position size of an order, using which the algo performs hypothetical trades during the backtest. After the backtest is run with a quantity, the same quantity value is used when the algo is deployed.

• Stop loss percentage is the value used to calculate the stop loss level once the hypothetical entry position has been taken. An exit trigger is generated if the price hits/crosses the calculated stop loss price and the positions will be hypothetically exited at the close price of the subsequent candle.

• Target profit percentage is the value used by algo to calculate the target profit price once the hypothetical entry position has been taken. An exit trigger is generated if the price hits/crosses the calculated target profit price and the positions will be hypothetically exited at the close price of the subsequent candle.
• Candle Interval is defined as the time frame of each candle interval. All backtest calculations are made using the Close price of the selected candle interval.
• Backtest period is the lookback period to perform a backtest and is defined by selecting the start and stop date for the backtest. The Backtest period can be modified to re-run backtests i.e users can change the start and end date of the backtest period but the period range is limited based on the candle interval.
• For a min candle interval, the maximum backtest period is 30 days from the start date. If the start date for the backtest is selected to be 1st Jan 2019, the allowed end date for the backtest would be till 30th Jan 2019.
• For (3-30) min candle interval, the maximum backtest period is 90 days from the start date. If the start date for the backtest is selected to be 1st Jan 2019, the allowed end date for the backtest would be till 31st March 2019.
• For an hour candle interval, the maximum backtest period is 1 year from the start date. If the start date for the backtest is selected to be 1st Jan 2019, the allowed end date for the backtest would be till 1st Jan 2020.
• For a day candle interval, the maximum backtest period is 5 years from the start date.
• These limits are subject to change based on the availability of data. The backtest period is also subjected to technical limitations such as bandwidth, server load, and various other technical implications.
• Equities/Crypto pairs/Future contracts can be added/removed on the backtest page. Backtests are run individually for every equity/crypto pair/contract that has been added and therefore the backtest counter is updated to reflect this.

Backtest Count

If 5 cryptos/stocks are selected in the Create strategy page and the backtest in run on the 5 scrips. The system will count this as 5 backtest and 5 tests out of the daily available limit will be used. IF the backtest is re-run without adding any new scrips, 5 backtest will be counted by the system, irrespective of its previous status. Every time you change a backtest parameter and run the backtest, 5 backtest will be counted by the system, in the above scenario.

### Backtest Results¶

On clicking the "Run Backtest" button, a fresh backtest is run for each in by first fetching all the appropriate historical market data for the respective instrument and initializing all the user-defined parameters. The historical market data is then processed to generate hypothetical trade signals and hypothetical trades are performed using the hypothetical initial capital.

Based on these hypothetical trades, certain performance metrics such as hypothetical profit/loss, winning streak, losing streak, etc. are generated to provide a generalized and simplified understanding of the algo’s hypothetical returns and risk. All the hypothetical trades generated are shown in the transactions table along with profit/loss and portfolio values during every trade.

1. Backtest P&L: The cumulative P&L realized after taking all the trades generated through the algo.

2. Wins vs Losses: Displays the number of trades that ended up being profitable and the ones that weren’t. This important piece of information can help you decide whether your Risk/Reward ratio based on stop loss/profit-target & average loss/losing trade v/s average gain/winning trade is favorable or not.

3. Winning Streak (WS): The highest number of subsequent winning trades, one after another.

4. Losing Streak (LS): The highest number of subsequent losing trades, one after another.

5. Max Drawdown (Max DD): Max drawdown measures the largest decline in the P&L curve at any given point of time.

##### More on Maximum drawdown¶

Maximum drawdown (Max DD) is the maximum loss from the peak (highest point) to a trough (lowest point) of a PnL chart before a new peak is attained. It signifies downside risk and is calculated by measuring the highest fall (largest loss) in over a specified time period.

Max DD = \frac{Peak - Trough}{Peak}

It is important to note that Max DD only measures the size of the largest loss among all the losses during a period. It does not consider the frequency of losses.

A max dd of 0.97 is better than 1.53. Similarly, a max dd of -0.12 is better than -0.93. The lower the value, the better. It should ideally as close to 0 as possible. If a strategy never made a loss-making trade, the Max DD would be zero.

#### Transaction details¶

Streak's backtest results also allow user to see the trade details (entry/exit) based on which the backtest PnL and other metrics are calculated. You can find these specific entries and exit date and time by clicking on "Transaction Details".

Transaction details will list the date and time of entry along with the entry price followed by the date and time of exit and also the profit or loss on the transaction.

#### Algo details¶

You can view the strategy summary on the top of the backtest page.

Edit parameters: This option provides quick access to the backtest parameters. You can change most of the conditions including chart type, candle interval, Stop Loss & Target Profit percentage.

Edit: Algos can be modified from the backtest page also by clicking on algo name then clicking Edit in the strategy summary section.

#### Trigger Types:¶

• EN - Entry
• SL - Stop Loss
• TP - Target Profit
• SO - Square off
• EX - Exit condition

#### Backtest error messages¶

During a backtest, if any error occurs/proper results are not be generated, we try to show an appropriate message to help the user adjust the input parameters and run the backtest again. These error messages are explained below:

1. No trades happened - This means that no hypothetical entry signals were generated for the algo and no hypothetical trades were performed for the backtest period selected by the user. This could mean that the algo conditions were never met in the specified backtest period or that the conditions were syntactically/logically incorrect or were not expressed properly with the right indicator parameters.
2. No trades happened because initial capital is low - This means that the algo conditions were met and trading signals were generated but due to insufficient hypothetical initial capital, hypothetical trades were not generated. It can be resolved by increasing the hypothetical initial capital or by decreasing the quantity and running the backtest again.
3. Limit Exceeded - This means while running backtest you have reached your daily maximum allowed backtest limit. This limit may vary depending on your subscription plan.
4. Error while fetching data - This means that an internal error occurred while fetching historical data. It can be resolved by waiting for a few minutes and running the backtest again. If the backtest counter gets decreased, you can write to us (support@streak.world) and we will allow a few additional backtests.
5. Server timed out - This means that the user's browser is not able to connect to Streak servers due to internet connection error. It can be resolved by checking the internet connection and running the backtest again.

Info

Backtesting on Streak: Backtesting on Streak allows users to measure the hypothetical performance or returns of an algo. All backtest results are a hypothetical representation of the performance and returns on an algo, based on certain underlying assumptions. These results do not provide any guarantee of future performance or returns, and all algos are subjected to market risks. The backtest page allows users to adjust and modify various input parameters that are used to run a backtest.

Deploy All:

Deploy allows users to take their algos live in the exchange and get actionable alerts based on the entry and exit conditions in their algo.

On clicking the "Deploy" button on either Backtest or My Algos page, a popup is rendered with a summary of the user's algo with the entry condition, exit condition, and candle interval. The user should also select the field "Algo cycle", which determines the number of loops for which the algo will be live and our systems will track the market movements.

Algo cycle defines the loop of the algo ie. An entry followed by respective exit.

Deployment Type: If Notification is selected, the platform will send an actionable notification based on the entry and exit conditions in their algo. If Auto Trading is selected, the platform will automatically execute orders, when entry and exit conditions are met. For simulation, you can select Paper Trading.

Order Type: Limit orders are only executed at a specified price or better. Market orders execute the orders at the current market price (at any price). Post Only Orders are Limit Orders that are only accepted if they do not immediately execute (market maker orders). Market makers use Post Only Orders to only submit passive orders to earn the Maker rebate.

Algo Cycle: The algo cycle determines the number of times an algo will take an entry and its respective exit. Algo cycle defines the loop of the algo: Trade Entry followed by respective exit. For 1 cycle, the algo will trigger one Entry followed by an Exit after which it will stop automatically. Maximum cycles allowed is 5.

### Backtest assumptions¶

During a backtest, hypothetical trades are generated with the following high-level assumptions:

1. During a backtest, irrespective of the order type, no margins as assumed for any instrument. The user must enter the desired initial capital value such that it is higher than the product of quantity and the instruments close price (initial capital >= (quantity x close price)).
2. During a backtest, any hypothetical signal to buy or sell is executed on the open price of the next candle irrespective of the actual volumes traded for that candle in the historical data.
3. During a backtest, no form of averaging is done i.e., the algo does not take multiple consecutive entry positions before exiting the current position (entry position is taken only after the previous position has been exited i.e. when quantity at hand is zero).
4. During a backtest, the algo only exists when either the exit condition is met or when the target profit price or stop-loss price is hit.
5. The values OHLCV (Open, High, Low, Close and Volume) are taken directly as present in the historical candle data.
6. During a backtest, a hypothetical buy signal is generated only if the condition is false in the previous candle and is true in the current candle.
7. During a backtest, the profit/loss and the PNL chart values are calculated on the Close price of every candle when a position is held.
8. Chart data is subjected to minor variations from market time to post-market times due to standard data adjustments.

#### DISCLAIMER¶

Backtesting is the process of testing a trading strategy on relevant historical data to ensure its viability before the trader risks any actual capital. A trader can simulate the strategy and analyze the results.

On clicking the "Run Backtest" button, a fresh backtest is run for each equity/contract by first fetching all the appropriate historical market data for the respective stock/contract and initializing all the user-defined parameters. The historical market data is then processed to generate hypothetical trade signals and hypothetical trades are performed using the hypothetical initial capital.

Based on these hypothetical trades, certain performance metrics such as hypothetical profit/loss, winning streak, losing streak, etc. are generated in an effort to provide a generalized and simplified understanding of the algo’s hypothetical returns and risk. All the hypothetical trades generated are shown in the transactions table along with profit/loss and portfolio values during every trade.

The results of all the backtest are hypothetical and do not guarantee or portray in any form or manner any future performance or returns. The backtest results are a hypothetical representation of algos performance and do not provide any guarantee to accuracy in data and are subject to limitations like rounding off, memory buffer limits, user's browser, system limitation, data availability, accurate data, etc.