Skip to content
DeepForgeby svx
All problems
HardTime Seriests-307

Newsvendor Order Quantile

Problem

Compute the newsvendor optimal order quantity as the sample quantile of demands at the critical fractile (price - cost) / (price - salvage). Use linear interpolation between order statistics, with the critical fractile clamped to the interval from 0 to 1.

Return 0.0 for empty demand, the sole value for a single demand, and use 0.5 when price equals salvage.

Hint

A higher unit margin relative to salvage pushes the critical fractile toward 1.

Test cases

case 1
in: [[10,20,30,40],10,4,1]
expected: 30
case 2
in: [[10,20,30,40],8,3,2]
expected: 35
case 3
in: [[5],10,4,0]
expected: 5
case 4
in: [[1,2,3,4,5],10,5,5]
expected: 5
case 5
in: [[10,20,30,40],5,4,1]
expected: 17.5
Starter codePython
def newsvendor_order_quantile(demands, price, cost, salvage):
    # Your code here
    pass

5 test cases · run your code against them in the editor