Skip to main content

Python package for PME (Public Market Equivalent) calculation

Project description

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

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

pypme-0.7.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

pypme-0.7.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pypme-0.7.0.tar.gz.

File metadata

  • Download URL: pypme-0.7.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.13 Windows/10

File hashes

Hashes for pypme-0.7.0.tar.gz
Algorithm Hash digest
SHA256 3a5b632fdee6fbfb624d7aa43a1c227060d8f562b70a4f3599c9faf391302876
MD5 6ead0307539f57e3152079f7d50a0f1c
BLAKE2b-256 d230b2a4be6379b26a7a21f20109e7e6e96632f7b0fcee1d386e07d85da22b3d

See more details on using hashes here.

File details

Details for the file pypme-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: pypme-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.13 Windows/10

File hashes

Hashes for pypme-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95024c0ce15dfd30c21b8cb449ef527811717a0fcfbb768432296cca90b995ac
MD5 4392bb48b343cbdc07d1be9c241b6198
BLAKE2b-256 817c0934af82c7d460c52eb13d2e8bd68796b610c2f855b74eb453d55cf6c2e8

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