关于算法:ECMT3150-R语言统计汇总

36次阅读

共计 4063 个字符,预计需要花费 11 分钟才能阅读完成。

ECMT3150: Assignment 1 (Semester 1, 2023)

  1. [Total: 24 marks]
    Note: Please append your R codes (as a separate .R le) for part (g) while you submit the
    assignment.
    Let Xi denote the log-price of a stock, Cherry Inc. (code: CRRY), by the end of trading day
    i, and let Xi := Xi Xi1; thus Xi is the log-return on trading day i (i.e., over period
    (i 1; i]).
    Assume fXig_i0 follows the AR(1) model:
    Xi = 0 + 1Xi1 + ui: (1)
    where ui iid normal with mean 0 and variance 2.
    Let fFigi0 be the natural ?ltration generated by fuigi0.
    (a) [2 marks] Express Xi in terms of Xi1 and ui.
    (b) [2 marks] Compute E(XijFi1).
    (c) [2 marks] Compute V ar(XijFi1).
    (d) [2 marks] What is the condition on 0 and 1 such that fXigi1 is a martingale
    di¤erence sequence?
    A trading strategy is de?ned by figi0, where i is measurable with respect to Fi. Speci?-
    cally, i represents the number of CRRY shares a trader buys at the start of day i.
    The log-return due to the trading strategy over period (0; T] is given by
    rT =
    TX
    i=1
    i1Xi.
    (e) [4 marks] Alice invested in a share of CRRY using a buy-and-hold strategy, with i 1
    for all i. Compute E(rT) and V ar(rT) with 0 = 0 and 1 = 1.
    (f) [4 marks] Bob suggested another strategy, with i Xi for i > 0 and Compute E(rT)
    and V ar(rT) with 0 = 0 and 1 = 1.
    1
    (g) [8 marks] Carol suggested yet another strategy, with i 1fXi > 0g and 0 = 1.
    We want to evaluate the risk-return tradeo¤ of the proposed strategies using computer
    simulation.
    Start an R session, and set a random seed equal to the last 3 digits of your student ID.1
    Then generate B sample values of rT (name them as r
    (1)
    T ; r
    (2)
    T ; : : : ; r
    (B)
    T ), and compute
    the sample mean and variance of rT as follows:
    rT =
    1
    B
    BX
    b=1
    r
    (b)
    T ;
    se(rT) =
    1
    B 1
    BX
    b=1
    (r
    (b)
    T rT )2:
    For the purpose of your simulations, set T = 63, 2 = 0:1, B = 1000.
    The Sharpe ratio, de?ned as SR = rTse(rT) , is a common measure of the risk-return
    tradeo¤. Trading strategies with higher SR are more preferred by investors.
    Complete the following table with SR values. Comment on the performance of the
    trading strategies under di¤erent scenarios.
  2. 1 Alice Bob Carol
  3. 1
    0:01 1
    0:01 1
  4. 0:9
  5. 1:1
  6. [Total: 16 marks] LetM denote the mood of Mimi (h: happy; a: angry), and let W denote
    the weather (s: sunny; r: rainy). The joint probability distribution of M and W is given in
    the table below. The row and column sums are displayed in the last column and in the last
    row, respectively.
    p(m;w) M = h M = a
    W = s 0:4 0:1
    W = r 0:2 0:3
    (a) [2 marks] Compute P (M = a).
    (b) [2 marks] Derive the conditional distribution of W given M = a.
    Assume that, given m and w, your test score S follows a normal distribution with mean
    (m;w) := E(SjM = m;W = w) and standard deviation 5. The conditional mean function
    (m;w) is given in the table below:
    1This is to ensure that your answers are replicable but di¤erent from those of other students.
    2
    (m;w) m = h m = a
    w = s 80 50
    w = r 70 40
    The passing score is 50 or above.
    (c) [3 marks] Compute the mean score E(S).
    (d) [3 marks] Given that Mimi was angry, what is the mean score you would get?
    (e) [3 marks] Compute the probability of failing the test.
    (f) [3 marks] Given that you failed the test, what is the probability that Mimi was angry?
  7. [Total: 20 marks]
    Note: Please append your R codes (as a separate .R ?le) while you submit the assignment.
    Carol, an amateur economist, proposes the following time series model for unemployment
    rate:
    yt =
    1
    20
    +
    p
    3
    2
    yt1 1
    4
    yt2 + “t; (2)
    where “t iid N(0; 0:022) (normal distribution with mean 0 and variance 0:022). The time
    period is measured in number of quarters.
    (a) [3 marks] Show that the time series fytg generated by model (1) is stationary.
    (b) [3 marks] There is a stochastic cycle in the time series generated by model (1). Find its
    periodity in number of quarters.
    (c) [4 marks] Compute the ACF for the ?rst 3 lags, i.e., (1), (2) and (3).
    (d) [2 marks] Write an R program to simulate a sample path of fytg over 30 years. Set the
    initial values y0 and y1 to be y0 = 0:1 and y1 = 0:12. While simulating the random
    numbers for “t, set the random seed to be your last 3 digits of your student ID.
    (e) [2 marks] Plot the sample ACF and record its value for the ?rst 3 lags (the values can be
    retrieved from the acf command output stored as a list). Why are they di¤erent from
    your answers in part (c)?
    (f) [3 marks] Using the simulated sample path in part (d), estimate an AR(2) model using
    the R command arima. Write down the estimated model with the parameter estimates
    and their standard error. Also record the estimated variance of the innovations.
    [Important note: the ?intercept?estimate in the arima output is in fact the unconditional
    mean; see Rob Hyndman?s page for details: https://robjhyndman.com/hyndsight/
    arimaconstants/.]
    (g) [3 marks] Using the simulated sample path in part (d) and the R package forecast,
    plot the point forecast and the con?dence interval for each period over the next 5 years.
    Describe the short-run and long-run behaviour of the point forecast and the con?dence
    interval.
正文完
 0