# Backtest

Backtesting is the process of applying a set of rules to historical data with the goal of assessing the strategy's effectiveness in generating profit.

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 curve, maximum gains/losses, average gain per winning trade, average loss per losing trade, maximum drawdown and much more. These metrics give you a comprehensive idea of your strategy performance before you deploy in the market.

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

The backtest page allows users to adjust and modify various input parameters which are used to run a backtest.

### Backtest Per Day¶

With Regular plan, you get a backtest count of 300 per day. With the Ultimate plan, you get a backtest count of 1000 per day. This backtest count depends on the number of instrument(s) added in a strategy.

Example

If a strategy has 1 scrip and you click on backtest, the count will reduce by 1. Likewise, if the strategy has 50 scrips and you click on backtest once then 50 counts of backtest will reduce. Overall you would have exhausted 51 counts till now. Hence if you are on an Ultimate plan, the backtest count will look like "949/1000", this means you now have 949 backtest left out of 1000 before your limit is reached for today

### Backtest Parameters¶

1. Position I would take allows you to decide whether you want to Buy or Sell the instrument. Do note for Dynamic Contract the Order Type setting set inside the contract will always supersede the position type selected here.

2. Charts - Here you have 3 options

A. Chart Type allows you to choose from Candle stick, Heikin Ashi and Renko. It is important to know Renko chart type is available only in Basic Create
B. Candle Interval is defined as the time frame of each candle. All backtest calculations are made using the close price of the selected candle interval.
C. Holding Type can be MIS or CNC/NRML and represents the holding type used to place hypothetical orders in a backtest. MIS is used for intra day margin trading, where the order will get squared off during the market close. CNC/NRML is used for overnight trading, where the stock/contract is held after the market closes and can be carried forward to the next day. If CNC/NRML has been selected as the holding type, CNC will be used as the holding type for equities and NRML for futures/options contracts based on the symbol and instrument segment.

3. Quanity represents the trading quantity to be used by the strategy. Quantity is a positive integer with defined absolute position size of an order, using which the strategy performs hypothetical trades during the backtest. After the backtest is run with a quantity, the same quantity value is used when the strategy is deployed. Here Quantity 1 = (1 Lot). Additionally, if strategy is in created in advanced mode, you can find Position Sizing parameters and the amount you'd want to allocate based on position sizing type selected.

4. Entry read a summary text of your entry condition and get an option to quickly change the entry start/stop time. ​

5. Exit read a summary text of your exit condition and have the ability to change TP SL types between Percentage, Points and Absolute (in create basic only percentage type).

6. Backtest parameters gives you the following 3 options

​A. Initial capital represents the hypothetical maximum capital allocated for a trade for each intrument. This capital does not represent any capital held by the user and is for backtest purposes only. Initial capital acts as the maximum capital that will be used by the system during a backtest to perform a hypothetical trade. ​While backtesting an entry will only be triggered when the notional value of the trade is less than the Initial capital + Cumulative Profit or Loss uptill previous trade
B. Backtest period is the look back period to perform a backtest and is defined by selecting the start and stop date for the backtest. 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 1 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 365 days. If the start date for the backtest is selected to be 1st Jan 2018, the maximum allowed end date for the backtest would be till 31st Dec 2018.
-- For a day candle interval, the maximum backtest period is five years. If the start date for the backtest is selected to be 1st Jan 2014, the allowed end date for the backtest would be till 1st Jan 2019.
-- These limits are subject to change based on the availability of data. The backtest period and the data fetched is also subjected to technical limitations such as bandwidth, data availability, server load and various or technical implications.
C. Daily Strategy Cycle indicates the number of hypothetical trades you'd like to take in the backtest period in a single day. This can be quite helpful for intraday strategies.

Important

Do note that the Daily Strategy Cycle parameter is only for backtesting and does not apply when you Deploy the strategy. While deploying the strategy you have to select the Strategy cycle parameter as per your requirement.

### Backtest Results1¶

On clicking the "Run Backtest" button, a fresh backtest is run for each instrument 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.

Note

If 5 scrips have been added and backtest is run, the counter will be updated as 5 backtests run and the count will be reduced. If no new equities/contracts have been added and backtest is run, the backtests are re-run on all the equities/contracts irrespective of its previous status. Every time you change a parameter mentioned above and run backtest, the backtest count reduces

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 strategy’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. P&L : The cumulative P&L realized after taking all the trades generated through the strategy.

2. Wins vs Losses (W vs L) : 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 stoploss/profit-target & average loss/losing trade v/s average gain/winnig 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 loss 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 result 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 entry 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.

#### Trigger Types:¶

• EN - Entry
• SL - Stop Loss
• TP - Target Profit
• SO - Square off
• EX - Exit condition
• TSL - Trailing Stop Loss
• EXP - Contract Expired

#### Brokerage Toggle¶

We account for all the deductions as per brokerage calculator on your broker's website. Brokerage charges include broker's brokerage, STT, transaction charges, GST and SEBI charges.

