Skip to main content

Calculate fundamental metrics of a portfolio's individual assets.

Project description

PortfolioStats

A python class to compute key portfolio statistics for assets based on their price data.

Introduction

PortfolioStats provides an organized method to calculate and view various portfolio metrics such as the Sharpe Ratio, cumulative returns, annualized returns, annualized volatility, and maximum drawdown.

Parameters

  • returns (pd.DataFrame): Return data for assets.
  • log (bool): Indicator to use logarithmic returns. Default is False.
  • annualization_factor (int): Factor to annualize returns and risk. Default is 252 (number of trading days in a year).

Calculations

Sharpe Ratio

$$\frac{E\bigl[r\bigl] \times A}{\sigma{\bigl[r\bigl]} \times \sqrt{A}}$$

Where:

  • $E\bigl[r\bigl]$ is the expected return of the asset.
  • $\sigma{\bigl[r\bigl]}$ is the standard deviation (risk) of the returns.

Cumulative Returns

Using simple returns: $$\text{Cumulative Return} = \prod^T_{i=1}(1+r_{i}) - 1$$

Using logarithmic returns: $$\text{Cumulative Return} = \sum^T_{i=1} r_{i}$$

Annualized Return

$$\text{Annualized Return} = E\bigl[r\bigl] \times \text{ }A$$

Annualized Volatility

$$\text{Annualized Volatility} = \sigma{\bigl[r\bigl]} \times \sqrt{A}$$

Maximum Drawdown

Using simple returns:

$$\text{MDD} = \min \left( \frac{\text{CR}{\text{trough}}}{\text{CR}{\text{peak}}} - 1 \right)$$

Using logarithmic returns:

$$\text{MDD} = \min \left( \text{CLR} - \text{CLR (max up to now)} \right)$$

Where:

  • $\text{CR}$ is the cumulative simple return series.
  • $\text{CLR}$ is the cumulative logarithmic return series.

Usage

Initialize the class with return data and optional parameters. Access the .info attribute to view the calculated portfolio statistics.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

portfolio-stats-1.0.3.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

portfolio_stats-1.0.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file portfolio-stats-1.0.3.tar.gz.

File metadata

  • Download URL: portfolio-stats-1.0.3.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for portfolio-stats-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ddf79e3308eea005433ecfcee86454ddecfffec455311f2233f26668dbf46731
MD5 7575e5e0a8b236cda7567b2411996813
BLAKE2b-256 9b93506eed0928f319ba5dd84984b2c810eed2a489c7fb9f00a940d5ea9d7c7f

See more details on using hashes here.

File details

Details for the file portfolio_stats-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for portfolio_stats-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b7666912feca31c0501afbc63354abf8a6d4203dc6b28beb5a4816e116e19b95
MD5 d51fefd1c2b70f85b3a602bb7e07484e
BLAKE2b-256 eefacb168a6f40a1ecba503a35a2d5631c79890982407070e9fadc3f873ea60c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page