MarketImpactCostΒΆ
Defined in fynance.backtest
- class MarketImpactCost(fee=0.0, impact=0.0, exponent=1.5)[source]
Bases:
objectNon-linear market-impact cost: linear fee + convex impact term.
Charges, per step, a proportional fee plus a super-linear market-impact term on the same turnover (the standard square-root impact law, where the cost grows faster than the trade size):
\[c_t = fee \cdot \tau_t + impact \cdot \tau_t^{\,exponent}\]where the turnover \(\tau_t = \sum_i |w_{t,i} - w_{t-1,i}|\) is defined exactly as in
ProportionalCost(the first step charges the initial position). Withexponent=1andimpact=0it reduces toProportionalCost. Conforms toCostModel.- Parameters:
- feefloat
Proportional (linear) fee per unit traded (e.g.
0.001= 10 bps).- impactfloat
Coefficient of the convex impact term, in the same units as
fee.- exponentfloat
Convexity exponent of the impact term (
> 1is super-linear). Default1.5(the square-root impact law: cost per unit traded grows as \(\sqrt{\tau}\)).
Examples
>>> import numpy as np >>> cost = MarketImpactCost(fee=0.0, impact=0.1, exponent=2.0) >>> cost(np.array([[1.0, 0.0], [0.0, 1.0], [0.0, 1.0]])) array([0.1, 0.4, 0. ])
- __call__(weights)[source]
Return the per-step (linear + convex impact) cost of a weight book.