Skip to main content

A quantitative finance library for portfolio analytics

Project description

arro

arro is a small quantitative-finance library for calculating return and risk metrics from periodic return series.

Input contract

Metric functions currently accept a pandas.Series whose:

  • values are finite decimal returns, such as 0.01 for 1%;
  • index is a unique, ascending pandas.DatetimeIndex;
  • values contain no missing data; and
  • returns are never below -1.0, because an unlevered investment cannot lose more than 100% of its value.

The metric layer is intentionally strict. Data-provider integrations should normalize prices and timestamps before calling these functions rather than silently repairing malformed data during a calculation.

import pandas as pd

import arro

returns = pd.Series(
    [0.01, -0.02, 0.015, 0.003, -0.005],
    index=pd.date_range("2024-01-01", periods=5, freq="B"),
)

print(arro.cumulative_return(returns))
print(arro.annualized_return(returns))
print(arro.volatility(returns))
print(arro.sharpe_ratio(returns, rf=0.04))
print(arro.sortino_ratio(returns, rf=0.04))
print(arro.max_drawdown(returns))
print(arro.calmar_ratio(returns))

Prices versus returns

arro metrics operate on returns, not prices. Convert a price series with Pandas before calculating metrics:

returns = prices.pct_change().dropna()

For adjusted equity data, use an adjusted price field so stock splits and distributions do not appear as investment losses. The correct field depends on the provider and its adjustment settings.

Annualization

When periods_per_year is omitted, arro infers these regular frequencies:

Frequency Periods per year
Business day or day 252
Week 52
Month 12
Quarter 4
Year 1

Pass periods_per_year explicitly for irregular or intraday data:

arro.volatility(minute_returns, periods_per_year=252 * 390)

Daily timestamps are ambiguous: US equity analytics normally use 252, while continuously traded assets may use 365. Use periods_per_year=365 for daily crypto data when that matches the intended methodology.

Metric conventions

  • Annualized return uses geometric compounding.
  • Volatility and Sharpe use sample standard deviation (ddof=1).
  • rf is an effective annual rate and is compounded into a periodic rate.
  • Sortino uses all observations when calculating target downside deviation.
  • Maximum drawdown is returned as a negative decimal.
  • Calmar divides annualized return by the absolute maximum drawdown.

Development

Install development dependencies and run:

python3 -m pytest

Pytest is configured to import code from src, avoiding accidental use of a globally installed arro package.

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

arro-0.1.5.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

arro-0.1.5-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file arro-0.1.5.tar.gz.

File metadata

  • Download URL: arro-0.1.5.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for arro-0.1.5.tar.gz
Algorithm Hash digest
SHA256 1d9a2c2885b87c6e5f28bd9b7aee9100dabba9a7ef4bc1ad3569162a0221885a
MD5 3ea1026994b76920c94b4b4ee6ce6d61
BLAKE2b-256 a5898d88ff940a7d82480d5c4b660c9b191ecedcd3751ad30823073285f3ca2d

See more details on using hashes here.

File details

Details for the file arro-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: arro-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for arro-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 069cce6117e6841751ac61d7b7f300f6001d55b6e7783a8e8f40a9115c7efb20
MD5 cac4a155cfbf043ba65cd887b6a5d9c9
BLAKE2b-256 9b940f037dd23865a6c56ed4be7882acfd132ad4cf5c6e879aaa02657787e485

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