Lindo Systems

! Asset-Liability Management, Stochastic case;
! Each period we can buy and sell a variety of investments,
   and we can borrow or lend for one period at a rate
   specific to the period.  In the stochastic case, the
   borrowing and lending rates are random variables.
  How should we invest each period?
! Keywords: Financial planning, Asset-Liability management,
  Bonds, Yield curve, Stochastic optimization;
SETS:
 PERIOD: NEED, BORRMX;
 NODE: LEND, BORR, RLEND, RBORR,
       PERD, PREV, NWORTH, SHORTF;
 ASSET: HOLDMX, HOLDIN;
 PXA( PERIOD, ASSET): PAYOUT, PBUY, PSEL;
 NXA( NODE, ASSET): HOLD, BUY, SEL;
ENDSETS
DATA:
! Uncertainty is represented by a tree of possible outcome paths;
  PERIOD = 1..7; ! There re 7 periods;
! External cash needs by period due to previous commitments;
 NEED =   -2000     -500      -400     -380     -360     -340 -300;
! Max we can borrow.           Cannot borrow(and not repay) at end;
 BORRMX =  2000     2000      2000     2000     2000     2000    0;

  ASSET= F     M     D; ! Three investments available;
 HOLDMX= 1     1     1; ! Maximum we can hold of each asset;
 HOLDIN= 0     0     0; ! Initially we own nothing of anything;
  PAYOUT=                ! Payout or throw-off ;
          0     0     0  !  by asset by period;
      -1000  -500 -2000
      -1800  1500 -1800
        400  1500  1000
       1800  1500  1000
       1800   200  1000
       5500 -1000  6000;
! Price in period t at which we can buy asset i;
 PBUY= 3000  2000  2000! Can buy only; 
      99999 99999 99999 ! in 1st period;
      99999 99999 99999
      99999 99999 99999
      99999 99999 99999
      99999 99999 99999
      99999 99999 99999;

! Price in period t at which we can sell asset i;
 PSEL = -999999; ! Cannot sell these investments once made;

