Higher-Moment Partial Fit

The incremental fit of the third and fourth co-moments. partial_fit! folds a block of observations into the state an estimator carries, and coskewness and cokurtosis read the answer out of it. Only the FullMoment arm of each estimator takes part, because SemiMoment clips against a centre that a new observation moves.

Functions

PortfolioOptimisers.port_opt_viewMethod
port_opt_view(
    x::CoskewnessPartialFitState,
    i,
    args...
) -> CoskewnessPartialFitState

Slices a CoskewnessPartialFitState to the selected assets.

A third co-moment reads three assets' observations and no fourth, so the sub-tensor over a subset of assets is the state of that subset, entry for entry, and the count passes through. M3 is assets × assets², and its column for the pair $(p, q)$ is $(p - 1) N + q$, so the slice keeps the rows i and the columns of every pair drawn from i. fourth_moment_index_generator builds that column set, in the order the sliced universe numbers its own pairs.

The slice copies by index and does not view, so a later partial_fit! on the viewed estimator writes into arrays of its own. The copy is small: a cluster's sub-tensor is cubic in the cluster size, where the full one is cubic in the universe size.

Arguments

  • x: The state to slice.
  • i: Index or indices of the assets to keep.
  • args...: Additional positional arguments (ignored).

Returns

  • state::CoskewnessPartialFitState: The state of the same sample over the selected assets.

Related

source
PortfolioOptimisers.port_opt_viewMethod
port_opt_view(
    x::CokurtosisPartialFitState,
    i,
    args...
) -> CokurtosisPartialFitState

Slices a CokurtosisPartialFitState to the selected assets.

A fourth co-moment reads four assets' observations and no fifth, so the sub-tensor over a subset of assets is the state of that subset, entry for entry, and the count passes through. M4 is assets² × assets², and both of its axes are numbered by the pair $(p, q)$ at $(p - 1) N + q$, so the slice keeps the columns of every pair drawn from i on both axes. M3 keeps the rows i and the same column set.

The slice copies by index and does not view, so a later partial_fit! on the viewed estimator writes into arrays of its own. The copy is small next to the state it comes from: a cluster's sub-tensor is quartic in the cluster size, so ten clusters of ten assets copy 80 KB each out of the 800 MB a hundred-asset state holds.

Arguments

  • x: The state to slice.
  • i: Index or indices of the assets to keep.
  • args...: Additional positional arguments (ignored).

Returns

  • state::CokurtosisPartialFitState: The state of the same sample over the selected assets.

Related

source
PortfolioOptimisers.partial_fitMethod
partial_fit(
    ske::Coskewness{<:Any, <:Any, <:FullMoment},
    args...;
    kwargs...
) -> Any

Coskewness method of partial_fit. Forwards to partial_fit!, because the fold already writes into no array of the state it was given.

This is the one family that overrides the generic method. The generic method copies the state before it folds, and a copy is what gives the verb its value semantics. This family's fold reaches merge_states, which reads the two states and builds a third, so the estimator handed over is already left as it was and the copy buys nothing.

Algorithm

  1. Forward X and every keyword to partial_fit!, and return the estimator it gives.

Arguments

  • ske: Coskewness estimator with a FullMoment moment algorithm.
  • args...: The observations, forwarded to partial_fit!.
  • kwargs...: Additional keyword arguments, forwarded to partial_fit!.

Returns

  • ske::Coskewness: A new estimator carrying the folded state.

Related

source
PortfolioOptimisers.partial_fitMethod
partial_fit(
    kte::Cokurtosis{<:Any, <:Any, <:FullMoment},
    args...;
    kwargs...
) -> Any

Cokurtosis method of partial_fit. Forwards to partial_fit!, because the fold already writes into no array of the state it was given.

The companion of the Coskewness method, and the one that pays for the override. The generic method would copy M4 before every fold, which is assets² × assets²: 800 MB at a hundred assets, per call, for a copy no caller reads.

Algorithm

  1. Forward X and every keyword to partial_fit!, and return the estimator it gives.

Arguments

  • kte: Cokurtosis estimator with a FullMoment moment algorithm.
  • args...: The observations, forwarded to partial_fit!.
  • kwargs...: Additional keyword arguments, forwarded to partial_fit!.

Returns

  • kte::Cokurtosis: A new estimator carrying the folded state.

Related

source