Open wukan1986 opened 11 months ago
I feel this would be better suited to a plugin for now. Maybe at some point in the future we'll support linear regressions, but it would definitely be something more generic than a residual method.
Hi, @orlp
In linear regression, it seems that only residual
and y_hat
have the same shape as y
,
coef
has a different shape.
For quantitative researchers, residual
is the most important
I found this https://stackoverflow.com/a/74906705/1894479
Hi! I recently released a polars extension package: polars-ols dedicated to supporting linear regressions in rust exposed as polars expressions.
So it’ll do exactly what you want with mode=“residuals” and it’ll be really fast in the context of your cross sectional regressions as all will run natively in parallel in rust. It also supports regularization, sample weighting, null handling etc. which may be also relevant for your problem.
If you can try it out: pip install polars-ols
, let me know if works for you
Description
In quantitative investment, it is often necessary to market value neutralize and industry neutralize the data, which requires the use of multiple linear regression to find the residuals. I tried implementing it but the performance was low. So I hope it implement in Rust.
my UDF:
I expect method like this:
FYI: https://github.com/pola-rs/polars/issues/7994 https://github.com/abstractqqq/polars_ds_extension/blob/main/src/num_ext/ols.rs#L39 https://github.com/abstractqqq/polars_ds_extension/blob/main/tests/test_ext.py#L222