A simple way to calculate retail stats
Project description
Retail Stats
This repository contains code to calculate various values used in retail for products whose sales and prices are provided.
Metrics currently available:
- Price Elasticity (In Progress)
- Cross Elasticity (Complete)
Installation
Install from PyPi.
pip install retail-stats
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.
from retail_stats.elasticity import calculate_cross_elasticity
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
Release history Release notifications | RSS feed
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.post1.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for retail_stats-0.0.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0a7e4e8d24fb13b389b151e7fdd304ad72b43723d9cb326a45cfcaf1e93ecd0 |
|
MD5 | 59684e11ceecb0655cd0c4be9143a25e |
|
BLAKE2b-256 | 13f42fe078c3e509eb6bf300c1820228eb09839a43a6ece2a1da25493e2b5183 |