Notes/Simulation Lab - Agricultural & Applied Economics

advertisement
In-Class Lab for Monte Carlo Simulation
AAE 575
Fall 2012
The goal of this lab is for the students to learn how to use Monte Carlo simulation in Excel to
empirically implement decision criteria such as maximization expected utility and break-even
probabilities.
Case 1 (Discrete Choice, 1 Random Variable):
Assume have Bt and non-Bt corn and have to choose which to plant
Yields:
Yno = PYpf(1 – )
YBt = Ypf
Profit:
no = PYpf(1 – ) – K
Bt = PYpf – T – K
Loss is random:  ~ beta (, , 0, 1)
no = PYpf(1 – ) – K
Bt = PYpf – T – K
U() = – exp(– R))
Constant Absolute Risk Aversion utility (CARA) U ( )   exp( R ) , where R is the coefficient
of absolute risk aversion R = – U/U
Decision Rule: Maximize expected utility, which for a discrete case means choose the option
with the highest expected utility, or equivalently, the highest certainty equivalent.
Technical issue: cannot find an analytical formula for the expected utility for this case:
E[U(no)] = E[U(PYpf(1 – ) – K)] = –exp(–RPYpf + RK)]E[exp(RPYpf)]
Cannot get a closed form solution for E[exp(A)] when  has beta distribution.
Monte Carlo Simulation
Suppose have variable x with pdf f(x) and want to know E[x] =
 xf ( x)dx , but cannot solve the
integral, how do you find the E[x]? If you can obtain many random draws from the pdf f(x), then
1 K
a Monte Carlo approximation of E[x] is: E[x]   xk , where xk is the kth random draw from
K k 1
the pdf f(x). A more common problem is that we know x ~ f(x), but want to know E[g(x)] =
1 K
g
(
x
)
f
(
x
)
dx

.
Again,
a
Monte
Carlo
approximation
of
E[g(x)]
is:
E[g(x)]
 g ( xk ) , where

K k 1
xk is kth random draw from pdf f(x).
Step 1: Draw Random Variables
Step 1a: Specify Parameters: set (, ) of loss, and then calculate implied  and .
(   min)2 (max   )   2 (   min)
(   min)(max   )2   2 (max   )
and



(max  min) 2
(max  min) 2
For our case here, min = 0 and max = 1.
Step 1b: Draw Uniform (0, 1)
In excel, under “Data” tab, choose “Data Analysis”. If “Data Analysis” is not there, then go to
“File” then choose “Options” and then “Add-Ins” and look for “Analysis ToolPak.
Once it’s working, under “Data” “Data Analysis” finds “Random Number Generation” in the
menu (you may have to scroll down).
In the box that opens, you have to file in several parts.
 “Number of Variables” type in 1 (this is the number of columns you want)
 “Number of Random Numbers” type 10,000 (this is the number of rows for each column)
 From the “Distribution” menu, choose “Uniform”
 “Parameters” leave the default values of 0 and 1
 “Random Seed” is an integer between 1 and 32,000 (roughly) and is used to generate a
sequence of random draws. Using the same seed will give the same sequence of random
draws on different machines and the seed allows you to reconstruct the same set of
random draws if you wish on any machine.
 Lastly: choose a cell address for the “Output Range” for where the random draws will
