Skip to main content

pypme – Python package for PME (Public Market Equivalent) calculation

Based on the Modified PME method.

Example

from pypme import verbose_xpme
from datetime import date

pmeirr, assetirr, df = verbose_xpme(
    dates=[date(2015, 1, 1), date(2015, 6, 12), date(2016, 2, 15)],
    cashflows=[-10000, 7500],
    prices=[100, 120, 100],
    pme_prices=[100, 150, 100],
)

Will return 0.5525698793027238 and 0.19495150355969598 for the IRRs and produce this dataframe:

Example dataframe

Notes:

  • The cashflows are interpreted from a transaction account that is used to buy from an asset at price prices.
  • The corresponding prices for the PME are pme_prices.
  • The cashflows is extended with one element representing the remaining value, that's why all the other lists (dates, prices, pme_prices) need to be exactly 1 element longer than cashflows.

Variants

  • xpme: Calculate PME for unevenly spaced / scheduled cashflows and return the PME IRR only. In this case, the IRR is always annual.
  • verbose_xpme: Calculate PME for unevenly spaced / scheduled cashflows and return vebose information.
  • pme: Calculate PME for evenly spaced cashflows and return the PME IRR only. In this case, the IRR is for the underlying period.
  • verbose_pme: Calculate PME for evenly spaced cashflows and return vebose information.
  • tessa_xpme and tessa_verbose_xpme: Use live price information via the tessa library. See below.

tessa examples – using tessa to retrieve PME prices online

Use tessa_xpme and tessa_verbose_xpme to get live prices via the tessa library and use those prices as the PME. Like so:

from datetime import datetime, timezone
from pypme import tessa_xpme

common_args = {
    "dates": [
        datetime(2012, 1, 1, tzinfo=timezone.utc), 
        datetime(2013, 1, 1, tzinfo=timezone.utc)
    ],
    "cashflows": [-100],
    "prices": [1, 1],
}
print(tessa_xpme(pme_ticker="LIT", **common_args))  # source will default to "yahoo"
print(tessa_xpme(pme_ticker="bitcoin", pme_source="coingecko", **common_args))
print(tessa_xpme(pme_ticker="SREN.SW", pme_source="yahoo", **common_args))

Note that the dates need to be timezone-aware for these functions.

Garbage in, garbage out

Note that the package will only perform essential sanity checks and otherwise just works with what it gets, also with nonsensical data. E.g.:

from pypme import verbose_pme

pmeirr, assetirr, df = verbose_pme(
    cashflows=[-10, 500], prices=[1, 1, 1], pme_prices=[1, 1, 1]
)

Results in this df and IRRs of 0:

Garbage example df

Other noteworthy libraries

  • tessa: Find financial assets and get their price history without worrying about different APIs or rate limiting.
  • strela: A python package for financial alerts.

References

Metadata

Release files for pypme 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypme 0.7.0
File Size Uploaded Provenance Actions
pypme-0.7.0.tar.gz 5.0 kB Without provenance Details for pypme-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pypme 0.7.0
File Interpreter ABI Platform Actions
pypme-0.7.0-py3-none-any.whl Python 3 none any Details for pypme-0.7.0-py3-none-any.whl

Total release size: 11.1 kB

Release files / pypme-0.7.0.tar.gz

Download URL pypme-0.7.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3a5b632fdee6fbfb624d7aa43a1c227060d8f562b70a4f3599c9faf391302876
BLAKE2b-256 checksum
How to use checksums
d230b2a4be6379b26a7a21f20109e7e6e96632f7b0fcee1d386e07d85da22b3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.9.13 Windows/10

Release files / pypme-0.7.0-py3-none-any.whl

Download URL pypme-0.7.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95024c0ce15dfd30c21b8cb449ef527811717a0fcfbb768432296cca90b995ac
BLAKE2b-256 checksum
How to use checksums
817c0934af82c7d460c52eb13d2e8bd68796b610c2f855b74eb453d55cf6c2e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.9.13 Windows/10

Security for pypme 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page