!   Below is a description of the tree of all possible outcomes.
  Each node corresponds to a particular outcome in a particular period.
    A path in the tree represents one possible set of outcomes. 
  This is a 7 period problem, so every path in the tree has 7
  nodes.  For example, one possible path is:
  1 -> 3 -> 6 -> 12 -> 25 -> 51 -> 102.
  Although not essential,  the tree used here is a binary tree, i.e.,
  all nodes, except for final period nodes, have two successors.
  For simplicity,  all paths are considered equally likely.
    The one period lending rates are based on a yield curve from
  2005, fitted with a Black/Derman/Toy stochastic interest rate model.
  The borrowing rate is simply set = lending rate + .005
    Each node is described by: node number, period, previous or 
  predecessor node, and the lending and borrowing rate associated with
  this outcome;
 NODE, PERD, PREV, RLEND,       RBORR =        
   1    1    0  0.0326      0.0376      
   2    2    1  0.037064518 0.042064518  
   3    2    1  0.040962628 0.045962628  
   4    3    2  0.032253001 0.037253001  
   5    3    2  0.037134275 0.042134275  
   6    3    3  0.037134275 0.042134275  
   7    3    3  0.042754296 0.047754296  
   8    4    4  0.030361098 0.035361098  
   9    4    4  0.035275441 0.040275441   
  10    4    5  0.035275441 0.040275441
  11    4    5  0.040985234 0.045985234  
  12    4    6  0.035275441 0.040275441  
  13    4    6  0.040985234 0.045985234  
  14    4    7  0.040985234 0.045985234  
  15    4    7  0.047619232 0.052619232  
  16    5    8  0.028620814 0.033620814 
  17    5    8  0.033376231 0.038376231
  18    5    9  0.033376231 0.038376231 
  19    5    9  0.038921772 0.043921772
  20    5   10  0.033376231 0.038376231 
  21    5   10  0.038921772 0.043921772    
  22    5   11  0.038921772 0.043921772
  23    5   11  0.045388718 0.050388718
  24    5   12  0.033376231 0.038376231
  25    5   12  0.038921772 0.043921772
  26    5   13  0.038921772 0.043921772
  27    5   13  0.045388718 0.050388718 
  28    5   14  0.038921772 0.043921772
  29    5   14  0.045388718 0.050388718  
  30    5   15  0.045388718 0.050388718 
  31    5   15  0.052930163 0.057930163 
  32    6   16  0.028247864 0.033247864 
  33    6   16  0.032984564 0.037984564 
  34    6   17  0.032984564 0.037984564
  35    6   17  0.038515529 0.043515529 
  36    6   18  0.032984564 0.037984564
  37    6   18  0.038515529 0.043515529
  38    6   19 0.038515529 0.043515529  
  39    6   19  0.044973946 0.049973946 
  40    6   20  0.032984564 0.037984564
  41    6   20  0.038515529 0.043515529
  42    6   21  0.038515529 0.043515529  
  43    6   21  0.044973946 0.049973946 
  44    6   22  0.038515529 0.043515529  
  45    6   22  0.044973946 0.049973946 
  46    6   23  0.044973946 0.049973946
  47    6   23  0.052515332 0.057515332 
  48    6   24  0.032984564 0.037984564 
  49    6   24  0.038515529 0.043515529 
  50    6   25  0.038515529 0.043515529 
  51    6   25  0.044973946 0.049973946 
  52    6   26  0.038515529 0.043515529 
  53    6   26  0.044973946 0.049973946  
  54    6   27  0.044973946 0.049973946       
  55    6   27  0.052515332 0.057515332 
  56    6   28  0.038515529 0.043515529 
  57    6   28  0.044973946 0.049973946 
  58    6   29  0.044973946 0.049973946
  59    6   29  0.052515332 0.057515332 
  60    6   30  0.044973946 0.049973946
  61    6   30  0.052515332 0.057515332
  62    6   31  0.052515332 0.057515332
  63    6   31  0.061321284 0.066321284
  64    7   32  0.02739986  0.03239986 
  65    7   32  0.031882856 0.036882856
  66    7   33  0.031882856 0.036882856
  67    7   33  0.037099334 0.042099334
  68    7   34  0.031882856 0.036882856
  69    7   34  0.037099334 0.042099334
  70    7   35  0.037099334 0.042099334
  71    7   35  0.043169299 0.048169299
  72    7   36  0.031882856 0.036882856
  73    7   36  0.037099334 0.042099334
  74    7   37  0.037099334 0.042099334
  75    7   37  0.043169299 0.048169299
  76    7   38  0.037099334 0.042099334
  77    7   38  0.043169299 0.048169299
  78    7   39  0.043169299 0.048169299 
  79    7   39  0.050232395 0.055232395
  80    7   40  0.031882856 0.036882856
  81    7   40  0.037099334 0.042099334
  82    7   41  0.037099334 0.042099334
  83    7   41  0.043169299 0.048169299
  84    7   42  0.037099334 0.042099334
  85    7   42  0.043169299 0.048169299
  86    7   43  0.043169299 0.048169299 
  87    7   43  0.050232395 0.055232395
  88    7   44  0.037099334 0.042099334
  89    7   44  0.043169299 0.048169299
  90    7   45  0.043169299 0.048169299 
  91    7   45  0.050232395 0.055232395
  92    7   46  0.043169299 0.048169299 
  93    7   46  0.050232395 0.055232395 
  94    7   47  0.050232395 0.055232395
  95    7   47  0.058451111 0.063451111
  96    7   48  0.031882856 0.036882856
  97    7   48  0.037099334 0.042099334
  98    7   49  0.037099334 0.042099334
  99    7   49  0.043169299 0.048169299
 100    7   50  0.037099334 0.042099334
 101    7   50  0.043169299 0.048169299
 102    7   51  0.043169299 0.048169299 
 103    7   51  0.050232395 0.055232395
 104    7   52  0.037099334 0.042099334
 105    7   52  0.043169299 0.048169299
 106    7   53  0.043169299 0.048169299 
 107    7   53  0.050232395 0.055232395
 108    7   54  0.043169299 0.048169299 
 109    7   54  0.050232395 0.055232395 
 110    7   55  0.050232395 0.055232395
 111    7   55  0.058451111 0.063451111
 112    7   56  0.037099334 0.042099334
 113    7   56  0.043169299 0.048169299
 114    7   57  0.043169299 0.048169299 
 115    7   57  0.050232395 0.055232395
 116    7   58  0.043169299 0.048169299 
 117    7   58  0.050232395 0.055232395 
 118    7   59  0.050232395 0.055232395
 119    7   59  0.058451111 0.063451111
 120    7   60  0.043169299 0.048169299 
 121    7   60  0.050232395 0.055232395 
 122    7   61  0.050232395 0.055232395
 123    7   61  0.058451111 0.063451111 
 124    7   62  0.050232395 0.055232395
 125    7   62  0.058451111 0.063451111
 126    7   63  0.058451111 0.063451111
 127    7   63  0.068014522 0.073014522;

