Price gap fill: private API

PortfolioOptimisers.carrier_listing_spanFunction
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.

  1. Any price carrier: nothing. The family states no span of its own.
  2. A PricesResult: its span field.

Arguments

  • pr: The price carrier the fill is running on.

Returns

  • span::Option{<:AbstractMatrix{Bool}}: The carrier's Listing Span, or nothing.

Related

source
PortfolioOptimisers.gap_fill_spanFunction
gap_fill_span(span::AbstractMatrix{Bool}, X::AbstractMatrix, strict::Bool) -> AbstractMatrix{Bool}
gap_fill_span(span::Nothing, X::AbstractMatrix, strict::Bool) -> BitMatrix

Resolve 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.

  1. span is an AbstractMatrix{Bool}: check its shape against X and answer it. A caller's own declaration and a derived PortfolioOptimisers.ListingSpan enter alike, under the public bound.
  2. span is nothing: report through strict_diagnostic when X holds a gap, then answer an all-false span of X's shape, which fills nothing.

Arguments

  • span: The listing statement the carrier holds, observations × assets, or nothing.
  • X: The price values of the window being transformed, observations × assets.
  • strict: If true, throws an ArgumentError when the carrier states no span; if false, issues a warning.

Validation

  • size(span) == size(X). Raises a DimensionMismatch.
  • The carrier states a span when X holds a gap. Raises an ArgumentError under strict.

Returns

  • span: The listing statement on the price clock of X, or an all-false span when the carrier states none.

Related

source
PortfolioOptimisers.gap_fill_seedFunction
gap_fill_seed(fill::CarriedPrice, obs::VecNum) -> Number
gap_fill_seed(fill::Num_VecToScaM, obs::VecNum) -> Number

Reduce one asset's observed training prices to the value apply_preprocessing replays.

Algorithm

The method that Julia selects is the algorithm.

  1. CarriedPrice: the last observed training price, which seeds a carry-forward on a later window that opens inside a gap.
  2. Num_VecToScaM: the reduction of the observed training prices, through vec_to_real_measure.

Arguments

  • fill: The convention, read off PriceGapFill.
  • obs: One asset's observed training prices, in observation order.

Returns

  • v::Number: The asset's fitted value.

Related

source
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) -> AbstractMatrix

Write 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.

  1. CarriedPrice: walk the observation axis carrying a price. Nothing is written until the walk meets an observed price or reaches t0, whichever is first; from t0 on, the carry is v until 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.
  2. Num_VecToScaM: write v onto every gap inside the listing. The value is already the reduction, so nothing is carried, an observed price is read by nothing, and t0 is read by nothing.

Arguments

  • fill: The convention, read off PriceGapFillResult.
  • 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) + 1 when the window holds none, as on the training window itself, and 1 when every observation follows the training window.

Returns

  • X::AbstractMatrix: The same matrix, with column j filled.

Related

source