Asset turnover
The turnover is used to measure the absolute weight change between the current weights and benchmark weights. They can be used to compute fees, or as a constraint. It can also be used as a risk measure, but we will detail that use in Risk Measures
PortfolioOptimisers.TurnoverEstimator Type
struct TurnoverEstimator{__T_w, __T_val, __T_dval, __T_fixed} <: AbstractEstimatorEstimator for turnover portfolio constraints.
TurnoverEstimator specifies turnover constraints for each asset in a portfolio, based on current portfolio weights w, asset-specific turnover values val, and a default value for assets not explicitly specified. Supports asset-specific turnover via dictionaries, pairs, or vectors of pairs.
This estimator can be converted into a concrete Turnover constraint using the turnover_constraints function, which maps the estimator's specifications to the assets in a given AssetSets object.
Fields
w: Current portfolio weights vector.val: Default value to use for the estimator. Ifnothing, the estimator provides the default value.dval: Default value for assets not specified inval.fixed: Whether the estimator is fixed and does not update with new weights.
Constructors
TurnoverEstimator(;
w::VecNum,
val::EstValType,
dval::Option{<:Number} = nothing,
fixed::Bool = false
) -> TurnoverEstimatorValidation
wis validated withassert_nonempty_finite_val.valis validated withassert_nonempty_nonneg_finite_val.dval, if notnothing,dval >= 0.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
w: Sliced to the selected indices viaport_opt_view.val: Sliced to the selected indices viaport_opt_view.
Examples
julia> TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2), dval = 0.0)
TurnoverEstimator
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┼ Float64: 0.0
fixed ┴ Bool: falseRelated
sourcePortfolioOptimisers.Turnover Type
struct Turnover{__T_w, __T_val, __T_fixed} <: AbstractResultContainer for turnover portfolio constraints.
Turnover stores the portfolio weights and turnover constraint values for each asset. The turnover constraint can be specified as a scalar (applied to all assets) or as a vector of per-asset values.
Mathematical definition
Where:
: N × 1turnover vector.: N × 1vector of current portfolio weights.: N × 1vector of benchmark portfolio weights.: Element-wise absolute value.
Fields
w: Current portfolio weights vector.val: Default value to use for the estimator. Ifnothing, the estimator provides the default value.fixed: Whether the estimator is fixed and does not update with new weights.
Constructors
Turnover(;
w::VecNum,
val::Num_VecNum = 0.0,
fixed::Bool = false
) -> TurnoverKeywords correspond to the struct's fields.
Validation
!isempty(w).val:AbstractVector:!isempty(val),length(w) == length(val),any(isfinite, val),all(x -> x >= 0, val).Number:isfinite(val)andval >= 0.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
w: Sliced to the selected indices viaport_opt_view.val: Sliced to the selected indices viaport_opt_view.
Examples
julia> Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0])
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: false
julia> Turnover(; w = [0.2, 0.3, 0.5], val = 0.02, fixed = true)
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Float64: 0.02
fixed ┴ Bool: trueRelated
PortfolioOptimisers.factory Method
factory(tn::Turnover, w::VecNum)Create a new Turnover constraint with updated portfolio weights.
factory constructs a new Turnover object using the provided portfolio weights w and the turnover values from an existing Turnover constraint tn.
Arguments
tn: ExistingTurnoverconstraint object.w: New portfolio weights vector.
Returns
tn::Turnover: New constraint object with updated weights and original turnover values.
Examples
julia> tn = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0])
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: false
julia> factory(tn, [0.0, 0.2, 0.8])
Turnover
w ┼ Vector{Float64}: [0.0, 0.2, 0.8]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: false
julia> tn = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0], fixed = true)
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: true
julia> factory(tn, [0.0, 0.2, 0.8])
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: trueRelated
sourcePortfolioOptimisers.factory Method
factory(tn::TurnoverEstimator, w::VecNum)Create a new TurnoverEstimator with updated portfolio weights.
Constructs a new TurnoverEstimator object using the provided portfolio weights w and the turnover values and default value from an existing TurnoverEstimator tn.
Arguments
tn: ExistingTurnoverEstimatorobject. Supplies turnover values and default value.w: New portfolio weights vector.
Returns
tn::TurnoverEstimator: New estimator object with the same values and default but updated weights.
Validation
wis validated to be non-empty, finite, and numeric.
Examples
julia> tn = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2),
dval = 0.0)
TurnoverEstimator
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┼ Float64: 0.0
fixed ┴ Bool: false
julia> factory(tn, [0.1, 0.4, 0.5])
TurnoverEstimator
w ┼ Vector{Float64}: [0.1, 0.4, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┼ Float64: 0.0
fixed ┴ Bool: false
julia> tn = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2),
dval = 0.0, fixed = true)
TurnoverEstimator
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┼ Float64: 0.0
fixed ┴ Bool: true
julia> factory(tn, [0.1, 0.4, 0.5])
TurnoverEstimator
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┼ Float64: 0.0
fixed ┴ Bool: trueRelated
sourcePortfolioOptimisers.factory Method
factory(tn::VecTnE_Tn, w::VecNum)Create new turnover constraints or estimators with updated portfolio weights.
Applies factory to each element in tn, constructing a new collection of turnover constraints or estimators with the provided portfolio weights w.
Arguments
tn: Vector of turnover constraints or estimators.w: New portfolio weights vector.
Returns
res::VecTnE_Tn: Vector of updated turnover constraints or estimators.
Examples
julia> tn1 = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0]);
julia> tn2 = Turnover(; w = [0.2, 0.3, 0.5], val = [0.05, 0.1, 0.0]);
julia> factory([tn1, tn2], [0.1, 0.4, 0.5])
2-element Vector{Turnover{Vector{Float64}, Vector{Float64}, Bool}}:
Turnover
w ┼ Vector{Float64}: [0.1, 0.4, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: false
Turnover
w ┼ Vector{Float64}: [0.1, 0.4, 0.5]
val ┼ Vector{Float64}: [0.05, 0.1, 0.0]
fixed ┴ Bool: falseRelated
PortfolioOptimisers.turnover_constraints Function
turnover_constraints(tn::TurnoverEstimator, sets::AssetSets; datatype::DataType = Float64,
strict::Bool = false)Generate turnover portfolio constraints from a TurnoverEstimator and asset set.
turnover_constraints constructs a Turnover object representing turnover constraints for the assets in sets, using the specifications in tn. Supports scalar, vector, dictionary, pair, or custom turnover types for flexible assignment and validation.
Arguments
tn:TurnoverEstimatorspecifying current weights, asset-specific turnover values, and default value.sets:AssetSetscontaining asset names or indices.datatype: Data type for default turnover values whendvalisnothing.strict: Iftrue, enforces strict matching between assets and turnover values (throws error on mismatch); iffalse, issues a warning.
Returns
tn::Turnover: Object containing portfolio weights and turnover values aligned withsets.
Details
- Turnover values are extracted and mapped to assets using
estimator_to_val.
Examples
julia> sets = AssetSets(; dict = Dict("nx" => ["A", "B", "C"]));
julia> tn = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2));
julia> turnover_constraints(tn, sets)
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: falseRelated
sourceturnover_constraints(tn::Option{<:Turnover}, args...; kwargs...)Propagate or pass through turnover portfolio constraints.
turnover_constraints returns the input Turnover object unchanged or nothing. This method is used to propagate already constructed turnover constraints, enabling composability and uniform interface handling in constraint generation workflows.
Arguments
tn: An existingTurnoverobject.args...: Additional positional arguments (ignored).kwargs...: Additional keyword arguments (ignored).
Returns
tn::Option{<:Turnover}: The input constraint object, unchanged.
Examples
julia> tn = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0]);
julia> turnover_constraints(tn)
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: falseRelated
sourceturnover_constraints(tn::VecTnE_Tn, sets::AssetSets; datatype::DataType = Float64,
strict::Bool = false)Broadcasts turnover_constraints over the vector.
Provides a uniform interface for processing multiple constraint estimators simultaneously.
Arguments
tn: Vector of turnover constraints or estimators.sets:AssetSetscontaining asset names or indices.datatype: Data type for default turnover values whendvalisnothing.strict: Iftrue, enforces strict matching between assets and turnover values (throws error on mismatch); iffalse, issues a warning.
Returns
res::VecTn: Vector of constructed turnover constraints.
Examples
julia> sets = AssetSets(; dict = Dict("nx" => ["A", "B", "C"]));
julia> tn1 = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2));
julia> tn2 = TurnoverEstimator(; w = [0.1, 0.4, 0.5], val = Dict("B" => 0.15, "C" => 0.3));
julia> turnover_constraints([tn1, tn2], sets)
2-element Vector{Turnover{Vector{Float64}, Vector{Float64}, Bool}}:
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Vector{Float64}: [0.1, 0.2, 0.0]
fixed ┴ Bool: false
Turnover
w ┼ Vector{Float64}: [0.1, 0.4, 0.5]
val ┼ Vector{Float64}: [0.0, 0.15, 0.3]
fixed ┴ Bool: falseRelated
sourcePortfolioOptimisers.port_opt_view Method
port_opt_view(tn::VecTnE_Tn, i)Create views of multiple turnover constraints or estimators for a subset of assets.
port_opt_view returns a vector of turnover constraint or estimator objects, each restricted to the indices or assets specified by i.
Arguments
tn: Vector of turnover constraints or estimators.i: Index or indices specifying the subset of assets.
Returns
res::VecTnE_Tn: Vector of turnover constraint or estimator objects, each restricted to the specified subset.
Details
Applies
port_opt_viewto each element intn.Supports both
TurnoverandTurnoverEstimatortypes.Enables composable and uniform processing of asset subsets for batch turnover constraints.
Examples
julia> tn1 = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0], fixed = true);
julia> tn2 = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2),
dval = 0.0, fixed = true);
julia> PortfolioOptimisers.port_opt_view(concrete_typed_array([tn1, tn2]), 1:2)
2-element Vector{Union{Turnover{SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, Bool}, TurnoverEstimator{SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, Dict{String, Float64}, Float64, Bool}}}:
Turnover
w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.2, 0.3]
val ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.1, 0.2]
fixed ┴ Bool: true
TurnoverEstimator
w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.2, 0.3]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┼ Float64: 0.0
fixed ┴ Bool: trueRelated
sourcePortfolioOptimisers.TnE_Tn Type
const TnE_Tn = Union{<:Turnover, <:TurnoverEstimator}Alias for a turnover constraint or estimator.
Represents either a constructed turnover constraint or a turnover constraint estimator. Used for flexible dispatch in turnover constraint generation and processing.
Related
sourcePortfolioOptimisers.VecTnE_Tn Type
const VecTnE_Tn = AbstractVector{<:TnE_Tn}Alias for a vector of turnover constraints or estimators.
Represents a collection of turnover constraints or estimators, enabling batch processing and broadcasting of turnover constraint generation.
Related
sourcePortfolioOptimisers.VecTn Type
const VecTn = AbstractVector{<:Turnover}Alias for a vector of turnover constraints.
Represents a collection of constructed turnover constraints for multiple portfolios or assets.
Related
sourcePortfolioOptimisers.Tn_VecTn Type
const Tn_VecTn = Union{<:Turnover, <:VecTn}Alias for a single turnover constraint or a vector of turnover constraints.
Enables flexible dispatch for functions that accept either a single turnover constraint or multiple constraints.
Related
sourcePortfolioOptimisers.TnE_Tn_VecTnE_Tn Type
const TnE_Tn_VecTnE_Tn = Union{<:TnE_Tn, <:VecTnE_Tn}Alias for a single turnover constraint/estimator or a vector of them.
Supports flexible dispatch for turnover constraint generation and processing, accepting either a single constraint/estimator or a collection.
Related
sourcePortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(tn::TnE_Tn) -> Bool
needs_previous_weights(tn::VecTnE_Tn) -> BoolCheck if a turnover constraint or estimator requires previous portfolio weights.
Arguments
tn: Turnover constraint or estimator.
Returns
Bool:trueif previous weights are needed,falseotherwise.
Related
source