pub struct FactorModel;Expand description
Multi-factor risk model supporting OLS regression and auxiliary analytics.
Implementations§
Source§impl FactorModel
impl FactorModel
Sourcepub fn ols(y: &[f64], x: &[Vec<f64>]) -> (Vec<f64>, f64)
pub fn ols(y: &[f64], x: &[Vec<f64>]) -> (Vec<f64>, f64)
Solve an OLS system using Gaussian elimination on the augmented matrix of the normal equations (X^T X) β = X^T y.
Returns (coefficients, r_squared). x rows are observations; columns
are regressors (the intercept column must already be included by the caller).
Sourcepub fn t_statistics(
coefficients: &[f64],
x: &[Vec<f64>],
y: &[f64],
betas: &[f64],
) -> Vec<f64>
pub fn t_statistics( coefficients: &[f64], x: &[Vec<f64>], y: &[f64], betas: &[f64], ) -> Vec<f64>
Compute t-statistics for each coefficient: β_i / SE_i where SE is derived from the OLS residual variance.
Sourcepub fn fit(
&self,
asset_returns: &[f64],
factors: &[Factor],
) -> FactorModelResult
pub fn fit( &self, asset_returns: &[f64], factors: &[Factor], ) -> FactorModelResult
Fit the factor model: regress asset_returns onto the provided factors.
The design matrix includes an intercept column (index 0).
Sourcepub fn fama_french_3(
asset_returns: &[f64],
mkt_rf: &[f64],
smb: &[f64],
hml: &[f64],
rf_rate: f64,
) -> FactorModelResult
pub fn fama_french_3( asset_returns: &[f64], mkt_rf: &[f64], smb: &[f64], hml: &[f64], rf_rate: f64, ) -> FactorModelResult
Fama-French three-factor model: regress excess asset returns onto MKT-RF, SMB, HML.
rf_rate is the per-period risk-free rate subtracted from asset_returns.
Sourcepub fn information_ratio(alpha: f64, residuals: &[f64]) -> f64
pub fn information_ratio(alpha: f64, residuals: &[f64]) -> f64
Annualised information ratio: alpha / tracking_error * sqrt(252).
Returns 0.0 when tracking_error is (near) zero.
Sourcepub fn factor_contribution(
exposures: &[FactorExposure],
factor_returns: &[f64],
) -> Vec<f64>
pub fn factor_contribution( exposures: &[FactorExposure], factor_returns: &[f64], ) -> Vec<f64>
Per-period factor contribution: beta_i * factor_return_i for each period.
Sourcepub fn systematic_return(
exposures: &[FactorExposure],
period_factor_returns: &[f64],
) -> f64
pub fn systematic_return( exposures: &[FactorExposure], period_factor_returns: &[f64], ) -> f64
Total systematic return for a single period: sum of beta_i * factor_return_i.
Sourcepub fn idiosyncratic_return(asset_return: f64, systematic: f64) -> f64
pub fn idiosyncratic_return(asset_return: f64, systematic: f64) -> f64
Idiosyncratic (alpha) return for a single period.