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,Turnover=run_back_test(data_box=db,back_end=None,n=5,weight_path=None,double_side_cost=0.003)
multi process
Value,Turnover=run_back_test(data_box=db,back_end='loky',n=5,weight_path=None,verbose=50,double_side_cost=0.003)
or
with __name__=='__main__':
Value,Turnover=run_back_test(data_box=db,back_end='multiprocessing',n=5,weight_path=None,double_side_cost=0.003)
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
from single_factor_model import run_plot,run_plot_turnover
run_plot(Value,show=True)
run_plot_turnover(Turnover,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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file single_factor_model-0.1.4-py3-none-any.whl.
File metadata
- Download URL: single_factor_model-0.1.4-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbe66f2cfbfe71d55317ca422030ec157c7a7b273fa72fe424b72a3604254283
|
|
| MD5 |
5565047f89254a46a89e2cb559a16706
|
|
| BLAKE2b-256 |
682a81e52bfe408c10aa5e8c82aa989ad1d62e0f411aeecb4260853aa093d1d9
|