forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_11_1.R
38 lines (28 loc) · 1.1 KB
/
ex_11_1.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
#
# Written by:
# --
# John L. Weatherwax 2009-04-21
#
# email: [email protected]
#
# Please send comments and especially bug reports to the
# above email address.
#
#-----
lambda_buy = seq( from=0, to=2, length.out=100 )
lambda_sell = lambda_buy
p_lambda_buy = 3 - lambda_buy + 0.2 * lambda_buy^2
p_lambda_sell = 2 + 0.2 * lambda_sell + 0.2 * lambda_sell^2
#postscript("../../WriteUp/Graphics/Chapter11/ex_11_1_p_vs_lambda_plot.eps", onefile=FALSE, horizontal=FALSE)
plot( lambda_buy, p_lambda_buy, col="red", type="l", xlab="lambda", ylab="p(lambda)" )
lines( lambda_sell, p_lambda_sell, col="blue" )
#dev.off()
# To find the optimal bid and ask prices we can maximize the expression lambda * ( p_lambda_buy - p_lambda_sell )
exp_to_max = lambda_buy * ( p_lambda_buy - p_lambda_sell )
plot( lambda_buy, exp_to_max )
spot = which.max( exp_to_max )
max_value = max(exp_to_max)
max_argument = lambda_buy[spot]
p_bid = p_lambda_sell[spot]
p_ask = p_lambda_buy[spot]
print( sprintf("max profit= %6.6f; lambda= %6.6f; p_bid = %6.2f; p_ask= %6.2f", exp_to_max[spot], lambda_buy[spot], p_bid, p_ask ) );