Composite price-level statistics: private API

PortfolioOptimisers.elastic_net_path — Function
elastic_net_path(
    path::ElasticNetPath,
    P::AbstractMatrix,
    y::AbstractVector
) -> Any

Returns the coefficients of the elastic net of y on the columns of P at the middle point of the path, by cyclic coordinate descent from zero.

ElasticNetPath states the objective and the middle point. The function solves the middle point alone. The problem has as many columns as the window has levels, so it does not need the rest of the path as warm starts.

Mathematical definition

The minimiser of the objective over one coefficient, with the others fixed, is

\[\begin{align} z_k &= \frac{S\left(\mathbf{P}_k^\intercal \boldsymbol{r}_k,\ \gamma \vartheta\right)}{\lVert \mathbf{P}_k \rVert^2 + \gamma (1 - \vartheta)}\,,\quad S(v, a) = \operatorname{sign}(v) \max(\lvert v \rvert - a, 0)\,. \end{align}\]

Where:

  • $\boldsymbol{z}$: Coefficients of the elastic net, one per column of $\mathbf{P}$. Coefficient $k$ is $z_k$.
  • $\mathbf{P}$: Regressors of the elastic net, one row per observation and one column per regressor. Column $k$ is $\mathbf{P}_k$.
  • $\boldsymbol{r}_k$: Residual of the response $\boldsymbol{y}$ without the term of column $k$.
  • $S$: Soft threshold.
  • $\gamma$: Regularisation strength of the elastic net. Here it is the strength at the middle point of the path.
  • $\vartheta$: Share of the $L_1$ penalty in the elastic net, the theta field of ElasticNetPath.

Algorithm

  1. Compute g, the product of each column with y, and lmax, the smallest strength at which every coefficient is zero. When lmax is zero, return zero coefficients.
  2. Take lam, the strength at the middle point, the threshold a of the soft threshold, and den, the denominator of each coordinate update.
  3. Start from the coefficients z at zero and the residual r equal to y.
  4. Sweep the columns in order. For each column k, compute rho, the product of the column with the residual without its own term, and apply the coordinate update, which gives znew. Update r, and record delta, the largest change of a coefficient in the sweep.
  5. Try the exact solve of elastic_net_polish on the sign pattern of z. When it gives the optimum, return it.
  6. Repeat steps 4 and 5 until delta is below tol or iters sweeps have run, and then return z.

Arguments

  • path: The path.
  • P: The regressors, observations × columns.
  • y: The response, observations × 1.

Returns

  • z::Vector: The coefficients, columns × 1.

Related

source
PortfolioOptimisers.elastic_net_polish — Function
elastic_net_polish(
    P::AbstractMatrix,
    y::AbstractVector,
    z::AbstractVector,
    lam::Real,
    theta::Real
) -> Any

Returns the exact elastic-net optimum on the sign pattern of z when that pattern is the pattern of the optimum, and nothing otherwise.

A point that meets the optimality conditions below minimises the objective of ElasticNetPath, because the objective is convex. For theta < 1 the objective is strictly convex, and the point is its only minimiser. At theta = 1 the objective is the lasso, and it can have more than one minimiser. Then the equations of the active columns are singular when the pattern holds more columns than there are observations, and the function returns nothing for such a pattern.

Mathematical definition

With $\mathcal{A}$ the nonzero coefficients of $\boldsymbol{z}$, the optimum on its sign pattern $\boldsymbol{s}$ solves

\[\begin{align} \left(\mathbf{P}_{\mathcal{A}}^\intercal \mathbf{P}_{\mathcal{A}} + \gamma (1 - \vartheta) \mathbf{I}\right) \boldsymbol{z}_{\mathcal{A}} &= \mathbf{P}_{\mathcal{A}}^\intercal \boldsymbol{y} - \gamma \vartheta\, \boldsymbol{s}\,, \end{align}\]

and it is the optimum of the objective when

\[\begin{align} \operatorname{sign}(\boldsymbol{z}_{\mathcal{A}}) &= \boldsymbol{s}\,,\\ \lvert \mathbf{P}_k^\intercal (\boldsymbol{y} - \mathbf{P}_{\mathcal{A}} \boldsymbol{z}_{\mathcal{A}}) \rvert &\leq \gamma \vartheta\,,\quad k \notin \mathcal{A}\,. \end{align}\]

Where:

  • $\mathcal{A}$: Active set, the columns whose coefficient in $\boldsymbol{z}$ is nonzero.
  • $\mathbf{P}_{\mathcal{A}}$, $\boldsymbol{z}_{\mathcal{A}}$: Columns of the regressors and coefficients of the active set.
  • $\boldsymbol{s}$: Signs of the coefficients of the active set in $\boldsymbol{z}$.
  • $\boldsymbol{z}$: Coefficients of the elastic net, one per column of $\mathbf{P}$. Coefficient $k$ is $z_k$.
  • $\mathbf{P}$: Regressors of the elastic net, one row per observation and one column per regressor. Column $k$ is $\mathbf{P}_k$.
  • $\boldsymbol{y}$: Response of the elastic net, one entry per observation.
  • $\gamma$: Regularisation strength of the elastic net.
  • $\vartheta$: Share of the $L_1$ penalty in the elastic net, the theta field of ElasticNetPath.

Algorithm

  1. Find A, the nonzero coefficients of z. When A is empty, return nothing.
  2. Take s, the signs of the coefficients of A, and factorise the matrix of the equations of the active columns, which gives F. When the matrix is singular, return nothing.
  3. Solve the equations with F, which gives zA. When a coefficient of zA does not keep its sign in s, return nothing.
  4. Write zA into zp, zero elsewhere, and compute corr, the product of each column with the residual.
  5. When an inactive column has abs(corr[k]) > lam * theta, return nothing. Otherwise return zp.

Arguments

  • P: The regressors, observations × columns.
  • y: The response.
  • z: The coefficients whose sign pattern the function tries.
  • lam: The regularisation strength.
  • theta: The share of the $L_1$ penalty.

Returns

  • z'::Union{Nothing, Vector}: The optimum, or nothing.

Related

source
PortfolioOptimisers.trend_reverting_fraction — Function
trend_reverting_fraction(P::AbstractMatrix) -> Any

Returns the trend-reverting fraction of a matrix of levels, the share of the interior levels, over every asset, at which the path turns.

A level turns when its two neighbours are both above it or both below it, so the path rises and then falls there, or falls and then rises. A matrix of $L$ levels and $N$ assets has $(L - 2) N$ interior levels. The fraction is zero below three levels. KernelTrendPattern states it as $\lambda_{t+1}$, after eq. (27) of the kernel trend pattern paper of Lai, Yang, Wu and Fang (2018).

Arguments

  • P: The levels, levels × assets.

Returns

  • lambda::Real: The fraction, in [0, 1], in the element type of the levels or a wider one.

Related

source