rwls 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rwls/__init__.py +11 -0
- rwls-0.0.1.dist-info/METADATA +96 -0
- rwls-0.0.1.dist-info/RECORD +5 -0
- rwls-0.0.1.dist-info/WHEEL +4 -0
- rwls-0.0.1.dist-info/licenses/LICENSE +21 -0
rwls/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Regime-weighted least squares (RWLS) for regime-dependent factor models.
|
|
2
|
+
|
|
3
|
+
Latent market regimes are identified with a multivariate Gaussian hidden Markov
|
|
4
|
+
model fitted to common factor returns. Each asset's factor loadings and residual
|
|
5
|
+
variance are then estimated separately for every regime by weighted least squares,
|
|
6
|
+
with each observation weighted by its posterior regime probability.
|
|
7
|
+
|
|
8
|
+
This release reserves the package name. The implementation is under development.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "0.0.1"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rwls
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Regime-weighted least squares: regime-dependent factor models estimated with hidden Markov posterior probabilities.
|
|
5
|
+
Author: Francisco Ibanez
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: factor models,financial econometrics,hidden Markov model,regime switching,weighted least squares
|
|
9
|
+
Classifier: Development Status :: 1 - Planning
|
|
10
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# rwls
|
|
19
|
+
|
|
20
|
+
Regime-weighted least squares (RWLS) for estimating regime-dependent factor models.
|
|
21
|
+
|
|
22
|
+
## The estimator
|
|
23
|
+
|
|
24
|
+
Factor models usually assume that an asset's exposures to common risk factors are
|
|
25
|
+
constant. In practice, betas, factor premia and idiosyncratic risk shift with
|
|
26
|
+
market conditions. RWLS estimates a separate factor model for every asset in every
|
|
27
|
+
latent market regime, without fitting a regime-switching model asset by asset.
|
|
28
|
+
|
|
29
|
+
Estimation proceeds in two stages:
|
|
30
|
+
|
|
31
|
+
1. **Regime identification.** A multivariate Gaussian hidden Markov model is fitted
|
|
32
|
+
to a small set of common factor returns `f_t`. Its posterior probabilities
|
|
33
|
+
`γ_t(s) = P(S_t = s | data)` measure how strongly each period belongs to each
|
|
34
|
+
regime `s`.
|
|
35
|
+
|
|
36
|
+
2. **Regime-weighted regressions.** For each asset `i` and regime `s`, the
|
|
37
|
+
loadings solve a weighted least-squares problem in which each observation is
|
|
38
|
+
weighted by its posterior regime probability:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
(α_is, β_is) = argmin Σ_t γ_t(s) · (r_it − α − β′ f_t)²
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The regime-specific residual variance is measured on the regime's effective
|
|
45
|
+
sample, the posterior mass `Σ_t γ_t(s)`:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
σ²_is = Σ_t γ_t(s) · e_it² / (Σ_t γ_t(s) − k)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
where `k` is the number of regression coefficients.
|
|
52
|
+
|
|
53
|
+
Every observation contributes to every regime in proportion to the evidence that
|
|
54
|
+
it belongs there. Assets are not hard-classified, and no observation is discarded.
|
|
55
|
+
Because all assets share the same factor history and weights, the regressions
|
|
56
|
+
for a whole cross-section are solved jointly. The cost of adding an asset is one
|
|
57
|
+
weighted regression per regime, which makes the approach practical for universes
|
|
58
|
+
of thousands of securities.
|
|
59
|
+
|
|
60
|
+
## From loadings to regime-conditional moments
|
|
61
|
+
|
|
62
|
+
Combined with the regime-conditional factor means `λ_s` and covariances `Ω_s`
|
|
63
|
+
from the hidden Markov model, the loadings imply asset-level moments in each
|
|
64
|
+
regime:
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
μ_s = α_s + B_s λ_s
|
|
68
|
+
Σ_s = B_s Ω_s B_s′ + diag(σ²_s)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Weighting these by forecast regime probabilities gives the asset return
|
|
72
|
+
distribution as a Gaussian mixture. Its mean and covariance are available in
|
|
73
|
+
closed form.
|
|
74
|
+
|
|
75
|
+
## Planned scope
|
|
76
|
+
|
|
77
|
+
- Hidden Markov regime identification on factor returns, with state alignment
|
|
78
|
+
across refits and one-step regime forecasts.
|
|
79
|
+
- Vectorized RWLS estimation for large cross-sections, with effective sample
|
|
80
|
+
sizes and sampling covariances of the regime-specific loadings.
|
|
81
|
+
- Regime-conditional and mixture moments of asset returns.
|
|
82
|
+
- Simulation tools for regime-switching factor models, for Monte Carlo
|
|
83
|
+
evaluation of the estimators.
|
|
84
|
+
|
|
85
|
+
Applications include conditional beta estimation, regime-dependent risk models
|
|
86
|
+
and portfolio construction. Portfolio optimization is one use of the estimated
|
|
87
|
+
moments, not the purpose of the package.
|
|
88
|
+
|
|
89
|
+
## Status
|
|
90
|
+
|
|
91
|
+
Under development. This release reserves the package name; the implementation
|
|
92
|
+
will follow in a later version.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
rwls/__init__.py,sha256=7uNJ0gJ1gvIgoUFtu15ffQEIwOISuPxp_h-SQWdNC38,498
|
|
2
|
+
rwls-0.0.1.dist-info/METADATA,sha256=vG8QuNdKIMGy1HEDf1XnyRfikT3g-mrVJos6f41B0r0,3683
|
|
3
|
+
rwls-0.0.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
4
|
+
rwls-0.0.1.dist-info/licenses/LICENSE,sha256=Qa-xO-3w0_VuWuAQtw8tI8IxGP5dP74YBvN8HFaLb2E,1073
|
|
5
|
+
rwls-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Francisco Ibanez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|