# NOT RUN {
gemSecurityPricing(muf = function(x) 1 / x)
gemSecurityPricing(
S = cbind(c(1, 0), c(0, 2)),
muf = function(x) 1 / x
)
gemSecurityPricing(
USP = cbind(c(1, 0), c(0, 2)),
muf = function(x) 1 / x
)
#### an example of Danthine and Donaldson (2005, section 8.3).
ge <- gemSecurityPricing(
S = matrix(c(
10, 5,
1, 4,
2, 6
), 3, 2, TRUE),
uf = function(x) 0.5 * x[1] + 0.9 * (1 / 3 * log(x[2]) + 2 / 3 * log(x[3]))
)
ge$p
#### an example of Sharpe (2008, chapter 2, case 1)
secy1 <- c(1, 0, 0, 0, 0)
secy2 <- c(0, 1, 1, 1, 1)
secy3 <- c(0, 5, 3, 8, 4) - 3 * secy2
secy4 <- c(0, 3, 5, 4, 8) - 3 * secy2
# unit security payoff matrix
USP <- cbind(secy1, secy2, secy3, secy4)
prob <- c(0.15, 0.25, 0.25, 0.35)
wt <- prop.table(c(1, 0.96 * prob)) # weights
geSharpe1 <- gemSecurityPricing(
S = matrix(c(
49, 49,
30, 30,
10, 0,
0, 10
), 4, 2, TRUE),
USP = USP,
uf = list(
function(x) CES(alpha = 1, beta = wt, x = x, es = 1 / 1.5),
function(x) CES(alpha = 1, beta = wt, x = x, es = 1 / 2.5)
)
)
geSharpe1$p
geSharpe1$p[3:4] + 3 * geSharpe1$p[2]
## an example of Sharpe (2008, chapter 3, case 2)
geSharpe2 <- gemSecurityPricing(
S = matrix(c(
49, 49, 98, 98,
30, 30, 60, 60,
10, 0, 20, 0,
0, 10, 0, 20
), 4, 4, TRUE),
USP = USP,
uf = list(
function(x) CES(alpha = 1, beta = wt, x = x, es = 1 / 1.5),
function(x) CES(alpha = 1, beta = wt, x = x, es = 1 / 2.5),
function(x) CES(alpha = 1, beta = wt, x = x, es = 1 / 1.5),
function(x) CES(alpha = 1, beta = wt, x = x, es = 1 / 2.5)
)
)
geSharpe2$p
geSharpe2$p[3:4] + 3 * geSharpe2$p[2]
geSharpe2$D
## an example of Sharpe (2008, chapter 3, case 3)
geSharpe3 <- gemSecurityPricing(USP,
uf = function(x) (x - x^2 / 400) %*% wt,
S = matrix(c(
49, 98,
30, 60,
5, 10,
5, 10
), 4, 2, TRUE)
)
geSharpe3$p
geSharpe3$p[3:4] + 3 * geSharpe3$p[2]
# the same as above
geSharpe3b <- gemSecurityPricing(
S = matrix(c(
49, 98,
30, 60,
5, 10,
5, 10
), 4, 2, TRUE),
USP = USP,
muf = function(x) (1 - x / 200),
wt = wt
)
geSharpe3b$p
geSharpe3b$p[3:4] + 3 * geSharpe3b$p[2]
## an example of Sharpe (2008, chapter 3, case 4)
geSharpe4 <- gemSecurityPricing(
S = matrix(c(
49, 98,
30, 60,
5, 10,
5, 10
), 4, 2, TRUE),
USP,
muf = function(x) abs((x - 20)^(-1)), wt = wt,
maxIteration = 100,
numberOfPeriods = 300,
ts = TRUE
)
geSharpe4$p
geSharpe4$p[3:4] + 3 * geSharpe4$p[2]
#### an example of Wang (2006, example 10.1, P146)
geWang <- gemSecurityPricing(
S = matrix(c(
1, 0,
0, 2,
0, 1
), 3, 2, TRUE),
muf = list(
function(x) 1 / x,
function(x) 1 / sqrt(x)
),
wt = c(0.5, 0.25, 0.25)
)
geWang$p # c(1, (1 + sqrt(17)) / 16)
# the same as above
geWang.b <- gemSecurityPricing(
S = matrix(c(
1, 0,
0, 2,
0, 1
), 3, 2, TRUE), wt = c(0.5, 0.25, 0.25),
uf = list(
function(x) log(x) %*% c(0.5, 0.25, 0.25),
function(x) 2 * sqrt(x) %*% c(0.5, 0.25, 0.25)
)
)
geWang.b$p
#### an example of Xu (2018, section 10.4, P151)
wt <- c(1, 0.5, 0.5)
ge <- gemSecurityPricing(
S = matrix(c(
1, 0,
0, 0.5,
0, 2
), 3, 2, TRUE),
uf = list(
function(x) CRRA(x, gamma = 1, p = wt)$u,
function(x) CRRA(x, gamma = 0.5, p = wt)$u
)
)
ge$p # c(1, (1 + sqrt(5)) / 4, (1 + sqrt(17)) / 16)
#### an example of incomplete market
ge <- gemSecurityPricing(
USP = cbind(c(1, 1), c(2, 1)),
uf = list(
function(x) sum(log(x)) / 2,
function(x) sum(sqrt(x))
),
ratio_adjust_coef = 0.1,
priceAdjustmentVelocity = 0.05,
policy = makePolicyMeanValue(span = 100),
maxIteration = 1,
numberOfPeriods = 2000,
)
ge$p
## the same as above
ge.b <- gemSecurityPricing(
USP = cbind(c(1, 1), c(2, 1)),
muf = list(
function(x) 1 / x,
function(x) 1 / sqrt(x)
),
wt = c(0.5, 0.5),
ratio_adjust_coef = 0.1,
priceAdjustmentVelocity = 0.05,
policy = makePolicyMeanValue(span = 100),
maxIteration = 1,
numberOfPeriods = 2000,
ts = TRUE
)
ge.b$p
matplot(ge.b$ts.p, type = "l")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab