Skip to main content

A simple way to calculate retail stats

Project description

Retail Stats

Codacy Badge Build Status Coverage Status

This repository contains code to calculate various values used in retail for products whose sales and prices are provided.

Metrics currently available:

  1. Price Elasticity (In Progress)
  2. Cross Elasticity (Complete)

Calculations

Cross Elasticity

From Wikipedia,

measures the responsiveness of the quantity demanded for a good to a change in the price of another good, ceteris paribus.

This can be seen written using the formula:

Percentage Change in Quantity Sold of Product B
-------------------------------------------------
Percentage Change in Price Charged for Product A

The implementation is a direct copy of the formula.

Calculate Cross Elasticity for a single pair of products

from math import isclose
from retail_stats import elasticity

original_quantity = 200
new_quantity = 400

original_price = 1000
new_price = 1050
# (200 / 300) / (50 / 1025)
expected_ced = 13.66666666666666
ced = elasticity.calculate_cross_elasticity(original_quantity, 
                                            new_quantity, 
                                            original_price, 
                                            new_price)

assert isclose(expected_ced, ced)

Calculate All Cross Elasticities

from math import isclose

import numpy as np

from retail_stats.elasticity import get_all_cross_elasticities

skus = np.array(list("ABCD"))
# [original, new]
qty_a = [200, 0]
qty_b = [200, 400]
prc_a = [1000, 1050]
prc_b = [1000, 1000]

qty_c = [1000, 1050]
qty_d = [1000, 1100]
prc_c = [100, 80]
prc_d = [80, 80]

original_quantities = [qty_a[0], qty_b[0], qty_c[0], qty_d[0]]
new_quantities = [qty_a[1], qty_b[1], qty_c[1], qty_d[1]]
original_prices = [prc_a[0], prc_b[0], prc_c[0], prc_d[0]]
new_prices = [prc_a[1], prc_b[1], prc_c[1], prc_d[1]]

"""
Cross Elasticities between pairs A,B and C,D

  | A | B | C | D 
A |   |   |   |
B |   |   |   | 
C |   |   |   | 
D |   |   |   |
"""

ceds = get_all_cross_elasticities(original_quantities=original_quantities,
                                  new_quantities=new_quantities,
                                  original_prices=original_prices,
                                  new_prices=new_prices)

assert ceds.shape == (len(skus), len(skus))
assert isclose(ceds[np.argwhere(skus == "A"), np.argwhere(skus == "A")], -41)
assert isclose(ceds[np.argwhere(skus == "B"), np.argwhere(skus == "A")], 13.66666666666666)
assert isclose(ceds[np.argwhere(skus == "D"), np.argwhere(skus == "C")], -0.4285714286)
assert isclose(ceds[np.argwhere(skus == "C"), np.argwhere(skus == "A")], 1)
assert isclose(ceds[np.argwhere(skus == "A"), np.argwhere(skus == "C")], 9)

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

retail-stats-0.0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

retail_stats-0.0.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file retail-stats-0.0.1.tar.gz.

File metadata

  • Download URL: retail-stats-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.4

File hashes

Hashes for retail-stats-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4a0e18906b5ccd6d39d7fb95cbef07b66ed06b1c8be2f5d338f59973c8ab567b
MD5 49e3cabab842e84fb88739091b477ec0
BLAKE2b-256 044087987c1b71d8fe547962d6e5bd001c953c9112d6a6659e3498184e114ab8

See more details on using hashes here.

File details

Details for the file retail_stats-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: retail_stats-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.4

File hashes

Hashes for retail_stats-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb60712c8026f5ae28d56f673039b109994e64d41877b9b4acd087daf9fcbfeb
MD5 55c59213fbbc8b08b09409260da37af0
BLAKE2b-256 3b441d51aebcf6819561c1409fcc6db7bef5fed90e0d8cbfcefa8b50ff3b3e51

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