Skip to content
/ skfin Public
forked from schampon/skfin

Machine learning for portfolio management and trading with scikit-learn

License

Notifications You must be signed in to change notification settings

cominho/skfin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

skfin

Machine learning for portfolio management and trading with scikit-learn

Motivation

This repo contains a set of python notebooks that cover topics related to machine-learning for portfolio management as illustrated by the figure below.

The concatenation of all notebooks as a single pdf file can be found here.

Example

An example to run a simple backtest with learning using a Ridge estimator:

from skfin import Backtester, MeanVariance, Ridge
from skfin.datasets import load_kf_returns
from skfin.plot import line
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

estimator = make_pipeline(StandardScaler(with_mean=False), Ridge(), MeanVariance())

returns_data = load_kf_returns(cache_dir="data")
ret = returns_data["Monthly"]["Average_Value_Weighted_Returns"][:"1999"]

transform_X = lambda x: x.rolling(12).mean().fillna(0)
transform_y = lambda x: x.shift(-1)
features = transform_X(ret)
target = transform_y(ret)

pnl_ = Backtester(estimator).train(features, target, ret)
line(pnl_, cumsum=True, title="Ridge")

Installation

git clone https://github.com/schampon/skfin.git 
cd skfin
./create_env.sh

About

Machine learning for portfolio management and trading with scikit-learn

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 92.5%
  • Python 7.5%