Package: ml-investment
Machine learning tools for investment tasks.
The purpose of these tools is to obtain deeper analytics
about companies using fundamental, global market and other data.
This repo is core ofhttps://stocks.ml.Table of content📔 Documentation🛠 Installation⏳ Quick StartUse application modelCreate your own pipeline📦 Applications⭐ ContributingRun testsRun tests in Docker📔 DocumentationVisitRead the Docsto know more about Ml_investment library.🛠 InstallationPyPI version$pipinstallml-investmentLatest version from source$pipinstallgit+https://github.com/fartuk/ml_investmentConfigurationYou may use config file~/.ml_investment/config.jsonto change repo parameters i.e. downloading datasets pathes, models pathes etc.Private information (i.e. api tokens for private datasets downloading)
should be located at~/.ml_investment/secrets.json⏳ Quick StartUse application modelThere are several pre-defined fitted models atml_investment.applications.
It incapsulating data and weights downloading, pipeline creation
and model fitting. So you can just use it without knowing internal structure.fromml_investment.applications.fair_marketcap_yahooimportFairMarketcapYahoofair_marketcap_yahoo=FairMarketcapYahoo()fair_marketcap_yahoo.execute(['AAPL','FB','MSFT'])tickerdatefair_marketcap_yahooAAPL2020-12-315.173328e+11FB2020-12-318.442045e+11MSFT2020-12-314.501329e+11Create your own pipeline1. Download dataYou may download default datasets byml_investment.download_scriptsfromml_investment.download_scriptsimportdownload_yahoofromml_investment.utilsimportload_config# Config located at ~/.ml_investment/config.jsonconfig=load_config()download_yahoo.main(config['yahoo_data_path'])>>> 1365it [03:32,  6.42it/s]
>>> 1365it [01:49,  12.51it/s]2. Create dict with dataloadersYou may choose from defaultml_investment.data_loadersor wrote your own. Each dataloader should haveload(index)interface.fromml_investment.data_loaders.yahooimportYahooQuarterlyData,YahooBaseDatadata={}data['quarterly']=YahooQuarterlyData(config['yahoo_data_path'])data['base']=YahooBaseData(config['yahoo_data_path'])3. Define and fit pipelineYou may specify all steps of pipeline creation.
Base pipeline consist of the folowing steps:Create data dict(it was done in previous step)Define features. Features is a number of values
and characteristics that will be calculated for model trainig.
Default feature calculators are located atml_investment.featuresDefine targets. Target is a final goal of the pipeline, it should
represent some desired useful property.
Default target calculators are located atml_investment.targetsChoose model. Model is machine learning algorithm, core of the pipeline.
It also may incapsulate validation and other stuff.
You may use wrappers fromml_investment.modelsimportlightgbmaslgbmfromml_investment.utilsimportload_config,load_tickersfromml_investment.featuresimportQuarterlyFeatures,BaseCompanyFeatures,\FeatureMergerfromml_investment.targetsimportBaseInfoTargetfromml_investment.modelsimportLogExpModel,GroupedOOFModelfromml_investment.pipelinesimportPipelinefromml_investment.metricsimportmedian_absolute_relative_errorfc1=QuarterlyFeatures(data_key='quarterly',columns=['netIncome','cash','totalAssets','ebit'],quarter_counts=[2,4,10],max_back_quarter=1)fc2=BaseCompanyFeatures(data_key='base',cat_columns=['sector'])feature=FeatureMerger(fc1,fc2,on='ticker')target=BaseInfoTarget(data_key='base',col='enterpriseValue')base_model=LogExpModel(lgbm.sklearn.LGBMRegressor())model=GroupedOOFModel(base_model=base_model,group_column='ticker',fold_cnt=4)pipeline=Pipeline(data=data,feature=feature,target=target,model=model,out_name='my_super_model')tickers=load_tickers()['base_us_stocks']pipeline.fit(tickers,metric=median_absolute_relative_error)>>> {'metric_my_super_model': 0.40599471294301914}4. Inference your pipelineSinceml_investment.models.GroupedOOFModelwas used,
there are no data leakage and you may use pipeline on the same company tickers.pipeline.execute(['AAPL','FB','MSFT'])tickerdatemy_super_modelAAPL2020-12-318.170051e+11FB2020-12-313.898840e+11MSFT2020-12-313.540126e+11📦 ApplicationsCollection of pre-trained modelsFairMarketcapYahoo
[docs]FairMarketcapSF1
[docs]FairMarketcapDiffYahoo
[docs]FairMarketcapDiffSF1
[docs]MarketcapDownStdYahoo
[docs]MarketcapDownStdSF1
[docs]⭐ ContributingRun tests$cd/path/to/ml_investment&&pytestRun tests in Docker$dockerbuild.-ttests$dockerruntests