Fees
PortfolioOptimisers.FeesEstimator Type
struct FeesEstimator{T1, T2, T3, T4, T5, T6} <: AbstractEstimator
tn::T1
l::T2
s::T3
fl::T4
fs::T5
kwargs::T6
endEstimator for portfolio transaction fees constraints.
FeesEstimator specifies transaction fee constraints for each asset in a portfolio, including turnover fees, long/short proportional fees, and long/short fixed fees. Asset-specific fees can be provided via dictionaries, pairs, or vectors of pairs. Input validation ensures all fee inputs are non-empty and non-negative where applicable.
Fields
tn: Turnover estimator or result.l: Long proportional fees.s: Short proportional fees.fl: Long fixed fees.fs: Short fixed fees.kwargs: Named tuple of keyword arguments for rounding fixed fees calculation.
Constructor
FeesEstimator(; tn::Union{Nothing, <:TurnoverEstimator, <:Turnover} = nothing,
l::Union{Nothing, <:AbstractDict, <:Pair{<:AbstractString, <:Real},
<:AbstractVector{<:Pair{<:AbstractString, <:Real}}} = nothing,
s::Union{Nothing, <:AbstractDict, <:Pair{<:AbstractString, <:Real},
<:AbstractVector{<:Pair{<:AbstractString, <:Real}}} = nothing,
fl::Union{Nothing, <:AbstractDict, <:Pair{<:AbstractString, <:Real},
<:AbstractVector{<:Pair{<:AbstractString, <:Real}}} = nothing,
fs::Union{Nothing, <:AbstractDict, <:Pair{<:AbstractString, <:Real},
<:AbstractVector{<:Pair{<:AbstractString, <:Real}}} = nothing,
kwargs::NamedTuple = (; atol = 1e-8))Validation
l,s,fl,fsare validated withassert_nonneg_finite_val.
Examples
julia> FeesEstimator(; tn = TurnoverEstimator([0.2, 0.3, 0.5], Dict("A" => 0.1), 0.0),
l = Dict("A" => 0.001, "B" => 0.002), s = ["A" => 0.001, "B" => 0.002],
fl = Dict("A" => 5.0), fs = ["B" => 10.0])
FeesEstimator
tn ┼ TurnoverEstimator
│ w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
│ val ┼ Dict{String, Float64}: Dict("A" => 0.1)
│ default ┴ Float64: 0.0
l ┼ Dict{String, Float64}: Dict("B" => 0.002, "A" => 0.001)
s ┼ Vector{Pair{String, Float64}}: ["A" => 0.001, "B" => 0.002]
fl ┼ Dict{String, Float64}: Dict("A" => 5.0)
fs ┼ Vector{Pair{String, Float64}}: ["B" => 10.0]
kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)Related
sourcePortfolioOptimisers.Fees Type
struct Fees{T1, T2, T3, T4, T5, T6} <: AbstractResult
tn::T1
l::T2
s::T3
fl::T4
fs::T5
kwargs::T6
endContainer for portfolio transaction fee constraints.
Fees stores transaction fee constraints for each asset in a portfolio, including turnover fees, long/short proportional fees, and long/short fixed fees. Fee values can be specified as scalars (applied to all assets) or as vectors of per-asset values. Input validation ensures all fee values are non-negative and, if vectors, non-empty.
Fields
tn: Turnover constraint result.l: Long proportional fees.s: Short proportional fees.fl: Long fixed fees.fs: Short fixed fees.kwargs: Named tuple of keyword arguments for deciding how small an asset weight has to be before being considered negligible.
Constructor
Fees(; tn::Union{Nothing, <:Turnover} = nothing,
l::Union{Nothing, <:Real, <:AbstractVector{<:Real}} = nothing,
s::Union{Nothing, <:Real, <:AbstractVector{<:Real}} = nothing,
fl::Union{Nothing, <:Real, <:AbstractVector{<:Real}} = nothing,
fs::Union{Nothing, <:Real, <:AbstractVector{<:Real}} = nothing,
kwargs::NamedTuple = (; atol = 1e-8))Validation
l,s,fl,fsare validated withassert_nonneg_finite_val.
Examples
julia> Fees(; tn = Turnover([0.2, 0.3, 0.5], [0.1, 0.0, 0.0]), l = [0.001, 0.002, 0.0],
s = [0.001, 0.002, 0.0], fl = [5.0, 0.0, 0.0], fs = [0.0, 10.0, 0.0])
Fees
tn ┼ Turnover
│ w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
│ val ┴ Vector{Float64}: [0.1, 0.0, 0.0]
l ┼ Vector{Float64}: [0.001, 0.002, 0.0]
s ┼ Vector{Float64}: [0.001, 0.002, 0.0]
fl ┼ Vector{Float64}: [5.0, 0.0, 0.0]
fs ┼ Vector{Float64}: [0.0, 10.0, 0.0]
kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)Related
sourcePortfolioOptimisers.fees_constraints Function
fees_constraints(fees::FeesEstimator, sets::AssetSets; datatype::DataType = Float64,
strict::Bool = false)Generate portfolio transaction fee constraints from a FeesEstimator and asset set.
fees_constraints constructs a Fees object representing transaction fee constraints for the assets in sets, using the specifications in fees. Supports asset-specific turnover, long/short proportional fees, and long/short fixed fees via dictionaries, pairs, or vectors of pairs, with flexible assignment and validation.
Arguments
fees:FeesEstimatorspecifying turnover, proportional, and fixed fee values.sets:AssetSetscontaining asset names or indices.datatype: Output data type for fee values.strict: Iftrue, enforces strict matching between assets and fee values (throws error on mismatch); iffalse, issues a warning.
Returns
Fees: Object containing turnover, proportional, and fixed fee values aligned withsets.
Details
Fee values are extracted and mapped to assets using
estimator_to_val.If a fee value is missing for an asset, assigns zero unless
strictistrue.Turnover constraints are generated using
turnover_constraints.
Examples
julia> sets = AssetSets(; dict = Dict("nx" => ["A", "B", "C"]));
julia> fees = FeesEstimator(; tn = TurnoverEstimator([0.2, 0.3, 0.5], Dict("A" => 0.1), 0.0),
l = Dict("A" => 0.001, "B" => 0.002), s = ["A" => 0.001, "B" => 0.002],
fl = Dict("A" => 5.0), fs = ["B" => 10.0]);
julia> fees_constraints(fees, sets)
Fees
tn ┼ Turnover
│ w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
│ val ┴ Vector{Float64}: [0.1, 0.0, 0.0]
l ┼ Vector{Float64}: [0.001, 0.002, 0.0]
s ┼ Vector{Float64}: [0.001, 0.002, 0.0]
fl ┼ Vector{Float64}: [5.0, 0.0, 0.0]
fs ┼ Vector{Float64}: [0.0, 10.0, 0.0]
kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)Related
sourcefees_constraints(fees::Union{Nothing, <:Fees}, args...; kwargs...)Propagate or pass through portfolio transaction fee constraints.
fees_constraints returns the input Fees object or nothing unchanged. This method is used to propagate already constructed fee constraints or missing constraints, enabling composability and uniform interface handling in constraint generation workflows.
Arguments
fees: An existingFeesobject ornothing.args...: Additional positional arguments (ignored).kwargs...: Additional keyword arguments (ignored).
Returns
Feesornothing: The input constraint object, unchanged.
Examples
julia> fees = Fees(; tn = Turnover([0.2, 0.3, 0.5], [0.1, 0.0, 0.0]), l = [0.001, 0.002, 0.0]);
julia> fees_constraints(fees)
Fees
tn ┼ Turnover
│ w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
│ val ┴ Vector{Float64}: [0.1, 0.0, 0.0]
l ┼ Vector{Float64}: [0.001, 0.002, 0.0]
s ┼ nothing
fl ┼ nothing
fs ┼ nothing
kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)
julia> fees_constraints(nothing)Related
sourcePortfolioOptimisers.calc_fees Function
calc_fees(w::AbstractVector, p::AbstractVector, ::Nothing, ::Function)
calc_fees(w::AbstractVector, p::AbstractVector, fees::Real, op::Function)
calc_fees(w::AbstractVector, p::AbstractVector, fees::AbstractVector{<:Real}, op::Function)Compute the actual proportional fees for portfolio weights and prices.
Arguments
w: Portfolio weights.p: Asset prices.fees: Scalar fee value.nothing: No proportional fee, returns zero.Real: Single fee applied to all relevant assets.AbstractVector{<:Real}: Vector of fee values per asset.
op: Function to select assets,.>=for long,<for short (ignored iffeesisnothing).
Returns
val::Real: Total actual proportional fee.
Examples
julia> calc_fees([0.1, 0.2], [100, 200], 0.01, .>=)
0.5Related
sourcecalc_fees(w::AbstractVector, p::AbstractVector, ::Nothing)
calc_fees(w::AbstractVector, p::AbstractVector, tn::Turnover)Compute the actual turnover fees for portfolio weights and prices.
Arguments
w: Portfolio weights.p: Asset prices.tn: Turnover structure.nothing: No turnover fee, returns zero.tn.val::Real: single turnover fee applied to all assets.tn.val::AbstractVector{<:Real}: vector of turnover fees per asset.
Returns
val::Real: Actual turnover fee.
Examples
julia> calc_fees([0.1, 0.2], [100, 200], Turnover([0.0, 0.0], 0.01))
0.5Related
sourcecalc_fees(w::AbstractVector, p::AbstractVector, fees::Fees)Compute total actual fees for portfolio weights and prices.
Sums actual proportional, fixed, and turnover fees for all assets.
Arguments
w: Portfolio weights.p: Asset prices.fees:Feesstructure.
Returns
val::Real: Total actual fees.
Examples
julia> fees = Fees(; l = [0.01, 0.02], s = [0.01, 0.02], fl = [5.0, 0.0], fs = [0.0, 10.0]);
julia> calc_fees([0.1, -0.2], [100, 200], fees)
15.9Related
sourcecalc_fees(w::AbstractVector, ::Nothing, ::Function)
calc_fees(w::AbstractVector, fees::Real, op::Function)
calc_fees(w::AbstractVector, fees::AbstractVector{<:Real}, op::Function)Compute the proportional fees for portfolio weights and prices.
Arguments
w: Portfolio weights.fees: Scalar fee value.nothing: No proportional fee, returns zero.Real: Single fee applied to all relevant assets.AbstractVector{<:Real}: Vector of fee values per asset.
op: Function to select assets,.>=for long,<for short (ignored iffeesisnothing).
Returns
val::Real: Total proportional fee.
Examples
julia> calc_fees([0.1, 0.2], 0.01, .>=)
0.003Related
sourcecalc_fees(w::AbstractVector, ::Nothing)
calc_fees(w::AbstractVector, tn::Turnover)Compute the turnover fees for portfolio weights and prices.
Arguments
w: Portfolio weights.tn: Turnover structure.nothing: No turnover fee, returns zero.tn.val::Real: single turnover fee applied to all assets.tn.val::AbstractVector{<:Real}: vector of turnover fees per asset.
Returns
val::Real: Turnover fee.
Examples
julia> calc_fees([0.1, 0.2], Turnover([0.0, 0.0], 0.01))
0.003Related
sourcecalc_fees(w::AbstractVector, fees::Fees)Compute total fees for portfolio weights and prices.
Sums proportional, fixed, and turnover fees for all assets.
Arguments
w: Portfolio weights.p: Asset prices.fees:Feesstructure.
Returns
val::Real: Total fees.
Examples
julia> fees = Fees(; l = [0.01, 0.02], s = [0.01, 0.02], fl = [5.0, 0.0], fs = [0.0, 10.0]);
julia> calc_fees([0.1, -0.2], fees)
15.004999999999999Related
sourcePortfolioOptimisers.calc_fixed_fees Function
calc_fixed_fees(w::AbstractVector, ::Nothing, kwargs::NamedTuple, ::Function)
calc_fixed_fees(w::AbstractVector, fees::Real, kwargs::NamedTuple, op::Function)
calc_fixed_fees(w::AbstractVector, fees::AbstractVector{<:Real}, kwargs::NamedTuple,
op::Function)Compute the fixed portfolio fees for assets that have been allocated.
Arguments
w: Portfolio weights.fees: Scalar fee value.nothing: No proportional fee, returns zero.Real: Single fee applied to all relevant assets.AbstractVector{<:Real}: Vector of fee values per asset.
kwargs: Named tuple of keyword arguments for deciding how small an asset weight has to be before being considered negligible.op: Function to select assets,.>=for long,<for short (ignored iffeesisnothing).
Returns
val::Real: Total fixed fee.
Examples
julia> calc_fixed_fees([0.1, 0.2], 0.01, (; atol = 1e-6), .>=)
0.02Related
sourcePortfolioOptimisers.calc_asset_fees Function
calc_asset_fees(w::AbstractVector, p::AbstractVector, ::Nothing, ::Function)
calc_asset_fees(w::AbstractVector, p::AbstractVector, fees::Real, op::Function)
calc_asset_fees(w::AbstractVector, p::AbstractVector, fees::AbstractVector{<:Real},
op::Function)Compute the actual proportional per asset fees for portfolio weights and prices.
Arguments
w: Portfolio weights.p: Asset prices.fees: Scalar fee value.nothing: No proportional fee, returns zero.Real: Single fee applied to all relevant assets.AbstractVector{<:Real}: Vector of fee values per asset.
op: Function to select assets,.>=for long,<for short (ignored iffeesisnothing).
Returns
val::AbstractVector{<:Real}: Total actual proportional per asset fee.
Examples
julia> calc_asset_fees([0.1, 0.2], [100, 200], 0.01, .>=)
2-element Vector{Float64}:
0.1
0.4Related
sourcecalc_asset_fees(w::AbstractVector, p::AbstractVector, ::Nothing)
calc_asset_fees(w::AbstractVector, p::AbstractVector, tn::Turnover)Compute the actual per asset turnover fees for portfolio weights and prices.
Arguments
w: Portfolio weights.p: Asset prices.tn: Turnover structure.nothing: No turnover fee, returns zero.tn.val::Real: single turnover fee applied to all assets.tn.val::AbstractVector{<:Real}: vector of turnover fees per asset.
Returns
val::Vector{<:Real}: Actual per asset turnover fee.
Examples
julia> calc_asset_fees([0.1, 0.2], [100, 200], Turnover([0.0, 0.0], 0.01))
2-element Vector{Float64}:
0.1
0.4Related
sourcecalc_asset_fees(w::AbstractVector, p::AbstractVector, fees::Fees)Compute total actual per asset fees for portfolio weights and prices.
Sums actual proportional, fixed, and turnover fees for all assets.
Arguments
w: Portfolio weights.p: Asset prices.fees:Feesstructure.
Returns
val::Vector{<:Real}: Total actual per asset fees.
Examples
julia> fees = Fees(; l = [0.01, 0.02], s = [0.01, 0.02], fl = [5.0, 0.0], fs = [0.0, 10.0]);
julia> calc_asset_fees([0.1, -0.2], [100, 200], fees)
2-element Vector{Float64}:
5.1
10.8Related
sourcecalc_asset_fees(w::AbstractVector, ::Nothing, ::Function)
calc_asset_fees(w::AbstractVector, fees::Real, op::Function)
calc_asset_fees(w::AbstractVector, fees::AbstractVector{<:Real}, op::Function)Compute the proportional per asset fees for portfolio weights and prices.
Arguments
w: Portfolio weights.fees: Scalar fee value.nothing: No proportional fee, returns zero.Real: Single fee applied to all relevant assets.AbstractVector{<:Real}: Vector of fee values per asset.
op: Function to select assets,.>=for long,<for short (ignored iffeesisnothing).
Returns
val::Vector{<:Real}: Total proportional per asset fee.
Examples
julia> calc_asset_fees([0.1, 0.2], 0.01, .>=)
2-element Vector{Float64}:
0.001
0.002Related
sourcecalc_asset_fees(w::AbstractVector, ::Nothing)
calc_asset_fees(w::AbstractVector, tn::Turnover)Compute the per asset turnover fees for portfolio weights and prices.
Arguments
w: Portfolio weights.tn: Turnover structure.nothing: No turnover fee, returns zero.tn.val::Real: single turnover fee applied to all assets.tn.val::AbstractVector{<:Real}: vector of turnover fees per asset.
Returns
val::Vector{<:Real}: Per asset turnover fee.
Examples
julia> calc_asset_fees([0.1, 0.2], Turnover([0.0, 0.0], 0.01))
2-element Vector{Float64}:
0.001
0.002Related
sourcecalc_asset_fees(w::AbstractVector, fees::Fees)Compute total per asset fees for portfolio weights and prices.
Sums proportional, fixed, and turnover fees for all assets.
Arguments
w: Portfolio weights.p: Asset prices.fees:Feesstructure.
Returns
val::Vector{<:Real}: Total per asset fees.
Examples
julia> fees = Fees(; l = [0.01, 0.02], s = [0.01, 0.02], fl = [5.0, 0.0], fs = [0.0, 10.0]);
julia> calc_asset_fees([0.1, -0.2], fees)
2-element Vector{Float64}:
5.001
10.004Related
sourcePortfolioOptimisers.calc_asset_fixed_fees Function
calc_asset_fixed_fees(w::AbstractVector, ::Nothing, kwargs::NamedTuple, ::Function)
calc_asset_fixed_fees(w::AbstractVector, fees::Real, kwargs::NamedTuple, op::Function)
calc_asset_fixed_fees(w::AbstractVector, fees::AbstractVector{<:Real}, kwargs::NamedTuple,
op::Function)Compute the per asset fixed portfolio fees for assets that have been allocated.
Arguments
w: Portfolio weights.fees: Scalar fee value.nothing: No proportional fee, returns zero.Real: Single fee applied to all relevant assets.AbstractVector{<:Real}: Vector of fee values per asset.
kwargs: Named tuple of keyword arguments for deciding how small an asset weight has to be before being considered negligible.op: Function to select assets,.>=for long,<for short (ignored iffeesisnothing).
Returns
val::Vector{<:Real}: Total per asset fixed fee.
Examples
julia> calc_asset_fixed_fees([0.1, 0.2], 0.01, (; atol = 1e-6), .>=)
2-element Vector{Float64}:
0.01
0.01Related
sourcePortfolioOptimisers.calc_net_returns Function
calc_net_returns(w::AbstractVector, X::AbstractMatrix, args...)
calc_net_returns(w::AbstractVector, X::AbstractMatrix, fees::Fees)Compute the net portfolio returns. If fees is provided, it deducts the calculated fees from the gross returns.
Returns the portfolio returns as the product of the asset return matrix X and portfolio weights w.
Arguments
w: Portfolio weights.X: Asset return matrix (assets × periods).fees:Feesstructure.args...: Additional arguments (ignored).
Returns
Vector{<:Real}: Portfolio net returns.
Examples
julia> calc_net_returns([0.5, 0.5], [0.01 0.02; 0.03 0.04])
2-element Vector{Float64}:
0.015
0.035Related
sourcePortfolioOptimisers.calc_net_asset_returns Function
calc_net_asset_returns(w::AbstractVector, X::AbstractMatrix, args...)
calc_net_asset_returns(w::AbstractVector, X::AbstractMatrix, fees::Fees)Compute the per asset net portfolio returns. If fees is provided, it deducts the calculated fees from the gross returns.
Returns the portfolio returns as the product of the asset return matrix X and portfolio weights w.
Arguments
w: Portfolio weights.X: Asset return matrix (assets × periods).fees:Feesstructure.args...: Additional arguments (ignored).
Returns
Matrix{<:Real}: Per asset portfolio net returns.
Examples
julia> calc_net_asset_returns([0.5, 0.5], [0.01 0.02; 0.03 0.04])
2×2 Matrix{Float64}:
0.005 0.01
0.015 0.02Related
source