1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
This release is a pre-release and may not be stable for production use.
Multi Factor Model
This project is to merge alpha factors into one factor with machine learning techniques.
Dependencies
python 3.5
pandas 0.22.0
numpy 1.14.3
pickle
sklearn 0.19.1
databox
Example
Preprocessing data
First create a databox object with original factors and market info. More can be found in project databox
from databox import databox
db=databox()\
.load_indestry(ind)\
.load_indexWeight(ind_weight)\
.load_suspend(sus)\
.load_adjPrice(price)\
.set_lag(freq='d',day_lag=1)
for fac_name,fac_df in factors_dictionary.items():
db.add_factor(fac_name,fac_df)
db.align_data()\
.factor_ind_neutral()\
.factor_size_neutral()
Then custmize your data for model training
sp=sample_pipeline()\
.set_fw_return_n(1)\
.set_sample_n(1)\
.factor_rank()\
.factor_zscore()\
.fw_return_ind_neutral()\
.fw_return_rank()\
.fw_return_I(thresh=2000)
Note all returns are multiplied by 100 for better modeling.
Now create sample as
X_train,y_train=sp.train_set(db)
X_test,y_test=sp.test_set(db)
X_test_all=sp.test_X(db)
Modeling
Classification Method
from sklearn.ensemble import RandomForestClassifier
clf=RandomForestClassifier()
tn,tt,ml=clf_model(clf,X_train,y_train,X_test,y_test)
Where y can be 0/1 or float and result tn (train) and tt (test) would be different depending on this. If clf is a tree based model, ml would be feature importance. If clf is a linear model, ml would be coeffient.
We can also creat a model by combining several models.
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
clf1=RandomForestClassifier()
clf2=LogisticRegression()
clf3=SVC()
from multi_factor_model import combine_clf_models
CLF=combine_clf_models()\
.add_clf('rf',clf1)\
.add_clf('lr',clf2)\
.add_clf('svc',clf3,weight=2)#default weight is 1
tn,tt,ml=clf_model(CLF,X_train,y_train,X_test,y_test)
Regression Method Same as Classification method with reg_model as the replacement of clf_model and combine_reg_models as that of combine_clf_models
Combined Factor
import pandas as pd
value=CLF.predict_proba(X_test_all)
factor=pd.Series(value[:,1],index=X_test_all.index)
Metadata
Release files for multi-factor-model 0.0.0a5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| multi_factor_model-0.0.0a5.tar.gz | 7.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| multi_factor_model-0.0.0a5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.5 kB
Release files / multi_factor_model-0.0.0a5.tar.gz
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | multi_factor_model-0.0.0a5.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
314ae7e24a2da837bf394d843180c497d0e0e009f97ed99b038d883c989d0c8d
|
|
BLAKE2b-256 checksum How to use checksums |
f5a01778ac294ce0494a65486b81481d5eeff65355ddd9db55fde9c736dd6650
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.14.2 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.5
|
Release files / multi_factor_model-0.0.0a5-py3-none-any.whl
| Download URL | multi_factor_model-0.0.0a5-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9e890ae3070a5756dba0376fc0a159d6aa843fd66152939ee591cac5adbde10
|
|
BLAKE2b-256 checksum How to use checksums |
76a9318501b84fc4516f451d1387dc679528c6468f09c6b39c523acabefda76e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.14.2 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.5
|
Security for multi-factor-model 0.0.0a5
Upload timing
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
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.