multiticker / core /taxes.py
Jitendra12421's picture
Upload folder using huggingface_hub
8fe2df2 verified
Raw
History Blame Contribute Delete
1.75 kB
"""
Tax, brokerage, and slippage calculator for Indian equity intraday trades.
Covers: brokerage (flat Rs 20), STT, exchange txn charge, GST, SEBI fee, stamp duty.
"""
def calculate_taxes_and_slippage(
price_0930, price_1510, qty,
high_0930, low_0930, high_1510, low_1510,
is_short,
):
"""
Compute net PnL after realistic slippage and all Indian regulatory charges.
Slippage model: 10% of the 1-min candle's (high - low) range,
applied as an adverse fill on both entry and exit.
Returns
-------
(net_pnl, total_taxes, exec_buy_price, exec_sell_price)
"""
slip_0930 = (high_0930 - low_0930) * 0.10
slip_1510 = (high_1510 - low_1510) * 0.10
if not is_short:
# LONG: Buy at 09:30 (ask penalty), Sell at 15:10 (bid penalty)
actual_buy_price = price_0930 + slip_0930
actual_sell_price = price_1510 - slip_1510
else:
# SHORT: Sell at 09:30 (bid penalty), Buy-to-cover at 15:10 (ask penalty)
actual_sell_price = price_0930 - slip_0930
actual_buy_price = price_1510 + slip_1510
buy_turnover = actual_buy_price * qty
sell_turnover = actual_sell_price * qty
total_turnover = buy_turnover + sell_turnover
brokerage = 20.0
stt = sell_turnover * 0.00025
exc_txn_charge = total_turnover * 0.0000325
gst = (brokerage + exc_txn_charge) * 0.18
sebi_fee = total_turnover * 0.000001
stamp_duty = buy_turnover * 0.00003
total_taxes = brokerage + stt + exc_txn_charge + gst + sebi_fee + stamp_duty
gross_pnl = (actual_sell_price - actual_buy_price) * qty
net_pnl = gross_pnl - total_taxes
return net_pnl, total_taxes, actual_buy_price, actual_sell_price