Home

Awesome

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:

Variants

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

References