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?
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!