REM REM STDP_ex1 REM Peter Lohmander 171015 CLS OPEN "PLEX1.txt" FOR OUTPUT AS #1 PRINT "" PRINT " Harvest optimization via stochastic dynamic programming" PRINT " Peter Lohmander Example 1 2017-10-15" PRINT "" PRINT #1, "" PRINT #1, " Harvest optimization via stochastic dynamic programming" PRINT #1, " Peter Lohmander Example 1 2017-10-15" PRINT #1, "" DIM f(100, 10), u(100, 10), DPProb(10) REM Delta Price Probability distribution DPProb(0) = .00 DPProb(1) = .03 DPProb(2) = .07 DPProb(3) = .10 DPProb(4) = .18 DPProb(5) = .24 DPProb(6) = .18 DPProb(7) = .10 DPProb(8) = .07 DPProb(9) = .03 DPProb(10) = .00 tmax = 20 deltat = 5 r = 0.03 p0 = 10 p1 = 0.3 p2 = 10 v0 = 0 v1 = 5 Landv = 50 FOR t = 0 TO 100 FOR i = 0 TO 10 f(t, i) = 0 u(t, i) = 0 NEXT i NEXT t FOR i = 1 TO 9 u(tmax, i) = 1 NEXT i REM boundary conditions at tmax t = tmax * deltat vol = v0 + v1 * t FOR i = 1 TO 9 netp = p0 + p1 * t + p2 * (i - 5) f(tmax, i) = EXP(-r * t) * (netp * vol + Landv) IF f(tmax, i) < 0 THEN f(tmax, i) = 0 NEXT i REM FOR i = 1 TO 9 REM PRINT i; " "; f(tmax, i) REM NEXT i REM Stochatic dynamic programming via backward recursion FOR tindex = tmax - 1 TO 0 STEP -1 t = tindex * deltat disc = EXP(-r * t) vol = v0 + v1 * t FOR i = 1 TO 9 REM Objective function in case of no instant harvest fnoharv = 0 FOR j = 1 TO 9 fnoharv = fnoharv + DPProb(j) * f(tindex + 1, j) NEXT j REM Objective function in case of instant harvest netp = p0 + p1 * t + p2 * (i - 5) fharv = disc * (netp * vol + Landv) fopt = fharv IF fnoharv > fharv THEN fopt = fnoharv f(tindex, i) = fopt IF fopt = fharv THEN u(tindex, i) = 1 IF f(tindex, i) < 0 THEN f(tindex, i) = 0 NEXT i NEXT tindex REM Result tables FOR tindex = 0 TO tmax t = tindex * deltat PRINT " Year = "; t PRINT "" PRINT " Net Price Harvest (1=Yes,0=N0) Expected Present Value" PRINT #1, " Year = "; t PRINT #1," " PRINT #1, " Net Price Harvest (1=Yes,0=N0) Expected Present Value" FOR i = 1 TO 9 netp = p0 + p1 * t + p2 * (i - 5) harvest = u(tindex, i) fopt = f(tindex, i) PRINT USING "################"; netp; harvest; fopt; PRINT "" PRINT #1, USING "################"; netp; harvest; fopt; PRINT #1, "" NEXT i INPUT z PRINT "" PRINT #1, "" NEXT tindex CLOSE #1 END **************************************************************************************** Harvest optimization via stochastic dynamic programming Peter Lohmander Example 1 2017-10-15 Year = 0 Net Price Harvest (1=Yes,0=N0) Expected Present Value -30 0 2772 -20 0 2772 -10 0 2772 0 0 2772 10 0 2772 20 0 2772 30 0 2772 40 0 2772 50 0 2772 Year = 5 Net Price Harvest (1=Yes,0=N0) Expected Present Value -29 0 2772 -19 0 2772 -9 0 2772 2 0 2772 12 0 2772 22 0 2772 32 0 2772 42 0 2772 52 0 2772 Year = 10 Net Price Harvest (1=Yes,0=N0) Expected Present Value -27 0 2772 -17 0 2772 -7 0 2772 3 0 2772 13 0 2772 23 0 2772 33 0 2772 43 0 2772 53 0 2772 Year = 15 Net Price Harvest (1=Yes,0=N0) Expected Present Value -26 0 2772 -16 0 2772 -6 0 2772 5 0 2772 15 0 2772 25 0 2772 35 0 2772 45 0 2772 55 0 2772 Year = 20 Net Price Harvest (1=Yes,0=N0) Expected Present Value -24 0 2762 -14 0 2762 -4 0 2762 6 0 2762 16 0 2762 26 0 2762 36 0 2762 46 0 2762 56 1 3101 Year = 25 Net Price Harvest (1=Yes,0=N0) Expected Present Value -23 0 2735 -13 0 2735 -2 0 2735 8 0 2735 18 0 2735 28 0 2735 38 0 2735 48 1 2828 58 1 3419 Year = 30 Net Price Harvest (1=Yes,0=N0) Expected Present Value -21 0 2684 -11 0 2684 -1 0 2684 9 0 2684 19 0 2684 29 0 2684 39 0 2684 49 1 3009 59 1 3618 Year = 35 Net Price Harvest (1=Yes,0=N0) Expected Present Value -20 0 2617 -10 0 2617 1 0 2617 11 0 2617 21 0 2617 31 0 2617 41 0 2617 51 1 3110 61 1 3722 Year = 40 Net Price Harvest (1=Yes,0=N0) Expected Present Value -18 0 2537 -8 0 2537 2 0 2537 12 0 2537 22 0 2537 32 0 2537 42 1 2545 52 1 3147 62 1 3750 Year = 45 Net Price Harvest (1=Yes,0=N0) Expected Present Value -17 0 2438 -6 0 2438 4 0 2438 14 0 2438 24 0 2438 34 0 2438 44 1 2550 54 1 3134 64 1 3717 Year = 50 Net Price Harvest (1=Yes,0=N0) Expected Present Value -15 0 2327 -5 0 2327 5 0 2327 15 0 2327 25 0 2327 35 0 2327 45 1 2521 55 1 3079 65 1 3637 Year = 55 Net Price Harvest (1=Yes,0=N0) Expected Present Value -13 0 2207 -3 0 2207 7 0 2207 17 0 2207 27 0 2207 37 0 2207 47 1 2465 57 1 2994 67 1 3522 Year = 60 Net Price Harvest (1=Yes,0=N0) Expected Present Value -12 0 2080 -2 0 2080 8 0 2080 18 0 2080 28 0 2080 38 0 2080 48 1 2389 58 1 2884 68 1 3380 Year = 65 Net Price Harvest (1=Yes,0=N0) Expected Present Value -10 0 1951 -0 0 1951 10 0 1951 20 0 1951 30 0 1951 40 0 1951 50 1 2296 60 1 2758 70 1 3221 Year = 70 Net Price Harvest (1=Yes,0=N0) Expected Present Value -9 0 1822 1 0 1822 11 0 1822 21 0 1822 31 0 1822 41 0 1822 51 1 2192 61 1 2621 71 1 3049 Year = 75 Net Price Harvest (1=Yes,0=N0) Expected Present Value -7 0 1693 3 0 1693 13 0 1693 23 0 1693 33 0 1693 43 0 1693 53 1 2080 63 1 2476 73 1 2871 Year = 80 Net Price Harvest (1=Yes,0=N0) Expected Present Value -6 0 1556 4 0 1556 14 0 1556 24 0 1556 34 0 1556 44 1 1601 54 1 1964 64 1 2327 74 1 2690 Year = 85 Net Price Harvest (1=Yes,0=N0) Expected Present Value -4 0 1405 6 0 1405 16 0 1405 26 0 1405 36 0 1405 46 1 1514 56 1 1846 66 1 2178 76 1 2509 Year = 90 Net Price Harvest (1=Yes,0=N0) Expected Present Value -3 0 1232 7 0 1232 17 0 1232 27 0 1232 37 0 1232 47 1 1425 57 1 1727 67 1 2030 77 1 2332 Year = 95 Net Price Harvest (1=Yes,0=N0) Expected Present Value -1 0 998 9 0 998 19 0 998 29 0 998 39 1 1061 49 1 1335 59 1 1610 69 1 1885 79 1 2160 Year = 100 Net Price Harvest (1=Yes,0=N0) Expected Present Value 0 1 2 10 1 251 20 1 500 30 1 749 40 1 998 50 1 1247 60 1 1496 70 1 1745 80 1 1994