factor model
Project description
This programme is built for back-testing factors.
Dependencies
python 3.5
pandas 0.23.0
numba 0.38.0
empyrical 0.5.0
pickle
multiprocessing
Example
Data Box: pre-process
from single_factor_model import data_box
db=data_box()\
.load_indestry(ind)\
.load_indexWeight(ind_weight)\
.load_suspend(sus)\
.load_adjPrice(price)\
.add_factor('factor0',factor0)\
.add_factor('factor1',factor1)\
.set_lag(freq='d',day_lag=1)\
.compile_data()
# freq can be 'd' or 'm', for detail please refer to db.set_lag doc.
Where price,ind,ind_weight,sus,factor0,factor1 are all dataframes with index as date (yyyymmdd,int) and column as tickers. You can save and load this data box object by db.save('path') and db.load('path').
Back Test
from single_factor_model import run_back_test
single process
Value=run_back_test(data_box=db,back_end=None,n=5,weight_path=None)
multi process
Value=run_back_test(data_box=db,back_end='loky',n=5,weight_path=None,verbose=50)
or
with __name__=='__main__':
Value=run_back_test(data_box=db,back_end='multiprocessing',n=5,weight_path=None)
To check detailed position of each portfolio each day, just assign weight_path.
Summary and Plot
summary by month
from single_factor_model import summary
S=summary(Value)
summary whole time period only
from single_factor_model import summary_total
S=summary_total(Value)
plot
run_plot(Value,show=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for single_factor_model-0.1.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f0e6c7883674474a3d039daa399f7fb694d3c5686b60e906659310ca71996d |
|
MD5 | dcf038d575e77c0a28e8d2b5985bff0e |
|
BLAKE2b-256 | 7c0ad6d105bb2f0278515ff50ebd11ecb3776a0e764730f1f655364a5dfef933 |
Close
Hashes for single_factor_model-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f62fd9e24796f620863feb874e4c0c3a530edc1fccaa5a4270581807da663e7 |
|
MD5 | 616f3ea5703bf2715fceec4bec6de1f2 |
|
BLAKE2b-256 | 2201a08c1bf570b4a0ed06ed8b9569c5f7e9cfc80e89a2ce8dc487c3a56ea33b |