Skip to content

This is a finance factor model, risk model, portfolio optimization, strategies research library.

Notifications You must be signed in to change notification settings

leolle/simulate

Repository files navigation

Simulate is a python library for risk modeling, find alpha, portfolio optimization and simulation. It is written in Python, its major dependencies are cvxpy and pandas.

The simulator is a package for simulating and optimizing multi-period investment, it is able to simulate the evolution of a portfolio, taking into account asset returns, transaction costs, and holding costs. The package includes simple but reasonable models of transaction cost based on asset bid-ask spread, volume, and volatility.

I consider a basic model of multi-period trading, which can be used to evaluate the performance of a trading strategy. We describe a framework for single-period optimization, where the trades in each period are found by solving a convex optimization problem that trades off expected return, risk, transaction costs.

Simulate provides functionality for implementing trading strategies using the convex optimization package CVXPY.

The package relies on Pandas for data handling (e.g., prices, returns, volumes). Our simple examples show how Quandl can be used to import open source financial data, but any other source can be used instead.

See the examples for basic usage.

1 Installation

  1. Install Anaconda
  2. Install required packages
pip install -r requirements.txt
  1. Install cvxpy (if it doesn’t work, use pip install)
conda install -c conda-forge lapack
conda install -c cvxgrp cvxpy
  1. Test the installation with nose
conda install nose
nosetests simulate
  1. add build-in packages into Python path.
export PYTHONPATH=./lib/:$PYTHONPATH

2 Risk Model:

Risk Modeling

./risk_model/images/input_workflow.png

Risk model is a multi-factor model using linear regression to measure the overall risk associated with a security relative to the market.

It is used for multiple ways, e.g. portfolio optimization, portfolio return &risk contribution.

3 factor model

Factor Model

./factor/images/factor_model.jpg

To find alpha by a factor.

  1. Select stocks by quantile using a factor screener.
  2. Generate a portfolio with equally weighted stocks.

4 optimization:

There are three optimization strategies provided in the library, mvo, black litterman and risk parity.

The fundamental introduction of these optimization methods and how-to run instruction are listed under below.

./optimization/mean_variance/images/markowitz.png

./optimization/risk_parity/images/balanced_risk_allocation.png

./optimization/black_litterman/images/black_litterman.png

5 simulation/backtest

backtest

Backtest a portfolio with data like price, volume, stock portfolio weight, trading cost, dividend, splits, etc.

6 strategy

About

This is a finance factor model, risk model, portfolio optimization, strategies research library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages