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

Uploaded Python 3

File details

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

File metadata

  • Download URL: portfolio-stats-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 fcd961b4fccaf9604d7e79dddd0059e75873a1e4f485fe5de7dce55ef131960f
MD5 03dabad8663fecf3dcc58f8448adf86f
BLAKE2b-256 4ba1b8d6d4bd5ec249dd55326d81955c5b75b55a50966b49788f21ddc2482d18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for portfolio_stats-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4481f6001ce0ed03877e750474031d80c621f76ae41d2941ac69d658e53539a6
MD5 f09915fea1e47c1212d5cf9fb8b13eb1
BLAKE2b-256 8eab82ecd508d8b3f322e8d6457c95ab0c0ccb2d19ea2f42380c2dd9794e42c9

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