appear in that cell and downward and to the right.
Step 1c: Transform U(0, 1) to beta (∙) pdf using the inverse CDF technique:
Each draw of loss  = BETAINV(U(0,1), , , 0, 1)
You may get issues with extreme draws, U(0,1) 0.00000001 or 0.99999999, so let’s set extremly
low draws to min and extremely high draws to max, and the others to the inverse cdf.
= if(U(0,1) < 0.000001, min, if(U(0,1) > 0.999999,max, BETAINV(U(0,1),,,0,1)))
Step 2: Calculate Profit and Utility for each draw
Step 2a: Specify Economic parameters P, Ypf, T, K, and R
I usually start with a sensible base case, and then adjust after that once I have the system
working. For now start with  = 0.03,  = 0.1, P = $6/bu, Y = 150 bu/ac, T = $20/ac, K =
$700/ac and R = 0.005. I usually create a place in the excel sheet for parameters.
Step 2b: Calculate no, Bt, U(no) and U(Bt) for each draw
Use these formulas: no = PYpf(1 – ) – K, Bt = PYpf – T – K, and U() = – exp(– R)). Link
the economic parameters to the cells where set them (anchored with $’s) and use the random
draw for . You will end up with four columns: Pi_no, Pi_Bt, U_no, and U_Bt.
Note that because nothing is random with Bt, the values of Pi_Bt and U_Bt are constant. We
will relax this assumption later.
Step 2c: Estimate integrals and other measures of interest
E[no] = Average no over all draws
E[Bt] = Average Bt over all draws
E[Uno] = average of Uno over all draws
E[UBt] = average of UBt over all draws
Certainty Equivalent: CEno = – ln(–E[Uno])/R and CEBt = – ln(–E[UBt])/R
Other measures based on numerical estimates of integrals
StDev(no) = StDev(no) over all the draws
CV(no) = StDev(no) over all the draws / E[no]
Skewness(no) = Skew(no) over all draws
Key probabilities (example):
Pr(no < Bt) = (Count of no < Bt) / total draws [Break Even Probability]
Excel’s countif function cannot use cell addresses in the criteria, so not able to easily
calculate (Count of no < Bt).
Another way to do Break Even Probability: Pr(no < Bt) = Pr(0 < Bt – no) = Pr( > 0)
a) Create a column  = Bt – no
b) Set a parameter “key” = the  difference of interest. Above we used 0.
c) Create a column “count” = if( > key,1,0) which = 1 if  > key and = 0 otherwise
d) Average(column “count”) is the proportion of times that count = 1 = Pr( > key)
Step 3: Calibrate Model and Conduct Analysis
Set economic parameters for base case, then set CARA R so that implied Risk Premium RP = EP
– CE is approximately 20-25% of Expected Profit for a moderate level of risk aversion, 35-40%
for high level. Once set CARA R, do not change it (i.e. do not recalibrate R for each parameter
change so that have a constant RP of x%).
Analysis ideas: Derive interesting curves
a) Set of  and  pairs that give  or CE = 0 (adoption indifference curves)
b) Plot break even probability versus tech fee T, mean loss  or st dev loss , etc.
Case 2 (Discrete Choice, Multiple Random Variables)
Add more sources of variability: assume pest free yield Ypf and/or crop price P are random.
Here we will assume they are independent, drawing correlated random variables takes more than
have time for in this class. Basic idea: multiply the vectors of U(0,1) RVs by a matrix to
generate correlated U(0,1), then transform them to the desired distributions.
Multiple Independent Random Variables
Step 1: Draw all the random variables you need, say loss, yield and price
Like step 1 above, except now have more than one to draw
Yield: assume a Weibull distribution, which has 2 parameters ( and )
Mean = [( + 1)/]
StDev = sqrt{( + 2)/) – ([( + 1)/])2}
Excel does not have the gamma function [∙], but the ln([∙]) = GAMMLN(∙), so
to get [∙], must use exp(ln([∙])) = exp(GAMMLN(∙)).
Inverse CDF = (–ln(1–U))^(1/)
Draw U(0,1), then transform to Weibull using the inverse of the CDF above,
setting ( and ) as seems best, e.g., ( = 175 and  = 4 imply mean yield of
158.6, st dev of 44.5, so CV – 28.1%
Price: assume a lognormal distribution, which has 2 parameters ( and , the mean and st
dev of the underlying normal pdf). Given mean and stdev of price, m and s are:
 = 2ln(mean) – 0.5ln(mean2 + stdev2)
 =sqrt{ln(mean2 + stdev2) – 2ln(mean)}
Drawing lognormal: do not use inverse CDF technique, but instead, draw normal
RV and transform to lognormal, since exp(normal) has a lognormal pdf.
a. Draw N(0,1)
b. Smooth N(0,1) draws: for each draw di, subtract average of draws (d) and
divide by st dev of draws (d), so new draw di  (di  d ) /  d , where
c. Calculate  and  parameters of lognormal
d. Price draw = exp( +  d )
Once have the price and yield draws, along with the loss draws, are ready for Step 2
Step 2: Calculate Profit and Utility for each draw
Like Step 2 above, expect now when calculating profit and utility for each draw, you
have more than one variable in the formula that is a random draw rather than a set
parameter.
Calibrate model and then identify the option (no or Bt) that gives the highest expected
profit or certainty equivalent.
Case 2 (Continuous Choice Variable)
The problem here is to identify the level of a single continuous random variable that maximizes
expected profit or expected utility. We will do examples, based on two papers
1) Seo, S., P.D. Mitchell, and D. Leatham. 2005. Effects of federal risk management
programs on optimal acreage allocation and nitrogen use in a Texas cotton-sorghum
system. J Agric Appld Econ 37:685-699.
2) Babcock, B., and A. Blackmer. 1992. The value of reducing temporal input
nonuniformities. J Agric Resourc Econ 17:335-347.
The general process is similar to that used for the discrete case, expect now the parameters of the
distribution depend functionally on the choice variable. Ponce we set up the functional
dependence of the pdf on the choice variable, we then manually change the choice variable and
identify the level that maximizes expected profit or expected utility/certainty equivalent.
Both examples here focus on nitrogen use, but express the dependence of profit on the choice
variable differently.
 Seo et al. (2005) assume that yield has a beta distribution, with the mean and variance of
