Skip to main content

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 a csv file
  • gammas (list[int]): List of gammas values
  • timeHorizon (list[int]): List of time horizons
  • models (list[Model]): List of Model classes
  • dateFormat (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 = False
  • riskFactorPositions (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

  1. Clone project: git clone https://github.com/sidnand/portfolioperformance
  2. Install packages: pip install -r requirements.txt
  3. 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.

  1. Run pip install -e . to install the package locally.
  2. Make changes.
  3. Update version number in setup.py. Please use the Semantic Versioning 2.0.0 system. Click to learn more.
  4. Run python setup.py sdist bdist_wheel to create a python wheel.
  5. Create a pull-request!

Release History

  • 1.1.0

    • quadprog == 0.1.12 update
    • Update code for latest pandas version
  • 1.0.0

    • Initial release of the package
    • Python <= 3.9.9
    • quadprog <= 0.1.11

Metadata

Release files for portfolioperformance 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for portfolioperformance 1.1.0
File Interpreter ABI Platform Actions
portfolioperformance-1.1.0-py3-none-any.whl Python 3 none any Details for portfolioperformance-1.1.0-py3-none-any.whl

Release files / portfolioperformance-1.1.0-py3-none-any.whl

Download URL portfolioperformance-1.1.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2269c55ca9a34365b16da0003ce32ce22a728ff8b8835323ef3b2be931a2d199
BLAKE2b-256 checksum
How to use checksums
28f2c38cf2b4940ec57cbd1748d5c8bb0ee5cd9b2c72a7a9d93f90a2287d3bc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Security for portfolioperformance 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page