Skip to main content

The Ultimate Metric Library

Project description

Metric Forge

Description of the image

Metric Forge is your ultimate toolkit for measuring and evaluating performance across various business domains.

Disclaimer

Metric Forge provides a collection of calculations across various domains, including finance, mortgage, marketing, and more. While every effort has been made to ensure the accuracy and reliability of the calculations and methods provided, Metric Forge is intended for informational and educational purposes only.

Important Notice:

No Warranty: The calculations and methods provided in this package are offered "as-is" without any guarantees or warranties of any kind, either express or implied. The package's creators do not assume any responsibility for errors or omissions or for any damages resulting from the use of the package.

Not Professional Advice: The results produced by the package should not be considered as professional financial, investment, legal, or any other type of advice. Users should consult with qualified professionals before making any decisions based on the outputs generated by this package.

Use at Your Own Risk: Users of Metric Forge assume full responsibility for the use of the package and its results. The creators of the package shall not be held liable for any decisions made based on the information provided or for any consequences arising from the use of the package.

By using this package, you acknowledge and agree to this disclaimer. If you do not agree, please refrain from using the Metric Forge package.

Getting Started

install the package via pip

pip install metric-forge

Ecommerce

You can use Ecommerce Metrics in two different ways:

  • With Polars
  • As a Single Value Function (SVF)

Metric Forge extends the Polars expression library; making it possible to perform row-wise-calculations for various metrics. In addition to mass calculations, you can also perform single value calculations that return just one value.

from metric_forge.ecommerce import * 
import polars as pl
data = pl.read_csv('datasets/ecommerce_metrics.csv')
data.head()
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (5, 15)
monthtotal_revenuenumber_of_orderscost_of_acquisitionnew_customerscarts_createdcompleted_purchasesrevenue_from_adsadvertising_spendnum_conversionsnum_visitorsrevenue_per_customeraverage_customer_lifetimenum_customers_losttotal_customers_beginning
strf64i64f64i64i64i64f64f64i64i64f64f64i64i64
"2023-01"87454.01188599122958.3505594061969142581339.9576965390.91016930013154202.4273293.1593642393306
"2023-02"145071.43064191318736.8742062341506142176875.08340215585.03701842714762116.1734361.8122451244680
"2023-03"123199.394181130528355.5868421201497965116505.48219114872.03795436710056384.2651564.7714141774675
"2023-04"109865.8484288514184.8158242819631102106008.04638112337.20436813219948144.3563283.3954622992972
"2023-05"65601.86404469118764.339456266100980197258.8099125351.99556814713110275.7346013.779142963768

Customer Acquisition Cost

