MarketImpactCostΒΆ

Defined in fynance.backtest

class MarketImpactCost(fee=0.0, impact=0.0, exponent=1.5)[source]

Bases: object

Non-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). With exponent=1 and impact=0 it reduces to ProportionalCost. Conforms to CostModel.

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 (> 1 is super-linear). Default 1.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.