MODEL:
 ! The single product inventory problem with Mark Down.
How much should we stock in anticipation of three periods of
uncertain demand:
 Period 1: The main, profitable period, e.g., Christmas.
 Period 2: The mark down period, when margins are slim, e.g. January.
 Period 3: Dispose of, by whatever means necessary,
            any product still left over.
  We want to maximize expected profit over the three periods.
  When we choose the amount to stock before period 1, we want to
take into account the Mark Down and dispose periods;
! Keywords: Mark down, Newsboy problem, Inventory, Correlation,
     Stochastic programming;

DATA:
 ! Inputs;
  C  = 30;  ! cost/unit purchased and stocked;
  R1 = 60;  ! revenue/unit sold in the first period;
  P1 =  5;  ! Extra penalty, e.g., lost good will, for
             lost sales during first period;
  R2 = 32;  ! Revenue/unit sold in the second (markdown) period;
  R3 = -10; ! Reveneue/unit left over after second period.
             Negative means we have to pay to get rid of it;

  PSTEAL = 0; !Probability that a sale in period 2 is someone
             who would have bought in period 1, but did not, 
             because he expected he could get a better price
             in period 2. This parameter is difficult to estimate;

! We must have some model for the distribution of D1 and D2, the
  demand in periods 1 and 2. If they are uncorrelated, life is simple;
  MU1 = 60; ! Forecast demand in period 1;
  SD1 = 12; ! S.D. in demand period 1;
  MU2 = 40; ! Forecast demand in period 2 before seeing D1;
  SD2 = 10; ! Forecast of S.D. in period 2 before seeing D1;

 ! If we can estimate the correlation between D1 and D2, 
 we can do a little better;
  DELTA = 0.25; ! Correlation between D1 and D2;

  NSAMP = 256; ! Number samples to take. 
               More samples ==>> more accuracy;

ENDDATA

SUBMODEL MARKDOWN:
 ! Decision variable:
     Q = amount to stock before period 1,
   Supplementary decision variables:
     S1 = sales in period 1,
     S2 = sales in period 2 (mark down period),
     S3 = sales in period 3 (unload by whatever means necessary),
     INVi = inventory at end of period i,
     SHORTi = unsatisfied demand in period i;

! Step 1: Core model definition--------------------------------+;
   [R_OBJ] MAX = TPROF;
    TPROF = -C*Q + R1*S1 - P1*SHORT1 + R2*S2 - PSTEAL*(R1 - R2)*S2 + R3*S3;
   
    @FREE(TPROF);

 ! Inventory equation for period 1;
   INV1 - SHORT1 = Q - D1; 
   S1 = D1 - SHORT1;  
 ! Assumes (cost/unit short) + (cost/unit excess) >= 0;

 ! Inventory equation for period 2;
   S3 - SHORT2 = INV1 - D2; 
   S2 = D2 - SHORT2;  

! SP related declarations --------------------------------------+;
! Step 2: staging info;
   @SPSTGVAR( 0, Q); ! Amount to purchase, Q, is a stage 0 decision;
   @SPSTGRNDV( 1, D1); ! D1 is a random variable observed
                             in stage 1, at the beginning;
   @SPSTGRNDV( 1, D2U); ! D2U is unadjusted period 2 demand;
 
! Step 3: Distribution info;
!  Assumption: D1 has a Normal distribution;
   @SPDISTNORM( MU1, SD1, D1); 

! Assumption: D1 and D2 have a bivariate Normal distribution
  with correlation DELTA;
   @SPDISTNORM( MU2, SD2A, D2U); 

!  Notice that if correlation is 0, then there is no adjustment,
  otherwise it decreases;

! Adjusted demand for period 2 after seeing D1;
   D2 = D2U + DELTA*SD2*(D1 - MU1)/SD1;
! Notice, there is no shift if D1 = MU1 or 
  if the correlation, DELTA = 0. The direction
  of adjustment depends upon the correlation and
  how D1 deviates from its mean;

! Step 4: Sampling/scenario structure;
   @SPSAMPSIZE( 1, NSAMP);  ! Specify the stage 1 sample size;
ENDSUBMODEL
SETS: !HISTPROF will store profits from each scenario; TSET /1..NSAMP/: HISTPROF; ENDSETS
CALC: @SET('TERSEO',1); ! Set output level to terse; ! Adjusted SD for period 2 after seeing D1. Assumption: D1 and D2 are bivariate Normal; SD2A = SD2*(1-DELTA^2)^0.5; ! Notice that if D1 and D2 are uncorrelated, there is no adjustment. If they are perfectly correlated, the uncertainty drops to 0; @SOLVE( MARKDOWN); !Loop to get profit for each scenario; I = 0; aprof = 0; @WHILE( I #LT# NSAMP: I = I + 1; @SPLOADSCENE( I); HISTPROF( I) = TPROF; aprof = aprof + tprof; ); !Create a histogram of profit over all samples; @CHARTHISTO( 'Histogram of Expected Profit', !Title; 'Profit Range', !X-Axis label; 'Frequency', !Y-Axis label; 'No. of Trials', !Legend; 15, !Number of bins; HISTPROF !Attribute to chart; ); @WRITE(@NEWLINE(1),' Recommended amount to stock = ',@FORMAT(Q,"12.2F"), @NEWLINE(1), ' giving expected profit of = ', @FORMAT( @SPMEAN(TPROF),"12.2F"),@NEWLINE(1)); ! @WRITE(@NEWLINE(1),' Recommended amount to stock = ',@FORMAT(Q,"12.2F"), @NEWLINE(1), ' giving expected profit of = ', @FORMAT( aprof/NSAMP,"12.2F"),@NEWLINE(1)); @WRITE(' Based on ',NSAMP,' scenarios.',@NEWLINE(1)); ENDCALC END