Skip to content
/ pypme Public

A Python package for PME (Public Market Equivalent) calculation

License

Notifications You must be signed in to change notification settings

ymyke/pypme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pypme – Python library 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.
  • investpy_pme and investpy_verbose_pme: Use price information from Investing.com. See below.

Investpy examples -- using investpy to retrieve PME prices online

Use investpy_pme and investpy_verbose_pme to use a ticker from Investing.com and compare with those prices. Like so:

from datetime import date
from pypme import investpy_pme

common_args = {
    "dates": [date(2012, 1, 1), date(2013, 1, 1)],
    "cashflows": [-100],
    "prices": [1, 1],
}
print(investpy_pme(pme_ticker="Global X Lithium", pme_type="etf", **common_args))
print(investpy_pme(pme_ticker="bitcoin", pme_type="crypto", **common_args))
print(investpy_pme(pme_ticker="SRENH", pme_type="stock", pme_country="switzerland", **common_args))

Produces:

-0.02834024870462727
1.5031336254547634
0.3402634808264912

The investpy functions take the following parameters:

  • pme_type: One of stock, etf, fund, crypto, bond, index, certificate. Defaults to stock.
  • pme_ticker: The ticker symbol/name.
  • pme_country: The ticker's country of residence. Defaults to united states.

Check out the Investpy project for more details.

Garbage in, garbage out

Note that the library 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

References