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

  • prices (pd.DataFrame): Price 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

Returns

Using simple returns: $$r_{t} = \frac{P_{t} - P_{t-1}}{P_{t-1}}$$

Using logarithmic returns: $$ r_{t} = ln \Bigl(\frac{P_{t}}{P_{t-1}}\Bigl)$$

Where:

  • $P_{t}$ is the price of the asset at time $t$

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 price 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.0.tar.gz (3.0 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.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: portfolio-stats-1.0.0.tar.gz
  • Upload date:
  • Size: 3.0 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.0.tar.gz
Algorithm Hash digest
SHA256 1ad77da45ff8144c8f52a367248404534be0e1216b5c5505cc1af0dfb35a3b02
MD5 b1c3a90026b2cfbd9510a531dc9c72a3
BLAKE2b-256 445652fe16343d6456067c78e0d8773348dddb0c505afe7b394091449708c56f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for portfolio_stats-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0963b2fd3dca586ad19ba859293f96e9b5820da829a404733cd0fea922763af
MD5 ad0eb7af81efad7a91934a8decf07dbb
BLAKE2b-256 7fcf0fe8e26a5404bcaefb5bc8376ff46a612063c866bdc5a19dfb9713af8bbc

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