Windowed preamble

A windowed estimator under SeedWindow folds. These methods fold it and read its estimate out of the fold. The private page documents the other names of this topic.

PortfolioOptimisers.supports_partial_fit — Method
supports_partial_fit(
    _::Union{WindowedCokurtosis{<:Any, <:Any, <:Any, <:SeedWindow}, WindowedCoskewness{<:Any, <:Any, <:Any, <:SeedWindow}, WindowedCovariance{<:Any, <:Any, <:Any, <:SeedWindow}, WindowedExpectedReturns{<:Any, <:Any, <:Any, <:SeedWindow}, WindowedVariance{<:Any, <:Any, <:Any, <:SeedWindow}}
) -> Bool

Return true, because a windowed estimator under a SeedWindow folds.

In a Carry Fold, a prior such as EmpiricalPrior folds each member that folds. It fits each other member again over the rows that it carries. A fit again over those rows cuts the window again, which is the rule of a RollingWindow. So a seed window must fold, and the answer is true for each inner estimator. If the inner estimator does not fold, partial_fit! throws an error that names it, and the prior does not fit the estimator again.

Arguments

  • est: Windowed estimator under a seed window.

Returns

  • true.

Related

source
PortfolioOptimisers.partial_fit! — Method
partial_fit!(est::SeedWindowed, X::MatNum; dims::Int = 1, kwargs...)
partial_fit!(est::SeedWindowed, x::VecNum; kwargs...)

Fold a block of observations into a windowed estimator under a SeedWindow.

The first fold cuts the block to the window, as a batch fit does, and folds the rows that remain into the inner estimator. It returns the estimator with window = nothing. Each later fold then passes every row to the inner estimator. The windowed estimator holds no state of its own. Its inner estimator holds the state of the fold, and the window of nothing records that the first fold happened.

The vector method folds one observation as a matrix of one row. It also changes each Bool vector keyword, such as a mask, to a matrix of one row. A first fold of one observation keeps it when the window keeps the last row.

Algorithm

  1. Read inner, the inner estimator. The declaration of each windowed type sets it as the first field.
  2. Resolve the window against the block to win with get_window. After the first fold, the window is nothing and win is a Colon.
  3. Cut the block with windowed_rows. Cut the active_mask and estimation_mask keywords with windowed_keywords.
  4. Fold the cut block into inner with partial_fit!.
  5. Return the estimator with the folded inner and window = nothing.

Arguments

  • est: Windowed estimator under a seed window.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • x::VecNum: One observation, with one entry for each asset.
  • dims: Dimension along which the computation runs.
  • kwargs...: Keywords for the fold of the inner estimator. The function cuts the two universe masks to the window.

Validation

  • est.w is nothing, because a vector of observation weights gives a new weight to each past observation when a new observation arrives. The function throws an ArgumentError otherwise.
  • The inner estimator folds, by supports_partial_fit. The function throws an ArgumentError otherwise.
  • dims in (1, 2).

Returns

  • est: The windowed estimator, with its inner estimator folded and its window spent.

Related

source
Statistics.mean — Method
mean(
    me::WindowedExpectedReturns{<:Any, <:Any, <:Any, <:SeedWindow};
    kwargs...
) -> Any

Read the expected returns from the fold of a windowed estimator under a SeedWindow.

The inner estimator holds the state of the fold, so the method reads it there.

Arguments

  • me: Windowed expected returns estimator under a seed window.
  • kwargs...: Keywords for the read of the inner estimator.

Returns

  • mu::ArrNum: Expected returns vector assets x 1 if the dims keyword does not exist or dims = 2, 1 x assets if dims = 1.

Related

source
Statistics.cov — Method
cov(
    ce::WindowedCovariance{<:Any, <:Any, <:Any, <:SeedWindow};
    kwargs...
) -> Any

Read the covariance from the fold of a windowed estimator under a SeedWindow.

The inner estimator holds the state of the fold, so the method reads it there.

Arguments

  • ce: Windowed covariance estimator under a seed window.
  • kwargs...: Keywords for the read of the inner estimator.

Returns

  • sigma::MatNum: Covariance matrix assets x assets.

Related

source
Statistics.cor — Method
cor(
    ce::WindowedCovariance{<:Any, <:Any, <:Any, <:SeedWindow};
    kwargs...
) -> Any

Read the correlation from the fold of a windowed estimator under a SeedWindow.

The inner estimator holds the state of the fold, so the method reads it there. The generic cor with no data reads the cache of the windowed estimator, which stays nothing.

Arguments

  • ce: Windowed covariance estimator under a seed window.
  • kwargs...: Keywords for the read of the inner estimator.

Returns

  • rho::MatNum: Correlation matrix assets x assets.

Related

source
Statistics.var — Method
var(
    ve::WindowedVariance{<:Any, <:Any, <:Any, <:SeedWindow};
    kwargs...
) -> Any

Read the variance from the fold of a windowed estimator under a SeedWindow.

The inner estimator holds the state of the fold, so the method reads it there.

Arguments

  • ve: Windowed variance estimator under a seed window.
  • kwargs...: Keywords for the read of the inner estimator.

Returns

  • vr::ArrNum: Variance vector of X, with the shape that matches the dimension of the computation.

Related

source
Statistics.std — Method
std(
    ve::WindowedVariance{<:Any, <:Any, <:Any, <:SeedWindow};
    kwargs...
) -> Any

Read the standard deviation from the fold of a windowed estimator under a SeedWindow.

The inner estimator holds the state of the fold, so the method reads it there. The generic std with no data reads the cache of the windowed estimator, which stays nothing.

Arguments

  • ve: Windowed variance estimator under a seed window.
  • kwargs...: Keywords for the read of the inner estimator.

Returns

  • sd::ArrNum: Standard deviation vector of X, with the shape that matches the dimension of the computation.

Related

source
PortfolioOptimisers.coskewness — Method
coskewness(
    ske::WindowedCoskewness{<:Any, <:Any, <:Any, <:SeedWindow};
    kwargs...
) -> Any

Read the coskewness from the fold of a windowed estimator under a SeedWindow.

The inner estimator holds the state of the fold, so the method reads it there.

Arguments

  • ske: Windowed coskewness estimator under a seed window.
  • kwargs...: Keywords for the read of the inner estimator.

Returns

  • cskew::MatNum: Coskewness tensor assets x assets².
  • V::MatNum: Negative spectral skewness matrix assets x assets of the coskewness tensor, after the matrix processing.

Related

source
PortfolioOptimisers.cokurtosis — Method
cokurtosis(
    kte::WindowedCokurtosis{<:Any, <:Any, <:Any, <:SeedWindow};
    kwargs...
) -> Any

Read the cokurtosis from the fold of a windowed estimator under a SeedWindow.

The inner estimator holds the state of the fold, so the method reads it there.

Arguments

  • kte: Windowed cokurtosis estimator under a seed window.
  • kwargs...: Keywords for the read of the inner estimator.

Returns

  • ckurt::MatNum: Square cokurtosis matrix assets² x assets².

Related

source