yield specified as quadratic functions depending on the chosen N rate.
 Babcock and Blackmer (1992) assume yield is an LRP function of the soil N level, with
soil N following a gamma distribution with parameters depending on the chosen N rate.
Economic theory
Model  = pf(x,) – rx, choose x to maximize E[U()]
max E[U ( )]  E[U ( pf ( x,  )  rx)]
x
FOC: E[U '( )( pf '( x,  )  r )]  0
E[U '( )( pf '( x,  )  r )]  E[U '( )( pf '( x,  )]  rE[U '( )]  0
E[U '( )( pf '( x,  )]  rE[U '( )]
Note E[XY] = E[X]E[Y] + cov(X,Y)
E[U '( )( pf '( x,  )]  E[U '( )]E[ pf '( x,  )]  cov[U '( ), pf '( x,  )]  rE[U '( )]
cov[U '( ), pf '( x,  )]
pE[ f '( x,  )] 
r
E[U '( )]
pE[MP] +cov(U,MP)/EU = r
EU creates wedge between optimal solution without risk
Seo et al.: Cotton yield, equations (9) and (10)
Mean = m0 + m1N + m2N2 = 586 + 2.06N – 0.0111N2
Variance = s0 + s1N + s2N2 = 68600 – 569N + 6.72N2
See how N increases, then decreases mean and at low N, decrease variability, but at higher rates,
increases yield variability.
Step 1: Set N rate
Step 2: Calculate implied mean and st dev using)
Mean  = 586 + 2.06N – 0.0111N2
StDev  = sqrt(68600 – 569N + 6.72N2)
Step 3: Calculate implied parameters of beta density
I assume min = 0 and =  + 2.5 (rounded to nearest pound of cotton), then use
(   min)2 (max   )   2 (   min)
(   min)(max   )2   2 (max   )
and


(max  min) 2
(max  min) 2
Notice how now the  and  depend on the N rate through the  and .

Step 4: Draw Uniform (0, 1)
Step 5: Transform to beta distribution using =BETAINV(U(0,1), , , min, max)
Step 6: Set remaining economic parameters, then calculate profit and utility for each draw
Step 7: Calibrate model, then vary N manually until you identify the N rate the maximizes
expected profit and expected utility/certainty equivalent.
For CARA R coefficient, I like to calibrate it so that the implied risk premium with expected
profit max is around 20-25% of expected profit, then re-optimize for EU/CE max.
Example Results: Shows little impact of EU max on optimal N Rate
R=0.00072
EP max
CE max
N*
61
58
EP
41.00
40.93
CE
30.63
30.68
Babcock et al.: Soil N (ppm) has a gamma pdf with parameters that depend on N applied
3 parameter gamma pdf (, and ) (equation (7) and Table 1)
 = 0 + 1N = 4.920 – 0.00478N
 = 0 + 1N = 1.963 + 0.0279N
 = 0 + 1N = 0 + 0.0366N
Note this 3 parameter gamma is the same as  + 2 parameter gamma
FYI: Mean Soil N =  +  and StDev Soil N = sqrt() (to check simulations)
Step 1: Set N rate
Step 2: Calculate parameters , and  (implied mean and st dev)
Step 3: Draw Uniform (0, 1)
Step 4: Transform to gamma pdf using =  + GAMMAINV(U(0,1), ,)
Step 5: Set remaining economic parameters, then calculate yield, profit and utility for each draw
Note: LRP Yield = 51.64 + 3.95 x min{24.44, SoilN}
(Table 3)
Step 6: Calibrate model, then vary N manually until you identify the N rate the maximizes
expected profit and expected utility/certainty equivalent.
Example Results: Shows large impact of EU max on optimal N Rate
CfC
R=0.0062
EP max
CE max
N*
149
181
EP
106.58
102.64
CE Pr(Yplat)
79.77
0.669
84.67
0.761
Download