Windowed variance
PortfolioOptimisers.WindowedVariance — Type
struct WindowedVariance{__T_ve, __T_w, __T_window, __T_rule, __T_cache} <: AbstractVarianceEstimatorFits an inner variance estimator on a rolling or indexed window of observations.
WindowedVariance holds another variance estimator, and applies it to the observations of a window, with optional observation weights. So the estimate can follow the most recent observations, or give them more weight.
Fields
ve: Variance estimator.w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.window: Observation window. An integer selects the lastwindowobservations, and a vector of indices selects those observations.rule:AbstractWindowRulethat sets the observations that the window keeps on the online step.RollingWindowkeeps the window at every fit, andSeedWindowkeeps it at the first fit alone.cache: Optional partial-fit state. It isnothinguntilpartial_fit!writes one. When the caller gives no data matrix, the batch verb of the estimator reads it. Each propagation channel does one thing with it.factorykeeps it unchanged, because a factory call resolves the configuration, not the sample.port_opt_viewcopies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone.obs_weights_viewremoves it, because a state has no slice on the observation axis. Only a type with an observation-weights field has that channel. A type with no such field falls through to the identity method, so it keeps its state. A family whose state has no exact asset slice removes it on both axes and names the reason.
Constructors
WindowedVariance(; ve::AbstractVarianceEstimator = SimpleVariance(), w::Option{<:ObsWeights} = nothing, window::Option{<:Int_VecInt} = nothing, rule::AbstractWindowRule = RollingWindow(), cache::Option{<:AbstractPartialFitState} = nothing) -> WindowedVarianceEach keyword sets the struct field of the same name.
Validation
- If
wis notnothing,!isempty(w). - If
windowis notnothing, it must be nonempty, nonnegative and finite.
Propagated parameters
factory passes its arguments on to these @fprop fields:
ve: Recursively updated throughfactory.w: Replaced with the incomingObsWeights.cache: Carried unchanged throughfactory.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
ve: Recursively viewed throughport_opt_view.cache: Sliced to the selected assets throughport_opt_view.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
ve: Recursively indexed throughobs_weights_view.w: Indexed to the selected observations throughobs_weights_view.
Examples
julia> WindowedVariance()WindowedVariance ve ┼ SimpleVariance │ me ┼ SimpleExpectedReturns │ │ w ┴ nothing │ w ┼ nothing │ corrected ┴ Bool: true w ┼ nothing window ┼ nothing rule ┴ RollingWindow()Related
AbstractVarianceEstimatorSimpleVarianceStatistics.var(ve::WindowedVariance, X::MatNum)Statistics.var(ve::WindowedVariance, X::VecNum)Statistics.std(ve::WindowedVariance, X::MatNum)Statistics.std(ve::WindowedVariance, X::VecNum)Statistics.var(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})Statistics.std(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})RollingWindowSeedWindowfactoryport_opt_viewobs_weights_viewwindowed_preamble
Statistics.var — Method
Statistics.var(ve::WindowedVariance, X::MatNum; dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing, kwargs...)Compute Statistics.var over a rolling or indexed window of observations, for a matrix input.
The method selects a window of observations from X, and applies the observation weights when the estimator holds them. Then it calls the inner variance estimator.
Algorithm
- Resolve the window and the observation weights with
windowed_preamble. It returnsinner, a copy ofve.vethat holds the windowed weights, and the windowedX, the windowediv, and theactive_maskandestimation_maskkeywords cut to the window. - Call
Statistics.varoninnerand the windowedX, and return its result. The inner estimator alone computes the value. This method changes only the observations and the weights that the inner estimator gets.
Arguments
ve: Windowed variance estimator.X: Data matrix of asset returns,observations × assets.dims: Dimension along which the computation runs.mean: Optional precomputed mean, passed to the inner estimator.iv: Optional implied volatility matrix. The estimator reads it only when one of its inner covariance estimators is anImpliedVolatility.kwargs...: More keyword arguments, passed to the inner estimator. The method cuts theactive_maskandestimation_maskkeywords to the window.
Returns
vr::ArrNum: Variance vector ofX, with the shape that matches the dimension of the computation.
Related
WindowedVarianceStatistics.var(ve::WindowedVariance, X::VecNum)Statistics.std(ve::WindowedVariance, X::MatNum)Statistics.std(ve::WindowedVariance, X::VecNum)Statistics.var(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})Statistics.std(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})windowed_preamble
Statistics.var — Method
Statistics.var(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel}; dims::Int = 1, mean = nothing, kwargs...)Compute Statistics.var over a rolling or indexed window of observations, for an Asset Panel input.
The method selects a window of observations from X, and applies the observation weights when the estimator holds them. Then it calls the inner variance estimator. It cuts the Asset Panel to the same observations and gives it to the inner estimator. A mask-aware inner estimator then reads the active mask of the window, and a plain one reduces to the Coverage Universe of the window.
Algorithm
- Cut
pnlto the observations of the window withwindowed_panel. - Resolve the window and the observation weights with
windowed_preamble. It returnsinner, a copy ofve.vethat holds the windowed weights, and the windowedX, the windowediv, and theactive_maskandestimation_maskkeywords cut to the window. - Call
Statistics.varoninnerand the windowedXandpnl, and return its result. The inner estimator alone computes the value. This method changes only the observations and the weights that the inner estimator gets.
Arguments
ve: Windowed variance estimator.X: Data matrix of asset returns,observations × assets.pnl: OptionalAssetPanel. The Coverage Universe of the fit comes from its active mask. If it isnothing, the rule reads only the finiteness of the returns.dims: Dimension along which the computation runs.mean: Optional precomputed mean, passed to the inner estimator.kwargs...: More keyword arguments, passed to the inner estimator. The method cuts theiv,active_maskandestimation_maskkeywords to the window.
Returns
vr::ArrNum: Variance vector ofX, with the shape that matches the dimension of the computation.
Related
Statistics.var — Method
Statistics.var(ve::WindowedVariance, X::VecNum; mean = nothing)Compute Statistics.var over a rolling or indexed window of observations, for a vector input.
The method selects a window of observations from X, and applies the observation weights when the estimator holds them. Then it calls the inner variance estimator.
Algorithm
- Resolve the window and the observation weights with
windowed_preamble. It returnsinner, a copy ofve.vethat holds the windowed weights, and the windowedX. - Call
Statistics.varoninnerand the windowedX, and return its result. The inner estimator alone computes the value. This method changes only the observations and the weights that the inner estimator gets.
Arguments
ve: Windowed variance estimator.X: Data vector of returns.mean: Optional precomputed mean, passed to the inner estimator.
Returns
vr::Number: Variance ofX.
Related
WindowedVarianceStatistics.var(ve::WindowedVariance, X::MatNum)Statistics.std(ve::WindowedVariance, X::MatNum)Statistics.std(ve::WindowedVariance, X::VecNum)Statistics.var(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})Statistics.std(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})windowed_preamble
Statistics.std — Method
Statistics.std(ve::WindowedVariance, X::MatNum; dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing, kwargs...)Compute Statistics.std over a rolling or indexed window of observations, for a matrix input.
The method selects a window of observations from X, and applies the observation weights when the estimator holds them. Then it calls the inner variance estimator.
Algorithm
- Resolve the window and the observation weights with
windowed_preamble. It returnsinner, a copy ofve.vethat holds the windowed weights, and the windowedX, the windowediv, and theactive_maskandestimation_maskkeywords cut to the window. - Call
Statistics.stdoninnerand the windowedX, and return its result. The inner estimator alone computes the value. This method changes only the observations and the weights that the inner estimator gets.
Arguments
ve: Windowed variance estimator.X: Data matrix of asset returns,observations × assets.dims: Dimension along which the computation runs.mean: Optional precomputed mean, passed to the inner estimator.iv: Optional implied volatility matrix. The estimator reads it only when one of its inner covariance estimators is anImpliedVolatility.kwargs...: More keyword arguments, passed to the inner estimator. The method cuts theactive_maskandestimation_maskkeywords to the window.
Returns
sd::ArrNum: Standard deviation vector ofX, with the shape that matches the dimension of the computation.
Related
WindowedVarianceStatistics.var(ve::WindowedVariance, X::MatNum)Statistics.var(ve::WindowedVariance, X::VecNum)Statistics.std(ve::WindowedVariance, X::VecNum)Statistics.var(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})Statistics.std(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})windowed_preamble
Statistics.std — Method
Statistics.std(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel}; dims::Int = 1, mean = nothing, kwargs...)Compute Statistics.std over a rolling or indexed window of observations, for an Asset Panel input.
The method selects a window of observations from X, and applies the observation weights when the estimator holds them. Then it calls the inner variance estimator. It cuts the Asset Panel to the same observations and gives it to the inner estimator. A mask-aware inner estimator then reads the active mask of the window, and a plain one reduces to the Coverage Universe of the window.
Algorithm
- Cut
pnlto the observations of the window withwindowed_panel. - Resolve the window and the observation weights with
windowed_preamble. It returnsinner, a copy ofve.vethat holds the windowed weights, and the windowedX, the windowediv, and theactive_maskandestimation_maskkeywords cut to the window. - Call
Statistics.stdoninnerand the windowedXandpnl, and return its result. The inner estimator alone computes the value. This method changes only the observations and the weights that the inner estimator gets.
Arguments
ve: Windowed variance estimator.X: Data matrix of asset returns,observations × assets.pnl: OptionalAssetPanel. The Coverage Universe of the fit comes from its active mask. If it isnothing, the rule reads only the finiteness of the returns.dims: Dimension along which the computation runs.mean: Optional precomputed mean, passed to the inner estimator.kwargs...: More keyword arguments, passed to the inner estimator. The method cuts theiv,active_maskandestimation_maskkeywords to the window.
Returns
sd::ArrNum: Standard deviation vector ofX, with the shape that matches the dimension of the computation.
Related
Statistics.std — Method
Statistics.std(ve::WindowedVariance, X::VecNum; mean = nothing)Compute Statistics.std over a rolling or indexed window of observations, for a vector input.
The method selects a window of observations from X, and applies the observation weights when the estimator holds them. Then it calls the inner variance estimator.
Algorithm
- Resolve the window and the observation weights with
windowed_preamble. It returnsinner, a copy ofve.vethat holds the windowed weights, and the windowedX. - Call
Statistics.stdoninnerand the windowedX, and return its result. The inner estimator alone computes the value. This method changes only the observations and the weights that the inner estimator gets.
Arguments
ve: Windowed variance estimator.X: Data vector of returns.mean: Optional precomputed mean, passed to the inner estimator.
Returns
sd::Number: Standard deviation ofX.
Related
WindowedVarianceStatistics.var(ve::WindowedVariance, X::MatNum)Statistics.var(ve::WindowedVariance, X::VecNum)Statistics.std(ve::WindowedVariance, X::MatNum)Statistics.var(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})Statistics.std(ve::WindowedVariance, X::MatNum, pnl::Option{<:AssetPanel})windowed_preamble