Asset panel concat: private API
Functions
PortfolioOptimisers.assert_panel_concat — Function
assert_panel_concat(
a::AssetPanel,
b::AssetPanel,
k::Integer
)
Refuses a part of a concatenation of Asset Panels whose schema differs from the schema of the first part.
Algorithm
- Check that
bis static whenais static, and time-varying whenais time-varying. - Check that the asset axis of
bhas the length of the asset axis ofa. - Check that the Panel Field names of
bequal the names ofa, in the same order. - Check each pair of fields with
assert_panel_field_concat.
Arguments
a: The first part.b: A later part.k: The position ofbin the concatenation, which the messages quote.
Validation
panel_is_static(a) == panel_is_static(b). AnArgumentErroris thrown otherwise.- The two asset counts are equal. A
DimensionMismatchis thrown otherwise. - The two lists of Panel Field names are equal. An
ArgumentErroris thrown otherwise.
Returns
nothing.
Related
PortfolioOptimisers.assert_panel_field_concat — Function
assert_panel_field_concat(f::AbstractPanelField, g::AbstractPanelField, k::Integer) -> nothing
assert_panel_field_concat(f::CategoricalPanelField, g::CategoricalPanelField, k::Integer) -> nothing
assert_panel_field_concat(f::TensorPanelField, g::TensorPanelField, k::Integer) -> nothingRefuses a Panel Field of a later part of a concatenation of Asset Panels whose schema differs from its field in the first part.
Algorithm
The method that Julia selects is the algorithm.
- Two fields of different kinds: throw. Two numeric fields, or two fields of one kind that the library does not define, have no more schema to check.
- Two categorical fields: check that the levels are equal. A code indexes the levels of its own part, so a code over other levels names another category.
- Two tensor fields: check that the axis names, the labels and the groups are equal.
Arguments
f: The field of the first part.g: The field of the same name in a later part.k: The position of the later part, which the messages quote.
Validation
- The two fields are of one kind. An
ArgumentErroris thrown otherwise. - Two categorical fields have equal levels. An
ArgumentErroris thrown otherwise. - Two tensor fields have equal axis names, labels and groups. An
ArgumentErroris thrown otherwise.
Returns
nothing.
Related
PortfolioOptimisers.panel_field_vcat — Function
panel_field_vcat(f::NumericPanelField, fs::AbstractVector) -> NumericPanelField
panel_field_vcat(f::CategoricalPanelField, fs::AbstractVector) -> CategoricalPanelField
panel_field_vcat(f::TensorPanelField, fs::AbstractVector) -> TensorPanelFieldConcatenates the parts of one time-varying Panel Field along the observation axis.
assert_panel_field_concat checked the schema of each part before the call, so the result takes the name, the levels, the axis name, the labels and the groups of f.
Algorithm
The method that Julia selects is the algorithm. Each kind concatenates the value arrays of its parts with panel_values_vcat, their observed masks with panel_omsk_vcat, and their placeholder masks with panel_pmsk_vcat.
Arguments
f: The field of the first part.fs: The field of each part,ffirst, in the order of the observations.
Returns
- A Panel Field of the kind of
f, over the observations of every part.
Related
PortfolioOptimisers.panel_values_vcat — Function
panel_values_vcat(vs::AbstractVector{<:RepeatedLeading}) -> AbstractArray
panel_values_vcat(vs::AbstractVector) -> AbstractArrayConcatenates the value arrays of the parts of one Panel Field along the observation axis.
Algorithm
The method that Julia selects is the algorithm.
- Every part is a
RepeatedLeadingarray, and every part lifts an array equal to the one of the first part: return one lazy lift of that array over the observations of every part. Otherwise concatenate the parts withvcat. - Any other parts: concatenate them with
vcat.
Arguments
vs: The value array of each part, in the order of the observations.
Returns
v::AbstractArray: The values over the observations of every part.
Related
PortfolioOptimisers.panel_omsk_vcat — Function
panel_omsk_vcat(ms::AbstractVector{Nothing}, vals::AbstractVector) -> Nothing
panel_omsk_vcat(ms::AbstractVector, vals::AbstractVector) -> AbstractArray{Bool}Concatenates the observed masks of the parts of one Panel Field along the observation axis.
A part with no observed mask cannot blank, so each of its cells was observed.
Algorithm
The method that Julia selects is the algorithm.
- No part has an observed mask: return
nothing. - Otherwise: write an array of
truevalues of the size of its values for each part with no mask, and concatenate the masks withvcat.
Arguments
ms: The observed mask of each part, ornothing, in the order of the observations.vals: The value array of each part, which gives the size of a missing mask.
Returns
omsk::Option{<:AbstractArray{Bool}}: The observed mask over the observations of every part, ornothing.
Related
PortfolioOptimisers.panel_pmsk_vcat — Function
panel_pmsk_vcat(ms::AbstractVector{Nothing}, vals::AbstractVector) -> Nothing
panel_pmsk_vcat(ms::AbstractVector, vals::AbstractVector) -> AbstractArray{Bool}Concatenates the placeholder masks of the parts of one Panel Field along the observation axis.
A part with no placeholder mask holds no placeholder, so each of its cells holds data.
Algorithm
The method that Julia selects is the algorithm.
- No part has a placeholder mask: return
nothing. - Otherwise: write an array of
falsevalues of the size of its values for each part with no mask, and concatenate the masks withvcat.
Arguments
ms: The placeholder mask of each part, ornothing, in the order of the observations.vals: The value array of each part, which gives the size of a missing mask.
Returns
pmsk::Option{<:AbstractArray{Bool}}: The placeholder mask over the observations of every part, ornothing.
Related
PortfolioOptimisers.panel_field_isequal — Function
panel_field_isequal(f::AbstractPanelField, g::AbstractPanelField) -> BoolTests whether two Panel Fields of one schema hold the same data: the same stored cells, the same observed mask and the same placeholder mask.
A missing mask is read as the concatenation along the observation axis reads it. A field with no observed mask holds data in each cell, as a mask that is true everywhere states, and a field with no placeholder mask holds no placeholder, as a mask that is false everywhere states. assert_panel_concat checked the schema before the call: the kind, the levels, the axis name, the labels and the groups.
Algorithm
- Compare the stored arrays, which
panel_field_arrayreads, withisequal. - Compare the observed masks with
panel_mask_isequal, withtruefor a missing mask. - Compare the placeholder masks with
panel_mask_isequal, withfalsefor a missing mask.
Arguments
f: The field of the first part.g: The field of the same name in a later part.
Returns
flag::Bool:truewhen the two fields hold the same data.
Related
PortfolioOptimisers.panel_mask_isequal — Function
panel_mask_isequal(m::Nothing, n::Nothing, fill::Bool) -> Bool
panel_mask_isequal(m::AbstractArray{Bool}, n::Nothing, fill::Bool) -> Bool
panel_mask_isequal(m::Nothing, n::AbstractArray{Bool}, fill::Bool) -> Bool
panel_mask_isequal(m::AbstractArray{Bool}, n::AbstractArray{Bool}, fill::Bool) -> BoolTests whether two masks of one Panel Field are equal, with fill in each cell of a missing mask.
The caller compared the stored arrays of the two fields first, so a mask has the shape of the values, and a missing mask needs no array to compare.
Algorithm
The method that Julia selects is the algorithm.
- Two missing masks: return
true. - One missing mask: return whether each cell of the other mask is
fill. - Two masks: compare them with
isequal.
Arguments
m: The mask of the first field, ornothing.n: The mask of the second field, ornothing.fill: The value of each cell of a missing mask.
Returns
flag::Bool:truewhen the two masks are equal.
Related
PortfolioOptimisers.panel_mask_vcat — Function
panel_mask_vcat(ms::AbstractVector{<:AllTrueMask}) -> AllTrueMask
panel_mask_vcat(ms::AbstractVector) -> AbstractMatrix{Bool}Concatenates one universe mask of the parts of a time-varying Asset Panel along the observation axis.
Algorithm
The method that Julia selects is the algorithm.
- Every part is an
AllTrueMask: return oneAllTrueMaskover the observations of every part, which stores no cell. - Any other parts: concatenate them with
vcat.
Arguments
ms: The mask of each part, in the order of the observations.
Returns
msk::AbstractMatrix{Bool}: The mask over the observations of every part.
Related
PortfolioOptimisers.panel_fields_panel — Function
panel_fields_panel(pf::AbstractVector{<:AbstractPanelField}) -> AssetPanelMakes the time-varying Asset Panel that carries the Panel Fields of a sample buffer, so that the checks and the vcat of an AssetPanel apply to them.
A SampleBufferState keeps its masks in A and E, and the Panel Fields alone in P. The masks of this panel are two AllTrueMask arrays, which store no cell. They are not the masks of the buffer, and no caller reads them. The constructor of the panel checks that the Panel Fields share one observation axis and one asset axis, and that their names are unique.
Algorithm
- Refuse an empty vector, and a vector whose first Panel Field is static.
- Make the
AssetPanelof the Panel Fields and of twoAllTrueMaskarrays over their axes.
Arguments
pf: The Panel Fields.
Validation
pfis not empty. AnIsEmptyErroris thrown otherwise.- Each Panel Field is time-varying. A
DimensionMismatchis thrown otherwise. - The rules of the
AssetPanelconstructor.
Returns
pnl::AssetPanel: The time-varying panel of the Panel Fields.
Related
PortfolioOptimisers.assert_buffer_panel_shape — Function
assert_buffer_panel_shape(X::AbstractMatrix, n::Integer, P::Nothing) -> nothing
assert_buffer_panel_shape(X::AbstractMatrix, n::Integer, P::AbstractVector{<:AbstractPanelField}) -> nothingRefuses Panel Fields that do not cover the valid region of a sample buffer.
The keyword constructor of SampleBufferState calls it. P holds the valid region alone, so its observation axis has n rows, and its asset axis is the width of X.
Algorithm
The method that Julia selects is the algorithm.
Pisnothing: return.- Make the panel of
Pwithpanel_fields_panel, and refuse axes that are not(n, size(X, 2)).
Arguments
X: Backing matrix of the buffer.n: Number of observations in the valid region.P: The Panel Fields of the buffer, ornothing.
Validation
- The rules of
panel_fields_panel. - The axes of
Pare(n, size(X, 2)). ADimensionMismatchis thrown otherwise.
Returns
nothing.
Related
PortfolioOptimisers.assert_buffer_panel_block — Function
assert_buffer_panel_block(Xo::AbstractMatrix, Ao, Eo, Po::Nothing) -> nothing
assert_buffer_panel_block(Xo::AbstractMatrix, Ao, Eo, Po::AbstractVector{<:AbstractPanelField}) -> nothingRefuses Panel Fields that do not make a time-varying Asset Panel over a block of a sample buffer.
The block arm of partial_fit! for a SampleBufferState calls it before it records a row. The Panel Fields of a block and the masks of the block are one time-varying AssetPanel, so they need both masks, and they share the observations and the assets of the block.
Algorithm
The method that Julia selects is the algorithm.
Poisnothing: return.- Make the panel of
Powithpanel_fields_panel, and refuse axes that are not the size ofXo. - Refuse a block that gives Panel Fields without both masks.
Arguments
Xo: The oriented block.Ao: The oriented active mask of the block, ornothing.Eo: The oriented estimation mask of the block, ornothing.Po: The Panel Fields of the block, ornothing.
Validation
- The rules of
panel_fields_panel. - The axes of
Poaresize(Xo). ADimensionMismatchis thrown otherwise. AoandEoare notnothingwhenPois notnothing. AnArgumentErroris thrown otherwise.
Returns
nothing.
Related
PortfolioOptimisers.panel_fields_view — Function
panel_fields_view(P::Nothing, i, j) -> nothing
panel_fields_view(P::AbstractVector{<:AbstractPanelField}, i, j) -> Vector{AbstractPanelField}Views each Panel Field of a sample buffer over the observations i and the assets j, and passes Panel Fields that are not there through.
The block arm of partial_fit! for a SampleBufferState takes the rows that a cap keeps with it, and port_opt_view of the buffer takes the selected assets with it. It passes no asset names to panel_field_view, so a tensor Panel Field keeps its whole label axis.
Arguments
P: The Panel Fields, ornothing.i: Observation index.j: Asset index.
Returns
P′: The viewed Panel Fields, ornothing.
Related
PortfolioOptimisers.panel_fields_append — Function
panel_fields_append(P::Nothing, Po::Nothing, n::Integer) -> nothing
panel_fields_append(P::AbstractVector{<:AbstractPanelField}, Po::AbstractVector{<:AbstractPanelField}, n::Integer) -> AbstractVectorJoins the Panel Fields of a sample buffer to the Panel Fields of a block, and keeps the last n rows.
The block arm of partial_fit! and merge_states for a SampleBufferState call it. n is the number of observations of the buffer after the append, so the cap has already set it. The rows of Po are always kept, because a cap truncates a block before the append. vcat of two Asset Panels joins the rows, so it checks that the two lists hold the same Panel Fields.
Algorithm
The method that Julia selects is the algorithm.
PandPoarenothing: returnnothing.- Make the panel of each list with
panel_fields_panel, and check that the two can join withassert_panel_concat. - Set
keep = n - tₒ, wheretₒis the number of rows ofPo. ReturnPowhenkeepis zero. - When
keepis less than the number of rows ofP, view the lastkeeprows ofP. - Join the kept rows and
Powithvcat, and return the Panel Fields of the result.
Arguments
P: The Panel Fields of the buffer, ornothing.Po: The Panel Fields of the block, ornothing.n: The number of observations of the buffer after the append.
Validation
- The rules of
panel_fields_paneland ofassert_panel_concat.
Returns
P′: The Panel Fields of the lastnobservations, ornothing.
Related
PortfolioOptimisers.sample_buffer_panel — Function
sample_buffer_panel(state::SampleBufferState) -> Option{<:AssetPanel}Rebuilds the time-varying Asset Panel of the observations a sample buffer holds, or gives nothing when the buffer records no Panel Field.
The call with no data of a refit prior and returns_result call it. A buffer that records Panel Fields records both masks too, so the panel has its Panel Fields and both of its masks. The masks are copies of the valid region, because a later fold writes into the backing masks. The Panel Fields are the Panel Fields of the buffer, because nothing writes into them.
Algorithm
- Return
nothingwhenstate.Pisnothing. - Copy the masks
AandMover the valid region into twoMatrix{Bool}. - Make the
AssetPanelofstate.Pand the two masks.
Arguments
state: The buffer to read.
Returns
pnl::Option{<:AssetPanel}: The panel of the rows of the buffer, ornothing.
Related
PortfolioOptimisers.sample_buffer_fit_kwargs — Function
sample_buffer_fit_kwargs(state::SampleBufferState, pnl::Nothing) -> NamedTuple
sample_buffer_fit_kwargs(state::SampleBufferState, pnl::AssetPanel) -> NamedTupleGives the keywords that a fit over the rows of a sample buffer passes to the batch verb of a prior, beside the panel pnl of sample_buffer_panel.
The call with no data of a refit prior, buffer_prior, and the Choice Rule of an online step, pin_buffer_choice, both read them, so the two fits read the same data. A buffer that records no Panel Field gives its masks as keywords, as a matrix call of the batch verb takes them. A buffer that records Panel Fields gives its masks inside pnl, so the keywords hold no mask. Both give the Exogenous Series and the implied volatilities that the buffer records.
Algorithm
The method that Julia selects is the algorithm.
pnlisnothing: mergesample_buffer_kwargs,exogenous_buffer_kwargsandimplied_volatility_buffer_kwargsofstate.pnlis an Asset Panel: mergeexogenous_buffer_kwargsandimplied_volatility_buffer_kwargsofstate.
Arguments
state: The buffer to read.pnl: The panel of the rows of the buffer, whichsample_buffer_panelgives, ornothing.
Returns
kwargs::NamedTuple: The keywords of the fit.
Related
PortfolioOptimisers.buffer_asset_panel — Function
buffer_asset_panel(state::SampleBufferState) -> Option{<:AssetPanel}Rebuilds the Asset Panel of the observations a sample buffer holds, from every part of a panel that the buffer records, or gives nothing when the buffer records no active mask.
A buffer that records Panel Fields gives the panel of sample_buffer_panel. A buffer that records an active mask and no Panel Field gives a panel with no Panel Field. Its estimation mask is the one that the buffer records or, when the buffer records none, a copy of the active mask. The carry of EmpiricalPrior records the active mask alone, so its call with no data gives a member that it refits this panel, as the batch fit gives the member rd.pnl. returns_result rebuilds the panel of a ReturnsResult with it. The masks are copies of the valid region, because a later fold writes into the backing masks.
Algorithm
- Return
sample_buffer_panelofstatewhenstate.Pis notnothing. - Read the masks with
sample_buffer_kwargs, and returnnothingwhen they hold no active mask. - Copy the active mask, and the estimation mask or a second copy of the active mask, into two matrices.
- Make the
AssetPanelof no Panel Field and the two masks.
Arguments
state: The buffer to read.
Returns
pnl::Option{<:AssetPanel}: The panel of the rows of the buffer, ornothing.
Related