Learn R Programming

GE (version 0.3.8)

gemSecurityPricing: Compute Security Market Equilibria for Some Simple Cases

Description

Compute the equilibrium of a security (i.e. asset) market by the function sdm2 and by computing marginal utility of securities (see Sharpe, 2008).

Usage

gemSecurityPricing(
  S = diag(2),
  UP = diag(nrow(S)),
  uf = NULL,
  muf = NULL,
  ratio_adjust_coef = 0.05,
  numeraire = 1,
  ...
)

Value

A general equilibrium containing a value marginal utility matrix (VMU).

Arguments

S

an n-by-m supply matrix of securities.

UP

a unit (security) payoff k-by-n matrix.

uf

a utility function or a utility function list.

muf

a marginal utility function or a marginal utility function list.

ratio_adjust_coef

a scalar indicating the adjustment velocity of demand structure.

numeraire

the index of the numeraire commodity.

...

arguments to be passed to the function sdm2.

References

Danthine, J. P., Donaldson, J. (2005, ISBN: 9780123693808) Intermediate Financial Theory. Elsevier Academic Press.

Sharpe, William F. (2008, ISBN: 9780691138503) Investors and Markets: Portfolio Choices, Asset Prices, and Investment Advice. Princeton University Press.

Wang Jiang (2006, ISBN: 9787300073477) Financial Economics. Beijing: China Renmin University Press. (In Chinese)

Xu Gao (2018, ISBN: 9787300258232) Twenty-five Lectures on Financial Economics. Beijing: China Renmin University Press. (In Chinese)

https://web.stanford.edu/~wfsharpe/apsim/index.html

See Also

gemSecurityPricingExample.

Examples

Run this code
# \donttest{
gemSecurityPricing(muf = function(x) 1 / x)

gemSecurityPricing(
  S = cbind(c(1, 0), c(0, 2)),
  muf = function(x) 1 / x
)

gemSecurityPricing(
  UP = 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
UP <- 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),
  UP = UP,
  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),
  UP = UP,
  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(UP,
  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),
  UP = UP,
  muf = function(x) (1 - x / 200) * 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),
  UP,
  muf = function(x) abs((x - 20)^(-1)) * wt,
  maxIteration = 100,
  numberOfPeriods = 300,
  ts = TRUE
)

geSharpe4$p
geSharpe4$p[3:4] + 3 * geSharpe4$p[2]

## an example of Sharpe (2008, chapter 6, case 14)
prob1 <- c(0.15, 0.26, 0.31, 0.28)
wt1 <- prop.table(c(1, 0.96 * prob1))
prob2 <- c(0.08, 0.23, 0.28, 0.41)
wt2 <- prop.table(c(1, 0.96 * prob2))

uf1 <- function(x) CES(alpha = 1, beta = wt1, x = x, es = 1 / 1.5)
uf2 <- function(x) CES(alpha = 1, beta = wt2, x = x, es = 1 / 2.5)
geSharpe14 <- gemSecurityPricing(
  S = matrix(c(
    49, 49,
    30, 30,
    10, 0,
    0, 10
  ), 4, 2, TRUE),
  UP = UP,
  uf = list(uf1,uf2)
)

geSharpe14$D
geSharpe14$p
geSharpe14$p[3:4] + 3 * geSharpe14$p[2]
mu <- marginal_utility(geSharpe14$Payoff, diag(5),uf=list(uf1,uf2))
mu[,1]/mu[1,1]
mu[,2]/mu[1,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 * c(0.5, 0.25, 0.25),
    function(x) 1 / sqrt(x) * 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),
  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, prob = wt)$u,
    function(x) CRRA(x, gamma = 0.5, prob = wt)$u
  )
)

ge$p # c(1, (1 + sqrt(5)) / 4, (1 + sqrt(17)) / 16)

#### an example of incomplete market
ge <- gemSecurityPricing(
  UP = 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(
  UP = cbind(c(1, 1), c(2, 1)),
  muf = list(
    function(x) 1 / x * c(0.5, 0.5),
    function(x) 1 / sqrt(x) * 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")

#### an example with outside position.
asset1 <- c(1, 0, 0)
asset2 <- c(0, 1, 1)

# unit (asset) payoff matrix
UP <- cbind(asset1, asset2)
wt <- c(0.5, 0.25, 0.25) # weights

uf1 <- function(x) prod((x + c(0, 0, 2))^wt)
uf2 <- function(x) prod(x^wt)

ge <- gemSecurityPricing(
  S = matrix(c(
    1, 1,
    0, 2
  ), 2, 2, TRUE),
  UP = UP,
  uf = list(uf1, uf2),
  numeraire = 1
)

ge$p
ge$z
uf1(ge$Payoff[,1])
uf2(ge$Payoff[,2])
# }

Run the code above in your browser using DataLab