Tool to test the out-of-sample performance of portfolio optimization models
Project description
Portfolio Performance
Tool to test the out-of-sample performance of portfolio optimization models. Based on the paper: Optimal Versus Naive Diversification:
I have also developed a playground website for this package so you can easily run these models on your own data. Link to website
Usage
Installation
pip install portfolioperformance
Models
# Each model takes a name parameter
ew = EqualWeight("Equal Weight")
minVar = MinVar("Minimum Variance")
JagannathanMa = JagannathanMa("Jagannathan Ma")
minVarShortSellCon = MinVarShortSellCon("Minimum Variance with Short Sell Constrains")
kanZhouEw = KanZhouEw("Kan Zhou EW")
meanVar = MeanVar("Mean Variance (Markowitz)")
meanVarShortSellCon = MeanVarShortSellCon("Mean Variance with Short Sell Constrains")
kanZhou = KanZhou("Kan Zhou Three Fund")
bayesStein = BayesStein("Bayes Stein")
bayesSteinShortSellCon = BayesSteinShortSellCon("Bayes Stein with Short Sell Constrains")
macKinlayPastor = MacKinlayPastor("MacKinlay and Pastor")
Example
import numpy as np
from portfolioperformance import *
# Risk aversion levels
GAMMAS = [1, 2, 3, 4, 5, 10]
# Time horizons
TIME_HORIZON = [60, 120]
benchmark = <benchmark model>
# List of models
models = [
benchmark,
# <add other list of models>
]
app = App(<data path>, GAMMAS, TIME_HORIZON, models, dateFormat=<pandas datetime format>,
dateRange=["01011990", "01012010"], delim=<"," or "\s+">,
riskFactorPositions=[positions for risk factor column],
riskFreePosition=<risk free asset column>)
sr = app.getSharpeRatios()
sig = app.getStatisticalSignificanceWRTBenchmark(benchmark)
API
App Class
Parameters
path
(str
): Path to acsv
filegammas
(list[int]
): List of gammas valuestimeHorizon
(list[int]
): List of time horizonsmodels
(list[Model]
): List of Model classesdateFormat
(str
): Pandas date time format, default = "%Y-%m-%d"dateRange
([str, str]
): Start and end date, default = []delim
(str
): Delimitation type, either "," or "\s+" (whitespace), default = ","logScale
(bool
): Whether or not data is in log-scale, default = FalseriskFactorPositions
(list
): Risk factor asset column positions (where position 1 is the date column), default = []riskFreePosition
(int
): Risk free asset column position, default = 1
Methods
getSharpeRatios() -> dict[str, float]
Get the sharpe ratios
- Returns: -
dict[str, float]
: A dictionary with model name and sharpe ratio as a key-valued pair
getStatisticalSignificanceWRTBenchmark(benchmark) -> dict[str, float]
Get the statistical significance with respect to a benchmark model
-
Parameters:
benchmark
(Model
): Benchmark model
- Returns:
dict[str, float]
: A dictionary with model name and sharpe ratio as a key-valued pair
Development
Setup
- Clone project:
git clone https://github.com/sidnand/portfolioperformance
- Install packages:
pip install -r requirements.txt
- Make project:
setapp
- Make changes!
Folder Structure
.
|-- __init__.py # import /src/app.py and all models
|-- /src
|-- app.py # code for running all the optimiation models
|-- model.py # parent class to all the models
|-- modelNoGamma.py # class for models that don't take extra parameters
|-- modelGamma.py # class for models that take an extra gamma parameter; gamma is a list of constants for the investors risk-aversion level
|-- ./models # all the models
|-- ./utils
|-- filter.py # includes a function that is used to filter the parameters passed to a function
|-- quadprog.py # quadratic programming
|-- sharedOptions.py # models options that are in common with >2 models
|-- statistics.py # statistics functions
Create Pull-Request
Please create a pull-request to include your changes onto this repo. These changes will be reflected on the playground website linked above.
- Run
pip install -e .
to install the package locally. - Make changes.
- Update version number in
setup.py
. Please use the Semantic Versioning 2.0.0 system. Click to learn more. - Run
python setup.py sdist bdist_wheel
to create a python wheel. - Create a pull-request!
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 Distribution
portfolioperformance-1.0.0.tar.gz
(12.2 kB
view hashes)
Built Distribution
Close
Hashes for portfolioperformance-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5299687ee710810e5c8179e537f81cf7e6c151d261e788b5a858b0e40bab7a9 |
|
MD5 | 862daa524359ecfaf3c960e989c54de5 |
|
BLAKE2b-256 | ddb940419fc4d14595aaedbfec1b41d5a5a6dba97065ed1d587c756ca2faf23f |
Close
Hashes for portfolioperformance-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e033306dc9645af007eec879eab26ea7fc6107c5c2bf5e9fee05381eaea86b40 |
|
MD5 | fa0a4de063221f5f609dd413453e0ff2 |
|
BLAKE2b-256 | da82756823b165022aa8934a623a54d8d8381a58a27ce7480c9b3efe3a3185ed |