ProportionalCostΒΆ

Defined in fynance.backtest

class ProportionalCost(fee=0.0, slippage=0.0)[source]

Bases: object

Proportional transaction cost: (fee + slippage) * turnover.

Turnover at each step is the absolute traded weight \(\sum_i |w_{t,i} - w_{t-1,i}|\) (the first step charges the initial position). Conforms to CostModel.

Parameters:
feefloat

Proportional fee per unit traded (e.g. 0.001 = 10 bps).

slippagefloat

Additional proportional slippage per unit traded.

Examples

>>> import numpy as np
>>> cost = ProportionalCost(fee=0.01)
>>> cost(np.array([[1.0, 0.0], [0.5, 0.5], [0.5, 0.5]]))
array([0.01, 0.01, 0.  ])
__call__(weights)[source]

Return the per-step proportional cost of a weight book.