HAC log determinant: private API
Functions
PortfolioOptimisers.hac_log_det_path! — Function
hac_log_det_path!(
g::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
r::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
s::Number,
decay::Number,
hac_lags::Union{Integer, AbstractVector{<:Union{Number, AbstractJuMPScalar}}}
) -> Tuple{AbstractVector{<:Union{Number, AbstractJuMPScalar}}, AbstractVector{<:Union{Number, AbstractJuMPScalar}}}
Computes $\ln \det(I + s B)$ and its derivative in $s$ at one point, for each count of observations up to the length of g, where $B$ is the banded matrix $A / c$ of regime_bias_table.
The rows of the banded LDLᵀ factorisation of hac_ldl_taylor_row! carry each pivot with its derivative, so $\ln \det$ is the sum of the logs of the pivots, and its derivative the sum of $d_{m}' / d_{m}$. $B$ at one count is the leading block of $B$ at the next, so a pivot that is not positive marks that count and every larger one. At zero lags the buffers keep one row, which no lag reads, so the path is that of the plain weights.
Arguments
g::VecNum: Output: $\ln \det(I + s B)$ at each count, $\infty$ past the first pivot that is not positive (mutated).r::VecNum: Output: the derivative at each count, zero wheregis $\infty$ (mutated).s::Number: Point of the lattice.decay::Number: Decay of the weights.hac_lags::Union{Integer, VecNum}: Count of HAC lags, or the weight of each lag.
Returns
(g, r)::Tuple{VecNum, VecNum}: The filled vectors.
Related
PortfolioOptimisers.hac_log_det_peak — Function
hac_log_det_peak(
gh::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
rh::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
xf::AbstractRange,
decay::Number,
K::Integer,
hac_lags::Union{Integer, AbstractVector{<:Union{Number, AbstractJuMPScalar}}}
) -> Union{Nothing, Tuple{Any, Any}}
Finds the cut of the HAC transform of one count, the point $\sigma^{*}$ where $\ln \det(I + \sigma B)$ has its maximum, and the value there.
The derivative $\rho_{0}$ falls in $\sigma$, and it falls to $-\infty$ at the first zero of the determinant where $B$ has a negative eigenvalue. The lattice brackets its zero, and a bisection on the exact derivative of hac_log_det_slope finds it. A shift of the cut by one sixteenth in $\ln \sigma$ moves the factor of the first moment by 0.3 % at two assets, a half-life of 5 and five lags, so the step of the lattice is too coarse. The value at the cut is the lattice value below it plus the integral of the exact derivative, by the 4-point Gauss–Legendre rule.
Arguments
gh::VecNum: $\ln \det(I + \sigma B)$ on the lattice, $\infty$ past the zero of the determinant.rh::VecNum: Its derivative on the lattice.xf::AbstractRange: Lattice of $\ln \sigma$.decay::Number: Decay of the weights.K::Integer: Count of observations.hac_lags::Union{Integer, VecNum}: Count of HAC lags, or the weight of each lag.slope: In place ofdecay,Kandhac_lags, a function of $\sigma$ that gives the exact derivative, or a negative number past the first zero of the determinant. The first method reads it fromhac_log_det_slopeon the banded matrix.
Returns
peak::Option{<:Tuple{Number, Number}}: $(\sigma^{*}, \ln \det(I + \sigma^{*} B))$, ornothingwhere the derivative is positive on the whole lattice, because $B$ is positive definite.
Related
PortfolioOptimisers.hac_log_det_slope — Function
hac_log_det_slope(
decay::Number,
K::Integer,
t::Number,
hac_lags::Union{Integer, AbstractVector{<:Union{Number, AbstractJuMPScalar}}}
) -> Any
Computes the slope $\ell'(t)$ of $\ell(t) = \ln \det(I + t A)$ from the banded LDLᵀ factorisation of $I + t A$, with the first derivative in $t$ carried through it.
$\ell(t) = \sum_{m} \ln d_{m}(t)$ over the pivots, so $\ell' = \sum_{m} d_{m}' / d_{m}$. hac_log_det_peak bisects on it to find the cut of a HAC transform. A row whose diagonal $t\, c\, \lambda^{m}$ falls below the machine epsilon of decay times $1 - \lambda$ enters the sum as its weight, so the loop stops there and adds the remaining mass, as mahalanobis_bias_sums does.
Arguments
decay::Number: Decay of the weights.K::Integer: Count of observations in the estimate.t::Number: Argument of the log-determinant.hac_lags::Union{Integer, VecNum}: Count of HAC lags, or the weight of each lag.
Returns
slope::Option{<:Number}: $\ell'(t) = \sum_{k} \mu_{k} / (1 + t \mu_{k})$ over the eigenvalues $\mu$ of $A$, ornothingwhere $I + t A$ is not positive definite.
Related
PortfolioOptimisers.hac_ldl_taylor_row! — Function
hac_ldl_taylor_row!(
buf::NamedTuple,
ta::Number,
a::Number,
decay::Number,
p::Integer
) -> Any
Adds one row to the banded LDLᵀ factorisation of $I + t A$, with each entry carried as its value and its first derivative in $t$.
The entries of $I + t A$ are linear in $t$, so the diagonal of the row is $(1 + t a, a)$ and its entry at lag $i$ is $(t a_{i}, a_{i})$, with $a_{i} = k_{i}\, a / \lambda^{i}$. The recursion is that of hac_ldl_row!, in taylor_mul and taylor_div.
Arguments
buf::NamedTuple: Buffers of the factorisation (mutated):l[r, i], the entry of row $m - r$ at column $m - r - i$;d[r], the pivot of row $m - r$;row, scratch; andk, the weight $k_{i}$ of each lag, fromhac_lag_weights.ta::Number: $t\, c\, \lambda^{m}$, the diagonal of $t A$ in the row.a::Number: $c\, \lambda^{m}$, the diagonal of $A$ in the row.decay::Number: Decay of the weights.p::Integer: Count of lags that reach an observation of the estimate, $\min(L, m)$.
Returns
pivot::NTuple{2, <:Number}: The new pivot and its derivative.
Related
PortfolioOptimisers.gauss_legendre_rule — Function
gauss_legendre_rule(o::Number) -> NTuple{4, Tuple{Any, Any}}
Returns the nodes and weights of the 4-point Gauss–Legendre rule on $[-1, 1]$, in the number type of o.
Arguments
o::Number: One, in the number type of the rule.
Returns
rule::NTuple{4, <:Tuple{Number, Number}}: The pair of node and weight of each point.
Related