Lesson 12 of 15
Slippage & Transaction Costs
Slippage & Transaction Costs
Real trading incurs costs that reduce profitability. Two major sources are:
Slippage
Slippage is the difference between the expected price and the actual execution price. When buying, you pay slightly more; when selling, you receive slightly less.
effective_price = price * (1 + direction * slippage)
direction = 1for a buy (price goes up slightly)direction = -1for a sell (price goes down slightly)
Net Return
After accounting for trading costs (spread, commission, etc.), the net return is simply:
net_return = gross_return - trade_cost_pct
Task
Implement:
apply_slippage(price, direction, slippage=0.001)— returns the effective execution pricenet_return(gross_return, trade_cost_pct)— returns the return after costs
Python runtime loading...
Loading...
Click "Run" to execute your code.