#### Backtest edit parameters¶

Provides a quick access to the backtest parameters. You can change most of the conditions including chart type, candle interval, SL,TP,TSL values.

#### Strategy details¶

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

#### Edit strategy¶

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

#### 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 strategy and no hypothetical trades were performed for the backtest period selected by the user. This could mean that the strategy 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 strategy 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.
1. 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 and we will allow few additional backtests.
2. 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 strategy. All backtest results are a hypothetical representation of the performance and returns on an strategy, based on certain underlying assumptions. These results do not provide any guarantee of future performance or returns, and all strategies are subjected to market risks.

### Deploy¶

The Deploy function allows users to take their strategy live in the stock market and get actionable alerts based on the entry and exit conditions in their strategy.

Once you deploy a strategy on Streak, you no longer have to track the trade manually. Streak tracks the price movements for trade signals and will send one click actionable alerts when all the conditions specified in a strategy are met in real-time.

On clicking the "Deploy" button on either Backtest or my strategy page, a popup is rendered with a summary of the user's selected scrips and quantity used while backtesting.

#### Deployment type¶

• Live Trading: Sends an actionable entry/exit notification once the strategy conditions are met.

• Paper Trading: Deploying your strategies in Paper-Trading mode allows user to check the performance of the strategy without risking any actual capital. This simulates trades in the live stock market, where you can track real-time positions based on virtual trades.

Info

When a strategy is deployed as Paper trading, notifications are not sent, when conditions are met.

#### Strategy live for¶

MIS positions are squared off and strategies are stopped after market close. This option allows user to deploy strategies for multiple trading session by deploying it once. If you select "3 Day", the strategy will be redeployed automatically by the system in the morning before market open, for the current day and the next two days. Applicable only for MIS deployments.

#### Strategy cycle¶

Strategy Cycle defines the loop of the strategy i.e entry followed by respective exit. The user should select the field "Strategy cycle" while deploying, which determines the cycles for which the strategy will be live. If you select the strategy cycle as 5 the strategy will move to a stopped state after completing the five cycles. Currently the maximum cycle that can be selected is 50.

#### Holding type¶

If "MIS" is selected, the holding type will be intraday and the strategy will be live for that single day (or depending on the 'Strategy Live for' parameter selected while deploying). If the user selects "CNC/NRML", the holding type will be CNC for equities and NRML for future contracts and the strategy will be live for the next 30 days in waiting state (or until the strategy is stopped by the user or terminated due to some reason such as order rejection or user subscription expires).

### 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 is 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) for all instruments being tested].
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 strategy 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 strategy will only exit a position, when either the exit condition is met or when target profit/stop loss price or trailed stoploss price is hit, or position is squared off for MIS holding type
5. During a backtest, there is no context nor is any consideration given to corporate actions such as stock splits, rights issues etc. and no adjustments are made to stock/contract prices. 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 entry/exit 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 are calculated on the TP SL % and the PNL chart values are calculated on the Close price of every candle when a position is held, not only on buy/sell.
8. During a backtest, if the holding type is MIS, all open positions are hypothetically squared off at the open price of the 3:15 pm candle (for equity) 4:30 (for currency). This is done to simulate a square off done by the brokers for MIS orders.
9. Chart data is subjected to minor variations from market time to post market times due to standard data adjustments.
10. Position sizing doesn't assume any margin requirements or leverage. It uses allocation and instrument price directly to calculate the order quantity. You should enter the allocation value such that margin requirements are being satisfied in your trading account for live trades. Margin calculation is done by the broker. To check the margin requirements, visit your brokers' website.
11. During a backtest, quantity freeze is not consisdered, that is, hypothetical trades will be executed even when the quantity is higher than Freeze quantity (maximum quantity for a buy/sell order set by the exchange).
12. During a backtest, when a long position is enterted, to track Trailing SL (TSL), the candle Sequence is assumed as O>>L>>H>>C i.e the Low is assumed to come first, followed by the High and the Close (OLHC)
13. During a backtest, when a short position is enterted, to track Trailing SL (TSL), the candle Sequence is assumed as O>>H>>L>>C i.e the High is assumed to come first, followed by the low and the Close (OHLC)
14. While backtesting an entry will only be triggered when the notional value (Trade price * Quantity) of the instrument is less than the 'Initial capital + Cumulative Profit or Loss uptill previous trade'.
15. While conducting a backtest, the system by default checks the SL/TP on the entry candle. The system primarily checks if the SL is breached first and then whether the TP is hit. In the event of both SL and TP being triggered in the same candle (due to the candle range being huge or the SL/TP values being very narrow), it is assumed that the SL was breached first.

1. Disclaimer: The results of all the backtest are hypothetical and does not guarantee or portray in any form or manner any future performance or returns. Historical data is subject to limitations like rounding off, memory buffer limits, user's browser, system limitation, data availability, accurate data etc