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()
db.load_indestry(ind)
db.load_indexWeight(ind_weight)
db.load_suspend(sus)
db.load_adjPrice(price)
db.add_factor('factor0',factor0)
db.add_factor('factor1',factor1)
db.set_lag(freq='d',day_lag=1)
# freq can be 'd' or 'm', for detail please refer to db.set_lag doc.
db.compile_data()
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for single_factor_model-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e41f6bef59e7889c6c9949736f616deb860455df4b906a7e98e0a3d2c341894d |
|
MD5 | a7c769c7b1e0b72464802a63d7a36e1b |
|
BLAKE2b-256 | 01ab355a4406b2a6bc88fcf50f3cf30a2c5f2930deefad7d4da77d93d156e69e |