Cross-Sectional Idiosyncratic Diagnostics: private API

Functions

PortfolioOptimisers.standardised_idio_valueFunction
standardised_idio_value(e::Real, v::Real)

Return one standardised idiosyncratic return.

The idiosyncratic return is divided by the standard deviation the fit predicted for it, and the answer is NaN wherever that division has no meaning: a variance that is not positive, a variance that is not finite, and a return that is not finite each read NaN. A negative variance is clamped to zero before the square root, so the verb answers rather than raises on a variance estimate that undershot.

Arguments

  • e: One idiosyncratic return.
  • v: The idiosyncratic variance predicted for it.

Returns

  • z::Real: The standardised return, or NaN.

Related

source
PortfolioOptimisers.idio_predicted_volatilityFunction
idio_predicted_volatility(vs::MatNum)

Return the idiosyncratic volatility history the fit predicted.

A negative variance is clamped to zero before the square root, so a variance estimate that undershot answers 0 rather than raising. The two dependence series read it as the quantity whose ranking they score.

Arguments

  • vs: Idiosyncratic variance history observations × assets.

Returns

  • s::Matrix{<:Real}: Predicted volatility observations × assets.

Related

source
PortfolioOptimisers.idio_row_momentsFunction
idio_row_moments(z::MatNum, t::Integer)

Return the count and the three central moments of one cross-section of standardised idiosyncratic returns.

The calibration, the excess kurtosis and the skewness are each a function of these four numbers alone, so the two passes over the cross-section are made once and read three times. An entry that is not finite enters neither the count nor a moment.

Mathematical definition

\[m_{p} = \frac{1}{n} \sum_{i \in \mathcal{F}} \left( z_{i} - \bar{z} \right)^{p}, \qquad \bar{z} = \frac{1}{n} \sum_{i \in \mathcal{F}} z_{i}\]

Where:

  • $\mathcal{F}$: The assets at which the standardised return is finite.
  • $n$: Size of $\mathcal{F}$.

Arguments

  • z: Standardised idiosyncratic returns observations × assets.
  • t: Position of the observation.

Returns

  • n::Int: Number of assets at which the standardised return is finite.
  • m2::Real: Second central moment, or NaN when n is zero.
  • m3::Real: Third central moment, or NaN when n is zero.
  • m4::Real: Fourth central moment, or NaN when n is zero.

Related

source
PortfolioOptimisers.idio_vol_dependenceFunction
idio_vol_dependence(eps::MatNum, vs::MatNum, standardise::Bool)

Return the rank correlation of the predicted idiosyncratic volatility against the next observation's absolute idiosyncratic return, standardised or not.

It is the worker of idio_vol_ic and of idio_vol_residual_dependence, which read the same two cross-sections and differ only in whether the target is divided by the predicted volatility. Both score the volatility the fit predicted at observation $t$ against what the asset realised at observation $t + 1$, so the series is one entry shorter than the history.

The correlation is taken over the assets at which both cross-sections are finite, and an observation that shares fewer than five such assets reads NaN.

Arguments

  • eps: Idiosyncratic return history observations × assets.
  • vs: Idiosyncratic variance history observations × assets.
  • standardise: Divide the absolute return of observation $t + 1$ by the volatility predicted at observation $t$.

Validation

  • !isempty(eps).
  • size(vs) == size(eps).
  • size(eps, 1) > 1.

Returns

  • c::Vector{<:Real}: The series, observations - 1 entries. Entry t reads observations t and t + 1.

Related

source
PortfolioOptimisers.idio_nan_meanFunction
idio_nan_mean(v::VecNum)

Return the mean of the finite entries of a series.

A diagnostic series carries NaN at an observation that had too few assets, and the summary reads the observations that answered. This verb states that rule once for the four means the summary takes.

Arguments

  • v: The series.

Returns

  • m::Real: The mean of the finite entries, or NaN when the series carries none.

Related

source
PortfolioOptimisers.idio_nan_medianFunction
idio_nan_median(v::VecNum)

Return the median of the finite entries of a series.

The summary reads the median of the calibration series beside its mean, because one observation whose cross-section was nearly constant moves the mean and not the median.

Arguments

  • v: The series.

Returns

  • m::Real: The median of the finite entries, or NaN when the series carries none.

Related

source
PortfolioOptimisers.idio_diagnostic_dataFunction
idio_diagnostic_data(csfm::CrossSectionalFactorModel)
idio_diagnostic_data(csr::Nothing, vs::Option{<:MatNum})
idio_diagnostic_data(csr::CrossSectionalRegression, vs::Nothing)
idio_diagnostic_data(csr::CrossSectionalRegression, vs::MatNum)

Return the idiosyncratic return history and the idiosyncratic variance history an idiosyncratic diagnostic reads off a factor model block.

The group reads the residual of the fit against the variance the fit predicted for it. Neither history carries a factor axis, so the group takes no lag and no family re-basis, and the two histories are read as the block wrote them. The absent case is the dispatch rather than a branch, and its message names the field the caller must populate.

Arguments

  • csfm: A cross-sectional factor model block.
  • csr: The csr field of the block, or nothing.
  • vs: The vs field of the block, or nothing.

Validation

  • csfm.csr is not nothing, else an IsNothingError naming csr is raised.
  • csfm.vs is not nothing, else an IsNothingError naming vs is raised.

Returns

  • eps::MatNum: Idiosyncratic return history observations × assets.
  • vs::MatNum: Idiosyncratic variance history observations × assets.

Related

source