# Backtested Trading Strategy

**URL:** <https://community.aliceblueonline.com/t/backtested-trading-strategy/7536>\
**Category:** Educational insights\
**Created:** [September 6, 2023, 6:29am UTC](https://community.aliceblueonline.com/t/backtested-trading-strategy/7536 "2023-09-06T06:29:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreelekshmi\_pk](https://sea1.discourse-cdn.com/flex015/user_avatar/community.aliceblueonline.com/sreelekshmi_pk/32/3734_2.png) [@sreelekshmi\_pk](https://community.aliceblueonline.com/u/sreelekshmi_pk)\
**Post date:** [September 6, 2023, 6:29am UTC](https://community.aliceblueonline.com/t/backtested-trading-strategy/7536/1 "2023-09-06T06:29:06Z")

</div>

How do transaction costs impact the performance of a backtested trading strategy in the Indian stock market? Can you guide on accounting for these while backtesting?

---

<div class="post-metadata">

**Author:** ![Rakshitha\_M](https://sea1.discourse-cdn.com/flex015/user_avatar/community.aliceblueonline.com/rakshitha_m/32/3614_2.png) [@Rakshitha\_M](https://community.aliceblueonline.com/u/Rakshitha_M)\
**Post date:** [September 6, 2023, 7:16am UTC](https://community.aliceblueonline.com/t/backtested-trading-strategy/7536/2 "2023-09-06T07:16:26Z")

</div>

Absolutely! Transaction costs can significantly impact the outcome of a backtested trading strategy, often making a seemingly profitable strategy a loss-making one. Especially in markets like India, where brokerage, STT (Securities Transaction Tax), and other charges play a role, considering these costs is crucial.

**1. Types of Transaction Costs:**  
Brokerage: Fees paid to the broker for executing trades. Can be a fixed amount or a percentage of trade value.  
STT (Securities Transaction Tax): Tax levied on the sale and purchase of securities.  
Exchange Transaction Charges: Charges by exchanges like NSE or BSE.  
GST: Goods and Service Tax on brokerage and exchange transaction charges.  
Other Costs: Includes stamp duty, SEBI turnover fees, etc.

**2. Accounting for Transaction Costs in Backtesting:**  
While backtesting, it’s essential to simulate as close to reality as possible. Let’s illustrate with a hypothetical example:  
Consider you’re backtesting on daily data and have 100 buy and sell signals in a year.  
Let’s assume your average transaction cost (including all charges) is 0.05% of the traded volume.  
If, on average, you trade ₹100,000 on each signal, your total cost per trade is ₹50.  
For 200 trades (100 buys and 100 sells), your total transaction cost in a year would be ₹10,000.

**3. Integrating into Backtest Code (Python Example):**  
#Assuming nifty\_data dataframe from previous example  
TRANSACTION\_COST\_RATE = 0.0005

nifty\_data[‘Gross\_Return’] = nifty\_data[‘Close’] / nifty\_data[‘Close’].shift(1)  
nifty\_data[‘Net\_Return’] = np.where(nifty\_data[‘Signal’].diff() != 0,  
nifty\_data[‘Gross\_Return’] - TRANSACTION\_COST\_RATE,  
nifty\_data[‘Gross\_Return’])

nifty\_data[‘Strategy\_Net\_Return’] = nifty\_data[‘Signal’].shift(1) \* nifty\_data[‘Net\_Return’]

**4. Impact:**  
For strategies with higher trading frequency, transaction costs become even more critical.  
Transaction costs can turn high-frequency strategies unprofitable if not accounted for.

**5. Tips:**  
Always optimize and test strategies with transaction costs included. A strategy that doesn’t account for them is incomplete.  
Consider brokerages that offer low transaction costs if your strategy involves frequent trading.

**6. Stats (Hypothetical):**

| Metrics | Strategy (w/o Costs) | Strategy (w/ Costs) |
| --- | --- | --- |
| CAGR | 15% | 12% |
| Sharpe Ratio | 1.3 | 1.1 |
| Max Drawdown | 8% | 9% |

The table above depicts the substantial difference in results when transaction costs are considered.  
Note: Always be vigilant of hidden costs. Understanding them is not just vital for backtesting but also when you’re trading live.  
Remember, it’s not just about making profits; it’s about keeping them!
