forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchap_12_plot_EU.R
37 lines (28 loc) · 1.12 KB
/
chap_12_plot_EU.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#
# Written by:
# --
# John L. Weatherwax 2009-04-21
#
# email: [email protected]
#
# Please send comments and especially bug reports to the
# above email address.
#
#-----
limit_prices = seq( from=0, to=2, length.out=100 )
EU_of_n = function(n){
EU = ( 1 - exp( - limit_prices ) ) * ( -exp( -(n+1-limit_prices) + 0.5 * (n+1)^2 ) ) + exp( -limit_prices ) * ( - exp( -n + 0.5 * n^2 ) )
return(EU)
}
neg_log_neg_EU_n_0 = - log( -EU_of_n(0.) )
neg_log_neg_EU_n_m1 = - log( -EU_of_n(-1) )
neg_log_neg_EU_n_m2 = - log( -EU_of_n(-2) )
rng = range( c(neg_log_neg_EU_n_0, neg_log_neg_EU_n_m1, neg_log_neg_EU_n_m2 ) )
#postscript("../../WriteUp/Graphics/Chapter12/dup_fig_12_1.eps", onefile=FALSE, horizontal=FALSE)
plot( limit_prices, neg_log_neg_EU_n_0, ylim=rng, type="l", col="black" )
lines( limit_prices, neg_log_neg_EU_n_m1, col="red" )
lines( limit_prices, neg_log_neg_EU_n_m2, col="green" )
#dev.off()
limit_spot = which.max( neg_log_neg_EU_n_m1 )
optimal_limit_price = limit_prices[limit_spot]
print( sprintf("optimal price=%10.2f; prob_execution= %10.6f",optimal_limit_price, 1-exp(-optimal_limit_price)) )