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.2.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.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: portfolio-stats-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 e92fd45ac8103b6b0dd6c7e4eee3d53492596de8af972cef07405b73e02e364b
MD5 6897cd5a671a418797eb73bec2bcf452
BLAKE2b-256 21015b51ad113fe562283a8e94b35435c430c16a165360c8476588eb2e16918e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for portfolio_stats-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fb0edcb8dcf2cf26926e6605580985a81297ba7c3332336a2590fc899bcb3b16
MD5 0177c4fd1ec5125269bd893c7aceb335
BLAKE2b-256 6079747426602fc1a6bc1a47026ac51e09907b51c7c9b8e369822711a240b715

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