Skip to main content

FactorModel

Struct FactorModel 

Source
pub struct FactorModel;
Expand description

Multi-factor risk model supporting OLS regression and auxiliary analytics.

Implementations§

Source§

impl FactorModel

Source

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

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn factor_contribution( exposures: &[FactorExposure], factor_returns: &[f64], ) -> Vec<f64>

Per-period factor contribution: beta_i * factor_return_i for each period.

Source

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.

Source

pub fn idiosyncratic_return(asset_return: f64, systematic: f64) -> f64

Idiosyncratic (alpha) return for a single period.

Trait Implementations§

Source§

impl Clone for FactorModel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FactorModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FactorModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.