Skip to main content

Stockpyl

PyPI Documentation Status Coverage GitHub GitHub issues Twitter Follow

Stockpyl is a Python package for inventory optimization. It implements classical single-node inventory models like the economic order quantity (EOQ), newsvendor, and Wagner-Whitin problems. It also contains algorithms for multi-echelon inventory optimization (MEIO) under both stochastic-service model (SSM) and guaranteed-service model (GSM) assumptions.

Most of the models and algorithms implemented in Stockpyl are discussed in the textbook Fundamentals of Supply Chain Theory (FoSCT) by Snyder and Shen, Wiley, 2019, 2nd ed. Most of them are much older; see FoSCT for references to original sources.

For a tutorial, see Snyder, L. V., "Stockpyl: A Python Package for Inventory Optimization and Simulation," in: Bish, E. K. and H. Balasubramanian, INFORMS TutORials in Operations Research, 156–197, 2023. The associated Jupyter notebooks are at notebooks/.

For lots of details, read the docs.

Some Examples

Solve the newsvendor problem with a holding (overage) cost of 2, a stockout (underage) cost of 18, and demands that are normally distributed with a mean of 120 and a standard deviation of 10:

>>> from stockpyl.newsvendor import newsvendor_normal
>>> S, cost = newsvendor_normal(holding_cost=2, stockout_cost=18, demand_mean=120, demand_sd=10)
>>> S
132.815515655446
>>> cost
35.09966638649737

Use Chen and Zheng's (1994) algorithm (based on Clark and Scarf (1960)) to optimize a 3-node serial system under the stochastic-service model (SSM):

>>> from stockpyl.ssm_serial import optimize_base_stock_levels
>>> S_star, C_star = optimize_base_stock_levels(
...     num_nodes=3,
...     echelon_holding_cost=[4, 3, 1],
...     lead_time=[1, 1, 2],
...     stockout_cost=40,
...     demand_mean=10,
...     demand_standard_deviation=2
... )
>>> S_star
{1: 12.764978727246302, 2: 23.49686681508743, 3: 46.28013742779933}
>>> C_star
86.02533221942987

Simulate the same system using the optimal base-stock levels:

Optimize committed service times (CSTs) for a tree network under the guaranteed-service model (GSM) using Graves and Willems' (2000) dynamic programming algorithm:

>>> from stockpyl.gsm_tree import optimize_committed_service_times
>>> from stockpyl.instances import load_instance
>>> # Load a named instance, Example 6.5 from FoSCT.
>>> tree = load_instance("example_6_5")
>>> opt_cst, opt_cost = optimize_committed_service_times(tree)
>>> opt_cst
{1: 0, 3: 0, 2: 0, 4: 1}
>>> opt_cost
8.277916867529369

Resources

Feedback

If you have feedback or encounter problems, please report them on the Stockpyl GitHub Issues Page. (If you are not comfortable using GitHub for this purpose, feel free to e-mail me. My contact info is on my webpage.)

License

Stockpyl is open-source and released under the MIT License.

Citation

If you'd like to cite the Stockpyl package, you can use the following BibTeX entry:

@misc{stockpyl,
    title={Stockpyl},
    author={Snyder, Lawrence V.},
    year={2023},
    url={https://github.com/LarrySnyder/stockpyl}
}

Metadata

Release files for stockpyl 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stockpyl 1.0.2
File Size Uploaded
stockpyl-1.0.2.tar.gz 251.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stockpyl 1.0.2
File Interpreter ABI Platform
stockpyl-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 428.2 kB

Release files / stockpyl-1.0.2.tar.gz

Download URL stockpyl-1.0.2.tar.gz
Size 251.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1bcffd584c6cab1bb7a878f4fd7fe4c069b3672fd5c924d964ffd2fa8ab08519
BLAKE2b-256 checksum
How to use checksums
1931884166f4d70368ba243df26d82d8349a41095e973a2305550d109fa85f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.13

Release files / stockpyl-1.0.2-py3-none-any.whl

Download URL stockpyl-1.0.2-py3-none-any.whl
Size 176.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21010f20cd30ba317721fefcee3d016f69ddaf013509316427bc4cdc8b15c801
BLAKE2b-256 checksum
How to use checksums
ec617c5fba4743fc4fd95360e4ab8b3232e13815b68c24210183a38ea447f749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.13

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page