Solve the newsvendor problem for single-period ordering decisions under uncertain demand. Use this skill when the user needs to determine optimal order quantity for perishable goods, seasonal products, or one-time purchase decisions — even if they say 'how much to order for this season', 'perishable inventory', or 'single-period ordering'.
npx skills add https://github.com/asgard-ai-platform/skills --skill algo-sc-newsvendor
The newsvendor model determines optimal order quantity for a single selling period with uncertain demand. Balances overage cost (Co = cost - salvage) against underage cost (Cu = price - cost). Optimal Q* satisfies: P(D ≤ Q*) = Cu / (Cu + Co). Known as the critical ratio solution.
Trigger conditions:
When NOT to use:
IRON LAW: The Critical Ratio Determines Optimal Service Level
Q* = F⁻¹(Cu / (Cu + Co)) where F⁻¹ is the inverse demand CDF.
If margin is high relative to cost (Cu >> Co), order MORE (high service level).
If margin is low relative to excess cost (Co >> Cu), order LESS (low service level).
The optimal solution almost NEVER equals expected demand.
Define: unit cost (c), selling price (p), salvage value (v), demand distribution (mean μ, std σ). Compute: Cu = p - c, Co = c - v.
Gate: p > c > v (profitable with positive overage cost), demand distribution estimated.
Check: Q* > 0, CR between 0 and 1, Q* is above or below μ depending on whether CR > or < 0.5.
Gate: Q* directionally correct relative to mean demand.
Return optimal order quantity with profit analysis.
{
"optimal_quantity": 130,
"critical_ratio": 0.71,
"expected_profit": 2800,
"expected_leftover": 15,
"expected_stockout_probability": 0.29,
"metadata": {"price": 50, "cost": 20, "salvage": 5, "demand_mean": 100, "demand_std": 30}
}
Input: p=$50, c=$20, v=$5, D~Normal(100, 30)
Expected: Cu=30, Co=15, CR=30/45=0.667, z=0.43, Q*=100+0.43×30=113 units.
| Input | Expected | Why |
|-------|----------|-----|
| v = 0 (total loss) | Lower Q*, conservative | High overage cost pushes order down |
| p >> c (high margin) | Q* well above mean | Worth risking excess to avoid lost sales |
| σ = 0 (certain demand) | Q* = μ exactly | No uncertainty, order exactly demand |
| Script | Description | Usage |
|--------|-------------|-------|
| scripts/newsvendor.py | Compute newsvendor optimal quantity, expected profit, and fill rate | python scripts/newsvendor.py --help |
Run python scripts/newsvendor.py --verify to execute built-in sanity tests.
references/constrained-newsvendor.mdreferences/demand-fitting.mdGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.
Intelligently organizes your files and folders across your computer by understanding context, finding duplicates, suggesting better structures, and automating cleanup tasks. Reduces cognitive load and keeps your digital workspace tidy without manual effort.
Generates creative domain name ideas for your project and checks availability across multiple TLDs (.com, .io, .dev, .ai, etc.). Saves hours of brainstorming and manual checking.
You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.
Implements Manus-style file-based planning for complex tasks. Creates task_plan.md, findings.md, and progress.md. Use when starting complex multi-step tasks, research projects, or any task requiring >5 tool calls.
Creative research ideation and exploration. Use for open-ended brainstorming sessions, exploring interdisciplinary connections, challenging assumptions, or identifying research gaps. Best for early-stage research planning when you do not have specific observations yet. For formulating testable hypotheses from data use hypothesis-generation.
Comprehensive GitHub project management with swarm-coordinated issue tracking, project board automation, and sprint planning
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
Take asgard-ai-platform/algo-sc-newsvendor from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.