data.with_columns(pl.col('*').forge_ecommerce.customer_acquisition_cost('cost_of_acquisition', 'new_customers'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (12, 16)
monthtotal_revenuenumber_of_orderscost_of_acquisitionnew_customerscarts_createdcompleted_purchasesrevenue_from_adsadvertising_spendnum_conversionsnum_visitorsrevenue_per_customeraverage_customer_lifetimenum_customers_losttotal_customers_beginningcustomer_acquisition_cost
strf64i64f64i64i64i64f64f64i64i64f64f64i64i64f64
"2023-01"87454.01188599122958.3505594061969142581339.9576965390.91016930013154202.4273293.159364239330656.547661
"2023-02"145071.43064191318736.8742062341506142176875.08340215585.03701842714762116.1734361.812245124468080.072112
"2023-03"123199.394181130528355.5868421201497965116505.48219114872.03795436710056384.2651564.7714141774675236.296557
"2023-04"109865.8484288514184.8158242819631102106008.04638112337.20436813219948144.3563283.395462299297233.142093
"2023-05"65601.86404469118764.339456266100980197258.8099125351.99556814713110275.7346013.77914296376870.54263
"2023-08"136617.61457766033555.2788421881108601116872.97765424754.3885133928840290.1480892.1825352803479178.485526
"2023-09"110111.50117495915990.2134654151975139584633.08229220148.999371986028325.3102291.421977239343438.530635
"2023-10"120807.2577881325427.03315211380066954839.92638228157.52196327112385378.2064352.8261382742648225.017992
"2023-11"52058.4494352127772.4370663412005121556664.61551321276.9256384595502155.7325821.873762178231781.444097
"2023-12"146990.98521675211393.512382364170485544874.02451627873.99188931311910341.7669522.66604170325731.300858

Average Order Value

data.with_columns(pl.col('*').forge_ecommerce.average_order_value('total_revenue', 'number_of_orders'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (12, 16)
monthtotal_revenuenumber_of_orderscost_of_acquisitionnew_customerscarts_createdcompleted_purchasesrevenue_from_adsadvertising_spendnum_conversionsnum_visitorsrevenue_per_customeraverage_customer_lifetimenum_customers_losttotal_customers_beginningaverage_order_value
strf64i64f64i64i64i64f64f64i64i64f64f64i64i64f64
"2023-01"87454.01188599122958.3505594061969142581339.9576965390.91016930013154202.4273293.159364239330688.248246
"2023-02"145071.43064191318736.8742062341506142176875.08340215585.03701842714762116.1734361.8122451244680158.895324
"2023-03"123199.394181130528355.5868421201497965116505.48219114872.03795436710056384.2651564.771414177467594.405666
"2023-04"109865.8484288514184.8158242819631102106008.04638112337.20436813219948144.3563283.3954622992972124.142202
"2023-05"65601.86404469118764.339456266100980197258.8099125351.99556814713110275.7346013.77914296376894.937575
"2023-08"136617.61457766033555.2788421881108601116872.97765424754.3885133928840290.1480892.1825352803479206.996386
"2023-09"110111.50117495915990.2134654151975139584633.08229220148.999371986028325.3102291.4219772393434114.819084
"2023-10"120807.2577881325427.03315211380066954839.92638228157.52196327112385378.2064352.8261382742648148.594413
"2023-11"52058.4494352127772.4370663412005121556664.61551321276.9256384595502155.7325821.873762178231799.920248
"2023-12"146990.98521675211393.512382364170485544874.02451627873.99188931311910341.7669522.666041703257195.466736

Cart Abandonment Rate

data.with_columns(pl.col('*').forge_ecommerce.cart_abandonment_rate('carts_created', 'completed_purchases'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (12, 16)
monthtotal_revenuenumber_of_orderscost_of_acquisitionnew_customerscarts_createdcompleted_purchasesrevenue_from_adsadvertising_spendnum_conversionsnum_visitorsrevenue_per_customeraverage_customer_lifetimenum_customers_losttotal_customers_beginningcart_abandonment_rate
strf64i64f64i64i64i64f64f64i64i64f64f64i64i64f64
"2023-01"87454.01188599122958.3505594061969142581339.9576965390.91016930013154202.4273293.159364239330627.628238
"2023-02"145071.43064191318736.8742062341506142176875.08340215585.03701842714762116.1734361.81224512446805.64409
"2023-03"123199.394181130528355.5868421201497965116505.48219114872.03795436710056384.2651564.771414177467535.537742
"2023-04"109865.8484288514184.8158242819631102106008.04638112337.20436813219948144.3563283.395462299297243.861437
"2023-05"65601.86404469118764.339456266100980197258.8099125351.99556814713110275.7346013.77914296376820.61447
"2023-08"136617.61457766033555.2788421881108601116872.97765424754.3885133928840290.1480892.182535280347945.758123
"2023-09"110111.50117495915990.2134654151975139584633.08229220148.999371986028325.3102291.421977239343429.367089
"2023-10"120807.2577881325427.03315211380066954839.92638228157.52196327112385378.2064352.826138274264816.375
"2023-11"52058.4494352127772.4370663412005121556664.61551321276.9256384595502155.7325821.873762178231739.401496
"2023-12"146990.98521675211393.512382364170485544874.02451627873.99188931311910341.7669522.66604170325749.823944

Return on Advertising Spend

data.with_columns(pl.col('*').forge_ecommerce.return_on_advertising_spend('revenue_from_ads', 'advertising_spend'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (12, 16)
monthtotal_revenuenumber_of_orderscost_of_acquisitionnew_customerscarts_createdcompleted_purchasesrevenue_from_adsadvertising_spendnum_conversionsnum_visitorsrevenue_per_customeraverage_customer_lifetimenum_customers_losttotal_customers_beginningreturn_on_advertising_spend
strf64i64f64i64i64i64f64f64i64i64f64f64i64i64f64
"2023-01"87454.01188599122958.3505594061969142581339.9576965390.91016930013154202.4273293.159364239330615.088353
"2023-02"145071.43064191318736.8742062341506142176875.08340215585.03701842714762116.1734361.81224512446804.932621
"2023-03"123199.394181130528355.5868421201497965116505.48219114872.03795436710056384.2651564.77141417746757.833861
"2023-04"109865.8484288514184.8158242819631102106008.04638112337.20436813219948144.3563283.39546229929728.59255
"2023-05"65601.86404469118764.339456266100980197258.8099125351.99556814713110275.7346013.77914296376818.172438
"2023-08"136617.61457766033555.2788421881108601116872.97765424754.3885133928840290.1480892.18253528034794.721303
"2023-09"110111.50117495915990.2134654151975139584633.08229220148.999371986028325.3102291.42197723934344.200362
"2023-10"120807.2577881325427.03315211380066954839.92638228157.52196327112385378.2064352.82613827426481.947612
"2023-11"52058.4494352127772.4370663412005121556664.61551321276.9256384595502155.7325821.87376217823172.663196
"2023-12"146990.98521675211393.512382364170485544874.02451627873.99188931311910341.7669522.6660417032571.609889

Conversion Rate

data.with_columns(pl.col('*').forge_ecommerce.conversion_rate('num_conversions', 'num_visitors'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (12, 16)
monthtotal_revenuenumber_of_orderscost_of_acquisitionnew_customerscarts_createdcompleted_purchasesrevenue_from_adsadvertising_spendnum_conversionsnum_visitorsrevenue_per_customeraverage_customer_lifetimenum_customers_losttotal_customers_beginningconversion_rate
strf64i64f64i64i64i64f64f64i64i64f64f64i64i64f64
"2023-01"87454.01188599122958.3505594061969142581339.9576965390.91016930013154202.4273293.15936423933062.280675
"2023-02"145071.43064191318736.8742062341506142176875.08340215585.03701842714762116.1734361.81224512446802.892562
"2023-03"123199.394181130528355.5868421201497965116505.48219114872.03795436710056384.2651564.77141417746753.649562
"2023-04"109865.8484288514184.8158242819631102106008.04638112337.20436813219948144.3563283.39546229929720.66172
"2023-05"65601.86404469118764.339456266100980197258.8099125351.99556814713110275.7346013.7791429637681.121281
"2023-08"136617.61457766033555.2788421881108601116872.97765424754.3885133928840290.1480892.18253528034794.434389
"2023-09"110111.50117495915990.2134654151975139584633.08229220148.999371986028325.3102291.42197723934343.284672
"2023-10"120807.2577881325427.03315211380066954839.92638228157.52196327112385378.2064352.82613827426482.188131
"2023-11"52058.4494352127772.4370663412005121556664.61551321276.9256384595502155.7325821.87376217823178.342421
"2023-12"146990.98521675211393.512382364170485544874.02451627873.99188931311910341.7669522.6660417032572.628044

Customer Lifetime Value

data.with_columns(pl.col('*').forge_ecommerce.customer_lifetime_value('revenue_per_customer', 'average_customer_lifetime'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (12, 16)
monthtotal_revenuenumber_of_orderscost_of_acquisitionnew_customerscarts_createdcompleted_purchasesrevenue_from_adsadvertising_spendnum_conversionsnum_visitorsrevenue_per_customeraverage_customer_lifetimenum_customers_losttotal_customers_beginningcustomer_lifetime_value
strf64i64f64i64i64i64f64f64i64i64f64f64i64i64f64
"2023-01"87454.01188599122958.3505594061969142581339.9576965390.91016930013154202.4273293.1593642393306639.54169
"2023-02"145071.43064191318736.8742062341506142176875.08340215585.03701842714762116.1734361.8122451244680210.534716
"2023-03"123199.394181130528355.5868421201497965116505.48219114872.03795436710056384.2651564.77141417746751833.488253
"2023-04"109865.8484288514184.8158242819631102106008.04638112337.20436813219948144.3563283.3954622992972490.156408
"2023-05"65601.86404469118764.339456266100980197258.8099125351.99556814713110275.7346013.7791429637681042.039585
"2023-08"136617.61457766033555.2788421881108601116872.97765424754.3885133928840290.1480892.1825352803479633.258286
"2023-09"110111.50117495915990.2134654151975139584633.08229220148.999371986028325.3102291.4219772393434462.583676
"2023-10"120807.2577881325427.03315211380066954839.92638228157.52196327112385378.2064352.82613827426481068.863683
"2023-11"52058.4494352127772.4370663412005121556664.61551321276.9256384595502155.7325821.8737621782317291.805755
"2023-12"146990.98521675211393.512382364170485544874.02451627873.99188931311910341.7669522.666041703257911.164293

Product Development

You can use Product Development Metrics in two different ways:

  • With Polars
  • As a Single Value Function (SVF)

Metric Forge extends the Polars expression library; making it possible to perform row-wise-calculations for various metrics. In addition to mass calculations, you can also perform single value calculations that return just one value.

import polars as pl
data = pl.read_csv('datasets/customer-value.csv')
data
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (10, 3)
feature_nameimportance_scoresatisfaction_score
stri64i64
"Feature1"87
"Feature2"68
"Feature3"79
"Feature4"87
"Feature5"66
"Feature6"98
"Feature7"79
"Feature8"67
"Feature9"98
"Feature10"87

Underserved Customer Needs

from metric_forge.product_development import *


data.with_columns(pl.col('*').forge_product_dev.opportunity_score(importance_col='importance_score',satisfaction_col='satisfaction_score'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (10, 4)
feature_nameimportance_scoresatisfaction_scoreopportunity_score
stri64i64f64
"Feature1"879.0
"Feature2"684.0
"Feature3"795.0
"Feature4"879.0
"Feature5"666.0
"Feature6"9810.0
"Feature7"795.0
"Feature8"675.0
"Feature9"9810.0
"Feature10"879.0
data.with_columns(pl.col('*').forge_product_dev.customer_value_delivered(importance_col='importance_score',satisfaction_col='satisfaction_score'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (10, 4)
feature_nameimportance_scoresatisfaction_scorecustomer_value_delivered
stri64i64f64
"Feature1"870.56
"Feature2"680.48
"Feature3"790.63
"Feature4"870.56
"Feature5"660.36
"Feature6"980.72
"Feature7"790.63
"Feature8"670.42
"Feature9"980.72
"Feature10"870.56
data.with_columns(pl.col('*').forge_product_dev.opportunity_to_add_value(importance_col='importance_score',satisfaction_col='satisfaction_score'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (10, 4)
feature_nameimportance_scoresatisfaction_scoreopp_to_add_value
stri64i64f64
"Feature1"870.24
"Feature2"680.12
"Feature3"790.07
"Feature4"870.24
"Feature5"660.24
"Feature6"980.18
"Feature7"790.07
"Feature8"670.18
"Feature9"980.18
"Feature10"870.24
import polars as pl
data = pl.read_csv('datasets/customer-value-added.csv')
data
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (10, 4)
feature_nameimportance_scoresatisfaction_score_beforesatisfaction_score_after
stri64i64i64
"Feature1"879
"Feature2"989
"Feature3"798
"Feature4"878
"Feature5"668
"Feature6"989
"Feature7"798
"Feature8"676
"Feature9"988
"Feature10"877
data.with_columns(pl.col('*').forge_product_dev.customer_value_created(importance_col='importance_score'
                       ,satisfaction_after_col='satisfaction_score_after'
                       ,satisfaction_before_col='satisfaction_score_before'))
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (10, 5)
feature_nameimportance_scoresatisfaction_score_beforesatisfaction_score_aftercustomer_value_created
stri64i64i64f64
"Feature1"8790.16
"Feature2"9890.09
"Feature3"798-0.07
"Feature4"8780.08
"Feature5"6680.12
"Feature6"9890.09
"Feature7"798-0.07
"Feature8"676-0.06
"Feature9"9880.0
"Feature10"8770.0

Finance

The Finance module contains financial statement objects that you can call certain methods off of to get key financial metrics. You need to define these objects prior to running calcuations.

Income Statement

from metric_forge import *

income = IncomeStatement(revenue=10000,cogs=2000,expenses=3000,)
income.ebitda_margin()
0.5
income.earnings_per_share()
'Missing parameters: revenue, cogs, expenses, shares_outstanding'
income.net_profit_margin()
0.5

Balance Sheet

BalanceSheet(assets=300000,total_liabilities=150000,equity=150000).check_balance()
'The balance equation is correct: Assets - Liabilities = Equity'

Cash Flow

CashFlowStatement(operating_cash_flow=3000,capital_expenditures=4000).free_cash_flow()
-1000

Mortgage

The Mortgage module contains mortgage objects that you enable you to assess mortgage metrics. You need to define these objects prior to running calcuations.

from metric_forge.mortgage import *

mortgage = Mortgage(principal=360000,annual_interest_rate=5.75,start_date='2023-09-01',term_years=30,extra_principal_payment=200)
mortgage.calculate_monthly_payment()
2100.8622831967773
mortgage.generate_amortization_schedule()
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (360, 6)
payment_numberpayment_datepaymentinterest_paymentprincipal_paymentprincipal_remaining
i64strf64f64f64f64
1"2023-10-01"2100.8622831725.0375.862283359624.137717
2"2023-10-31"2100.8622831723.198993377.66329359246.474427
3"2023-11-30"2100.8622831721.389357379.472927358867.0015
4"2023-12-30"2100.8622831719.571049381.291234358485.710266
5"2024-01-29"2100.8622831717.744028383.118255358102.592011
356"2052-11-27"2100.86228349.6176322051.2446518303.739506
357"2052-12-27"2100.86228339.7887522061.0735316242.665975
358"2053-01-26"2100.86228329.9127742070.9495094171.716466
359"2053-02-25"2100.86228319.9894752080.8728082090.843657
360"2053-03-27"2100.86228310.0186262090.8436571.4501e-8
mortgage.calculate_principal_only_payment()
{'new_term_years': 24.14759462810461, 'time_saved_years': 5.85240537189539}
mortgage.refinance_assessment(RefinanceOption(new_loan_amount=350000,new_annual_interest_rate=5.25,new_term_years=30,associated_costs=5000))
{'Old Monthly Payment': 2100.8622831967773,
 'New Monthly Payment': 1932.7129574966407,
 'Monthly Savings': 168.14932570013661,
 'Break-Even Point (months)': 29.735474579996712,
 'Total Savings (over the loan term)': 55533.75725204917,
 'Should Refinance': True}

Web Traffic

from metric_forge.web_traffic import *
import polars as pl

data = pl.read_csv('datasets/web_traffic.csv')
data
<style> .dataframe > thead > tr, .dataframe > tbody > tr { text-align: right; white-space: pre-wrap; } </style> shape: (5, 8)
total_durationtotal_sessionssingle_page_sessionsnum_clicksnum_impressionstotal_costexitstotal_page_views
stri64i64i64i64i64i64i64
"1200"102100100050550
"1500"153150150075770
"0"01000220
"2500"255200200010010100
nullnullnullnullnullnullnullnull
data.with_columns(pl.col('*').forge_web_traffic.average_session_duration('total_duration', 'total_sessions'))
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

Cell In[25], line 1
----> 1 data.with_columns(pl.col('*').forge_web_traffic.average_session_duration('total_duration', 'total_sessions'))


TypeError: WebTraffic_Polars.average_session_duration() takes 2 positional arguments but 3 were given


          

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

metric_forge-0.2.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

metric_forge-0.2.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file metric_forge-0.2.1.tar.gz.

File metadata

  • Download URL: metric_forge-0.2.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for metric_forge-0.2.1.tar.gz
Algorithm Hash digest
SHA256 eb29be8249c1f24e4da6a9eb3a910facb616bd06c1f46ad373e40540a20e39e5
MD5 3f55fab1202cd495df034c017eb2531d
BLAKE2b-256 8ad8367e7c5a5c96fb2901068b0edb29060019def87a163899d149b10a54d363

See more details on using hashes here.

File details

Details for the file metric_forge-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for metric_forge-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d964aca5e813c2a1e5bbde5b8c4cbd6fea8343861ea6e60fd44ebba86423e02
MD5 be28da07fcff4d2f7850b4decc7a08bd
BLAKE2b-256 2e0c79c567e5655cff9513787238dbf6adb531c4d484fd0acfdfd53e6ad44bb1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page