Price gap fill: private API
PortfolioOptimisers.carrier_listing_span — Function
carrier_listing_span(pr::AbstractPricesResult) -> Nothing
carrier_listing_span(pr::PricesResult) -> Option{<:AbstractMatrix{Bool}}Read the Listing Span a price carrier states, or nothing when it states none.
The Listing Span rides on the price carrier, so a step that needs one asks the carrier rather than deriving its own. A PricesResult answers with its span field, which price_ingestion fills and a carrier assembled by hand leaves nothing; every other member of the family answers nothing, because a carrier that carries no span states no listing calendar and the step that asked must fall back and say so.
Algorithm
The method that Julia selects is the algorithm.
- Any price carrier:
nothing. The family states no span of its own. - A
PricesResult: itsspanfield.
Arguments
pr: The price carrier the fill is running on.
Returns
span::Option{<:AbstractMatrix{Bool}}: The carrier's Listing Span, ornothing.
Related
PortfolioOptimisers.gap_fill_span — Function
gap_fill_span(span::AbstractMatrix{Bool}, X::AbstractMatrix, strict::Bool) -> AbstractMatrix{Bool}
gap_fill_span(span::Nothing, X::AbstractMatrix, strict::Bool) -> BitMatrixResolve the Listing Span that bounds a PriceGapFill over one window.
The span is the carrier's, because a listing calendar is a fact about the instruments and a window cannot see all of it. A carrier that states none leaves only the window in hand, and the window cannot answer: a suspension straddling its edge reads there as an inception or a delisting, so a window-local derivation fills the wrong cells rather than fewer of them. So the fill is bounded by nothing at all — an all-false span, under which every cell lies outside a listing and no price is written — and it says so by name, refusing under strict. The diagnostic fires only when the window actually holds a gap, since a gapless window has nothing to fill and nothing to get wrong.
The refusal is strict_diagnostic's, which is the library's one strictness policy.
Algorithm
The method that Julia selects is the algorithm.
spanis anAbstractMatrix{Bool}: check its shape againstXand answer it. A caller's own declaration and a derivedPortfolioOptimisers.ListingSpanenter alike, under the public bound.spanisnothing: report throughstrict_diagnosticwhenXholds a gap, then answer an all-falsespan ofX's shape, which fills nothing.
Arguments
span: The listing statement the carrier holds,observations × assets, ornothing.X: The price values of the window being transformed,observations × assets.strict: Iftrue, throws anArgumentErrorwhen the carrier states no span; iffalse, issues a warning.
Validation
size(span) == size(X). Raises aDimensionMismatch.- The carrier states a span when
Xholds a gap. Raises anArgumentErrorunderstrict.
Returns
span: The listing statement on the price clock ofX, or an all-falsespan when the carrier states none.
Related
PortfolioOptimisers.gap_fill_seed — Function
gap_fill_seed(fill::CarriedPrice, obs::VecNum) -> Number
gap_fill_seed(fill::Num_VecToScaM, obs::VecNum) -> NumberReduce one asset's observed training prices to the value apply_preprocessing replays.
Algorithm
The method that Julia selects is the algorithm.
CarriedPrice: the last observed training price, which seeds a carry-forward on a later window that opens inside a gap.Num_VecToScaM: the reduction of the observed training prices, throughvec_to_real_measure.
Arguments
fill: The convention, read offPriceGapFill.obs: One asset's observed training prices, in observation order.
Returns
v::Number: The asset's fitted value.
Related
PortfolioOptimisers.gap_fill_column! — Function
gap_fill_column!(fill::CarriedPrice, X::AbstractMatrix, span::AbstractMatrix{Bool}, j::Integer, v::Number, t0::Integer) -> AbstractMatrix
gap_fill_column!(fill::Num_VecToScaM, X::AbstractMatrix, span::AbstractMatrix{Bool}, j::Integer, v::Number, t0::Integer) -> AbstractMatrixWrite one column's fill in place, inside the asset's listing and nowhere else.
Both methods read span before they read the price, so an observation outside the listing is never written whatever the convention states. That is where the guarantee sits: the fill cannot fabricate a price before an asset's first listing or after its delisting, because those observations are outside the span by the Span Rule.
Under CarriedPrice the seed v is a price observed at the end of the training window, so it may be written only onto an observation after that window, which t0 names. The walk starts with nothing to write; it may write the seed once it reaches t0 without having met an observed price, and it writes the most recent observed price wherever it has met one. A gap before t0 that no observed price precedes stays a gap: on the training window, which a Pipeline transforms with the step it just fitted, that is every observation, so a gap that opens the window is not filled from the window's own end.
Algorithm
The method that Julia selects is the algorithm, and the two differ in what they write.
CarriedPrice: walk the observation axis carrying a price. Nothing is written until the walk meets an observed price or reachest0, whichever is first; fromt0on, the carry isvuntil an observed price replaces it. Inside the listing, write the carry onto a gap once there is one to write, and take an observed price as the new carry.Num_VecToScaM: writevonto every gap inside the listing. The value is already the reduction, so nothing is carried, an observed price is read by nothing, andt0is read by nothing.
Arguments
fill: The convention, read offPriceGapFillResult.X: The price values of the window, mutated in place.span: The listing statement bounding the fill,observations × assets.j: Index of the column to fill.v: The asset's fitted value.t0: Index of the first observation after the training window.size(X, 1) + 1when the window holds none, as on the training window itself, and1when every observation follows the training window.
Returns
X::AbstractMatrix: The same matrix, with columnjfilled.
Related