Online selection rules: the second set: private API

PortfolioOptimisers.nonneg_quadratic_root — Function
nonneg_quadratic_root(a::Real, b::Real, c::Real) -> Any

Returns the largest non-negative root of $a \lambda^2 + b \lambda + c = 0$, or 0 when no root is real and non-negative.

Algorithm

  1. Set z, a zero of the type of a / b.
  2. When a is zero, the equation is the line $b \lambda + c = 0$. Return z when b is zero too, and otherwise the larger of z and -c / b.
  3. Compute the discriminant disc = b^2 - 4 * a * c. Return z when it is negative, because no root is real.
  4. Return the largest of z and the two roots (-b ± sqrt(disc)) / (2 * a).

Arguments

  • a: Coefficient of $\lambda^2$.
  • b: Coefficient of $\lambda$.
  • c: Constant term.

Returns

  • lambda::Real: The root, non-negative.

Related

source
PortfolioOptimisers.ConfidenceWeightedMeanReversionState — Type
struct ConfidenceWeightedMeanReversionState{__T_n, __T_sigma} <: AbstractPartialFitState

Carries the diagonal of the belief covariance over the weights, for the confidence weighted mean reversion rule.

ConfidenceWeightedMeanReversion seeds it and updates it once per period. The mean of the belief is the allocation held, so the carrier holds no mean.

Fields

  • n: Number of observations folded into the state.
  • sigma: The diagonal of $\Sigma_t$, the belief covariance over the weights, with one entry per asset. The update writes it in place. The seed is $1 / N^2$ per asset, and every step rescales it to the trace $1 / N$ of the seed.

Related

source
PortfolioOptimisers.lagged_window_correlation — Function
lagged_window_correlation(
    L1::AbstractMatrix,
    L2::AbstractMatrix
) -> Tuple{Any, Any}

Returns the lagged correlation of two consecutive windows of log price relatives, and the column means of the second window.

Entry (i, j) is the correlation of column i of L1 with column j of L2. The sample moments divide by the number of rows less one. An entry is zero when either column is constant. AntiCorrelation states the formula as $M_{\mathrm{cor}}$, and ranks the assets by the column means of the second window.

Arguments

  • L1: Log price relatives of the first window, rows × assets.
  • L2: Log price relatives of the second window, with the same size as L1.

Returns

  • (cor::AbstractMatrix, mu2::AbstractVector): The assets × assets lagged correlation, and the column means of L2.

Related

source
PortfolioOptimisers.anticorrelation_claims — Function
anticorrelation_claims(
    cor::AbstractMatrix,
    mu2::AbstractVector
) -> Any

Returns the claim matrix of an anti-correlation step.

Entry (i, j) is the claim of asset i on a transfer of its wealth to asset j. It is positive only when i differs from j, mu2[i] >= mu2[j], and cor[i, j] is positive. The negative diagonal entries of cor add to every claim of their asset. AntiCorrelation states the formula.

Arguments

Returns

  • claim::Matrix: The assets × assets claims, zero on the diagonal.

Related

source
PortfolioOptimisers.wealth_transfer — Function
wealth_transfer(
    w::AbstractVector,
    claim::AbstractMatrix
) -> Any

Returns the allocation after the transfers that a claim matrix names, from the wealth w held in each asset.

Each asset with a positive claim moves all of its wealth out, in proportion to its claims, and receives what the other assets move to it. The sum of the allocation stays the sum of w, and no asset gives more than it holds.

Arguments

Returns

  • q::AbstractVector: The allocation after the transfers.

Related

source
PortfolioOptimisers.ExpectationMaximisationState — Type
struct ExpectationMaximisationState{__T_n, __T_w1, __T_s} <: AbstractPartialFitState

Carries the Start Allocation and the statistic of the Learning-Rate Schedule, for the expectation-maximisation rule.

The online form of ExpectationMaximisation pulls towards the Start Allocation when its rate falls.

Fields

  • n: Number of observations folded into the state.
  • w1: Start Allocation $\boldsymbol{w}_1$, which the online form pulls towards.
  • s: Statistic of the Learning-Rate Schedule, or nothing for a fixed rate.

Related

source
PortfolioOptimisers.correction_ratio_cap — Function
correction_ratio_cap(eta::Real, t::Integer)
correction_ratio_cap(sched::AbstractLearningRateSchedule, t::Integer)

Returns the ceiling on the ratio $\eta_{t+1} / \eta_t$ in the online form of ExpectationMaximisation at period t.

The ceiling is one for a number and for every Learning-Rate Schedule that names no other, so the pull towards the Start Allocation comes from the fall of the rate alone. Under SelfConfidentRate it is $\sqrt{t / (t + 1)}$. That rate stays still while the mixture predicts well, and without the ceiling the weight of a bad predictor can decay exponentially. With the ceiling, no weight falls below $O(1 / t)$ of its start, so the mixture can still find an expert that becomes good late.

Arguments

  • eta: The eta field of the rule, a number or a Learning-Rate Schedule.
  • t: The period.

Returns

  • cap::Real: The ceiling, in $(0, 1]$.

Related

source
PortfolioOptimisers.CumulativeWealthState — Type
struct CumulativeWealthState{__T_n, __T_G, __T_p0} <: AbstractPartialFitState

Carries the cumulative log wealth of each asset and the Start Allocation, for the top-$k$ and weak aggregating weightings.

TopK and WeakAggregatingAlgorithm share it. On an ExpertMixture, each entry belongs to an expert and not to an asset.

Fields

  • n: Number of observations folded into the state.
  • G: Cumulative log wealth $\boldsymbol{G}_t = \sum_{s \leq t} \log \boldsymbol{x}_s$ of each asset. The update writes it in place.
  • p0: Start Allocation, the prior of the weak aggregating weights. TopK does not read it.

Related

source