rwls
Regime-weighted least squares (RWLS) for estimating regime-dependent factor models.
The estimator
Factor models usually assume that an asset's exposures to common risk factors are constant. In practice, betas, factor premia and idiosyncratic risk shift with market conditions. RWLS estimates a separate factor model for every asset in every latent market regime, without fitting a regime-switching model asset by asset.
Estimation proceeds in two stages:
-
Regime identification. A multivariate Gaussian hidden Markov model is fitted to a small set of common factor returns
f_t. Its posterior probabilitiesγ_t(s) = P(S_t = s | data)measure how strongly each period belongs to each regimes. -
Regime-weighted regressions. For each asset
iand regimes, the loadings solve a weighted least-squares problem in which each observation is weighted by its posterior regime probability:(α_is, β_is) = argmin Σ_t γ_t(s) · (r_it − α − β′ f_t)²The regime-specific residual variance is measured on the regime's effective sample, the posterior mass
Σ_t γ_t(s):σ²_is = Σ_t γ_t(s) · e_it² / (Σ_t γ_t(s) − k)where
kis the number of regression coefficients.
Every observation contributes to every regime in proportion to the evidence that it belongs there. Assets are not hard-classified, and no observation is discarded. Because all assets share the same factor history and weights, the regressions for a whole cross-section are solved jointly. The cost of adding an asset is one weighted regression per regime, which makes the approach practical for universes of thousands of securities.
From loadings to regime-conditional moments
Combined with the regime-conditional factor means λ_s and covariances Ω_s
from the hidden Markov model, the loadings imply asset-level moments in each
regime:
μ_s = α_s + B_s λ_s
Σ_s = B_s Ω_s B_s′ + diag(σ²_s)
Weighting these by forecast regime probabilities gives the asset return distribution as a Gaussian mixture. Its mean and covariance are available in closed form.
Planned scope
- Hidden Markov regime identification on factor returns, with state alignment across refits and one-step regime forecasts.
- Vectorized RWLS estimation for large cross-sections, with effective sample sizes and sampling covariances of the regime-specific loadings.
- Regime-conditional and mixture moments of asset returns.
- Simulation tools for regime-switching factor models, for Monte Carlo evaluation of the estimators.
Applications include conditional beta estimation, regime-dependent risk models and portfolio construction. Portfolio optimization is one use of the estimated moments, not the purpose of the package.
Status
Under development. This release reserves the package name; the implementation will follow in a later version.
License
MIT
Metadata
Release files for rwls 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rwls-0.0.1.tar.gz | 3.1 kB | Without provenance | Details for rwls-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rwls-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for rwls-0.0.1-py3-none-any.whl |
Total release size: 6.8 kB
Release files / rwls-0.0.1.tar.gz
| Download URL | rwls-0.0.1.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53f359635d9cb4e8a672aef1c95da5e7e8385190efd351ae8e9fbf51e3bd36cf
|
|
BLAKE2b-256 checksum How to use checksums |
53b2fdeb816b0c138ea515d9289d8f013668febc4c2e8f7c09bfccb6d7206024
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / rwls-0.0.1-py3-none-any.whl
| Download URL | rwls-0.0.1-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
542eb5b6a6349c0ba9f67e0ff6c1bbe005a67eada29f316537e977a542188d8e
|
|
BLAKE2b-256 checksum How to use checksums |
cfce41118384876f3eea9adb6d3bc4c1a2eb541b7b19f21070a2ab58ef715860
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for rwls 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.