transaction_costΒΆ

Defined in fynance.portfolio.sizing

transaction_cost(weights, fee=0.001, axis=0)[source]

Per-step transaction cost from weight turnover.

Cost at each step is fee times the traded amount (turnover): \(c_t = fee \\cdot \\sum_i |w_{t,i} - w_{t-1,i}|\), with the first step charging the initial position.

Parameters:
weightsarray_like

Portfolio weights over time, shape (T,) or (T, n_assets).

feefloat, optional

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

axis{0, 1}, optional

Time axis. Default 0.

Returns:
np.ndarray

Cost per step, shape (T,).

Examples

>>> import numpy as np
>>> w = np.array([[1.0, 0.0], [0.5, 0.5], [0.5, 0.5]])
>>> transaction_cost(w, fee=0.01)
array([0.01, 0.01, 0.  ])