联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Algorithm 算法作业Algorithm 算法作业

日期:2023-02-24 11:36

STA2570 Winter 2023

Assignment 2

March 11, 2023

1. In this exercise we estimate a time series model using a Bayesian approach. We consider

US quarterly inflation data in inflation.csv; it contains 252 values. Consider the AR(2)

model

Yt = α+ φ1Yt?1 + φ2Yt?2 + t, t = 1, . . . , T,

where the t are i.i.d. N(0, σ

2

). Here the parameter is θ = (α, φ1, φ2, σ). We assume that

Y0 and Y?1 are given as known. So for our data set T = 250.

Suppose we use the following prior:

β = (α, φ1, φ2) ~ N(0, I3).

σ2 ~ InverseGamma.

Also β and σ2 are independent under the prior. The definition of the inverse gamma distri-

bution can be found here: https://en.wikipedia.org/wiki/Inverse-gamma_distribution

(a) Write down the likelihood, i.e., the joint density of (Y1, . . . , YT ) as a function of the

parameters.

(b) Consider the posterior density pi(θ|y), where y = (y1, . . . , yT ) is the observed series.

Derive carefully:

– The conditional distribution of β given 2 . (It is normal.)

– The conditional distribution of σ2 given β. (It is inverse gamma.)

(c) Implement the Gibb’s sampler using the results in (a). Report the posterior mean of

each parameter. Compare your results with the frequentist estimates (e.g. using the

function arima() in R).

References: Chapter 1 (in particular Sections 1.3.2–1.3.4) of Applied Bayesian Econometrics for Central

Bankers, available at

www.bankofengland.co.uk/ccbs/applied-bayesian-econometrics-for-central-bankers-updated-2017.

Also see this blog post which explains the material in a more user-friendly way:

towardsdatascience.com/a-bayesian-approach-to-time-series-forecasting-d97dd4168cb7.

2. Consider the following stocks (in the Dow Jones Index). In R, their tickers are given as

follows:

1

symbol_seq <- c("MMM", "AXP", "AMGN", "AAPL", "BA",

"CAT", "CVX", "CSCO", "KO", "DIS",

"GS", "HD", "HON", "IBM",

"INTC", "JNJ", "JPM", "MCD", "MRK",

"MSFT", "NKE", "PG", "CRM", "TRV",

"UNH", "VZ", "V", "WBA", "WMT")

Consider weekly (arithmetic) returns of these stocks from 2017-01-01 to 2022-1-31. We

use the data from 2017-01-01 to 2019-12-31 for training, and the data from 2020-01-01 to

2022-01-31 for testing. In R, the stock prices can be downloaded using the following codes:

library(quantmod)

start_date <- "2017-01-01"

end_date <- "2022-1-31"

R_all <- list()

for (j in 1:length(symbol_seq)) {

symbol <- symbol_seq[j]

price <- getSymbols(Symbols = c(symbol), src = "yahoo",

return.class = "xts",

from = start_date, to = end_date,

periodicity = "daily", auto.assign = FALSE)

R_all[[j]] <- weeklyReturn(price)

# check there are no missing values

cat("j = ", j, "\n", sep = "")

cat(sum(!is.na(R)), " ", sum(is.na(R)), "\n")

}

For the purposes of this problem, we assume that the weekly return vectors are i.i.d. over

time. Over the training period, we estimate the covariance matrix Σ using the empirical

covariance matrix.

(a) Consider the empirical covariance matrix Σ estimated from the training data. Us-

ing quadratic programming, find the global minimum variance portfolio under the

constraints

iwi = 1 and wi ≥ 0 for all i.

(b) Find an equally weighted portfolio with 10 stocks such that the variance (of the

portfolio return) with respect to Σ is minimized. (Use the heuristics introduced in

the class.) Also find the 10 stocks whose variances are the smallest and form an

equally weighted portfolio.

(c) Consider the three portfolios found in (a) and (b). Compare the variances (of their

returns) in the testing period. Also plot density estimates of their return distributions.

Comment on your results.

3. (Taken from Chapter 3 of the book Optimization Methods in Finance (2nd edition), Cam-

bridge University Press) A company will face the following cash requirements in the next

2

eight quarters (positive entries present cash needs while negative entries represent cash

surpluses):

Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8

100 500 100 ?600 ?500 200 600 ?900

The company has three borrowing possibilities:

A 2-year loan available at the beginning of Q1, with a 1% interest per quarter.

The other two borrowing opportunities are available at the beginning of every quarter:

a 6-month loan with a 1.8% interest per quarter, and a quarterly loan with a 2.5%

interest for the quarter.

Any surplus can be invested at a 0.5% interest per quarter.

Formulate a linear program that maximizes the wealth of the company at the beginning

of Q9. (You are invited to solve the problem using an available package, but the solution

is not required.)


相关文章

版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp