代写代考 DAT 537 Assignment 1″

title: “DAT 537 Assignment 1”

pdf_document:
latex_engine: xelatex

Copyright By PowCoder代写 加微信 powcoder

“`{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

Note: This is an individual assignment. No discussion with a fellow student is allowed. Honor code is in place.

## Question 1

Create a numeric vector (call it x) that starts from -2 to 3 by 0.1 (the increment). Now answer the following questions.

1. How many elements does x have?
2. Now let s = 6. How would you extract the first s elements of x? How would you extract the last s elements of x?
3. How would you extract all the elements of x that are within 0.8 of the median of x?

## Question 2

1. Create a sequence of class Date that starts from September 1, 2022 and ends on September 30, has all the days, but omits weekend days.

## Question 3

1. Write a function (call it mylm) that takes two inputs: a vector y of n elements and a matrix X of n times k elements, where n should be greater than k, and returns three outputs: bhat = solve(X’X)X’y, X’X and X’y (the prime symbol means transpose). Use the attr method to return the second and third outputs. Note that you do not need to specify values for y and X when you write this function.

## Question 4

1. Now write the same function as in Q3, but use the list method to return the second output.

## Question 5

1. Write a function called momentum that takes as inputs (1) the ticker symbol of a traded asset, (2) the starting month of the data series and (3) the last month of the data series. The function then uses the quantmod library to download monthly data from Yahoo finance. It then extracts the adjusted closing prices of that asset. And for this price sequence it calculates, and returns, the conditional probability that the change in price this month will be positive given that the change in price in the previous month was negative. Use this function to calculate these conditional probabilities for the SP500 index (ticker symbol \^gspc) and Proctor and Gamble (ticket symbol PG). Is there momentum in these assets?

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com