! Measuring risk.  We consider any final net worth
 less than TARGET as bad. Our measure of risk is 
 the expected amount by which we fall short of the
 target, i.e., ESHORTF = E[max(0, TARGET - NWORTH)];
 TARGET = 7630;
! MXSHORT = upper limit we place on ESHORTF;
 MXSHORT = 99999;

! Punchline: We buy a fair amount of F and M, but nothing of D;
ENDDATA 

! Variables:
   BUY(t,i) = units bought at beginning of period t of asset i,
   SEL(t,i) = units sold at beginning of t of asset i,
   HOLD(t,i) = units held at end of t of asset i,
   BORR(t) = amount borrowed at beginning of t,
   LEND(t) = amount lent at the beginning of t
   NWORTH(t) = net worth at node t in final period
   SHORTF(t) = max(0,TARGET-NWORTH(t));

! Get index of final period;
  TF = @size( PERIOD);
! Get number final period nodes;
  NF = @SUM( NODE(n)| PERD(n) #EQ# TF: 1);
! Maximize expected wealth in final period;
   MAX =  @SUM( NODE( n)| PERD(n) #EQ# TF: NWORTH(n))/ NF;

        @FOR( NODE(n) | PERD(N) #EQ# TF:
          NWORTH(n)= 
           @SUM( ASSET(i): 
               PAYOUT(PERD(n),i)*HOLD(n,i)
             - PBUY(TF,i)   *BUY(n,i) 
             + PSEL(TF,i)   *SEL(n,i))
      + (1 + RLEND(PREV(n)))*LEND(PREV(n)) 
      - (1 + RBORR(PREV(n)))*BORR(PREV(n)) - NEED(TF);
             );

! First Period;
!  Individual asset balances;
 @FOR( ASSET(i):
   HOLDIN(i) + BUY(1,i) = SEL(1,i) + HOLD(1,i);
   HOLD(1,i) <= HOLDMX(i)
    );

!   Cash balance constraint;
!   Cash inflows from investments + borrowings in 1
    + asset sales in 1 = asset purchases in 1 + loans made in 1
    + external liabilities in 1;
   @SUM( ASSET(i): PAYOUT(1,i)*HOLDIN(i) + PSEL(1,i)*SEL(1,i)) + BORR(1) 
   = @SUM( ASSET(i):PBUY(1,i)*BUY(1,i)) + LEND(1) + NEED(1);

   BORR(1) <= BORRMX(1);  ! Borrowing limit;

! Same applies for subsequent periods;
  @FOR( NODE( t) | t #GT# 1:
!   For each asset type i:  Ending inventory in t-1 + purchases
    = sales + ending inventory in t;
   @FOR( ASSET( i):
      HOLD(PREV(t),i) + BUY(t,i) = SEL(t,i) + HOLD(t,i);
      HOLD(t,i) <= HOLDMX(i)
        );

!   Cash inflows from investments + repayments from loans in t-1
   + borrowings in t + asset sales in t
   = asset purchases in t + loans made in t
      + repayment of borrowings in previous period
      + external liabilities in t;
    @SUM( ASSET(i): PAYOUT(PERD(t),i)*HOLD(t,i) + PSEL(PERD(t),i)*SEL(t,i))
        +(1+RLEND(PREV(t)))*LEND(PREV(t)) + BORR(t) =
    @SUM( ASSET(i): PBUY(PERD(t),i)*BUY(t,i)) + (1 + RBORR(PREV(t)))*BORR(PREV(t)) + LEND(t)
        + NEED(PERD(t));

    BORR(t) <= BORRMX(PERD(t));  ! Borrowing limit;
      );

  ! Here is the risk computations.
    Compute amount short each final outcome;
    @FOR( NODE(t)| PERD(t) #EQ# TF:
      SHORTF(t) >= TARGET - NWORTH(t);
        );
   ! Compute average, or expected, amount short;
     ESHORTF = @SUM( NODE(t) | PERD(t) #EQ# TF: SHORTF(t))/NF;
   ! Constrain it;
     ESHORTF <= MXSHORT;