View the step-by-step solution to:

Question

when i am doing this part, i can't get any output like the first picture. (use R studio) does my step is taking

wrong? What should I do? Can you give me the steps?



1109451611094515

1.jpg

X
65
Source on Save / -
Environment History
Run Source -
66
## Approach 2: apply a function over all (or selected) elements ove A
Import Dataset
67
# Note: data frame is like a list; each column is an element of a 7
# rm(list = 'ret_df_1')
Global Environment -
68
Data
69
ret_df_1 <- mutate_all(ds_cls_1[, -1], cal_return)
70
ret_df_1 <- mutate(ret_df_1, Date = ds_cls_1$Date) %% select(Date,
Ods_cls_1 3225 ob
71
ret_df_1; head(ret_df_1, 3); tail(ret_df_1, 3)|
72
73
### Report the mean, variance and standard deviations of the daily
Files
Plots Packages
74
## write a summary function and use sapply again
Install Update
75 -
Name
Description
70:45
(Top Level) :
R Script
User Library
Console
Terminal * ~ Jobs x
assertt...
Easy Pre and Po
Assertions
C:/Users/user/Desktop/
+ rel_ul_1 <- mutate_dil(us_CIs_IL, -1j, cal_recurn)
BH
Boost C+ + Head
+ ret_df_1 <- mutate(ret_df_1, Date = ds_cls_1$Date) %%% select(Date, eve
Files
rything())
cli
Helpers for Devel
+ ret_df_1; head(ret_df_1, 3); tail(ret_df_1, 3)
Command Line
+ ret_df_1 <- mutate_all(ds_cls_1[, -1], cal_return)
Interfaces
+ ret_df_1 <- mutate(ret_df_1, Date = ds_cls_1$Date) %>% select(Date, eve
clip
Read and Write
rything())
the System Clipbo
+ ret_df_1; head(ret_df_1, 3); tail(ret_df_1, 3)
0
colors...
A Toolbox for
+
Manipulating and
9
R
Co

2.jpg

Question (a): Calculate the stock return as "t =
(Price, - Pricet-1) x100% for each stock. Report
Pricet-1
the mean, variance and standard deviations of the daily returns of each series.
Task (a.1): Calculating stock returns
R commands:
cal_return <- function(price_x, diff_len = 1) {
price_x = c(rep(NA, diff_len), diff(price_x, diff_len) /
price_x
lag(price_x, diff_len) [-seq_len(diff_len) ]) * 100
The command "mutate_all" applies the function "cal_return" to all (or selected) elements in the list
"ds_cls_1".
ret_df_1 <- mutate_all(ds_cls_1[, -1], cal_return)
ret_df_1 <- mutate(ret_df_1, Date = ds_cls_1$Date) %>% select(Date, everything())
ret_df_1; head(ret_df_1, 3); tail(ret_df_1, 3)
Output :
## # A tibble: 4, 383 x 6
##
Date
p_AAN p_IBN p_MSFT p_SBUX
p_WMT
<date>
<dbl> <dbl> <dbl> <dbl>
<dbl>
##
1 2000-01-03 NA
NA NA
NA
NA
# #
2
2000-01-04 -1.49
NA -3.38
-3.17
-3.74
##
2000-01-05
NA 1.05
1.31
-2.04
# #
2000-01-06 -1.89
NA -3.35
3.62
1.09
# #
2000-01-07 -2.31
NA 1.31
-0.498
7.56
##
6 2000-01-10 -1.58
NA 0.729
4.26
-1.82
##
7 2000-01-11 -0.400
NA -2.56
-2.88
-1.49
##
8 2000-01-12 -0.802
NA - 3.26
0.247 -1.79
## 9 2000-01-13 3.64
NA 1.89
7. 16
0.0961
## 10 2000-01-14 -3.12
NA 4.12
-2.53
-0.960
## # ... with 4, 373 more rows
## # A tibble: 3 x 6
##
Date
P_AAN P_IBN p_MSFT p_SBUX p_WMT
<date>
<dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2000-01-03 NA
NA NA
NA
NA
## 2 2000-01-04 -1.49
NA -3.38
-3.17 -3.74
## 3 2000-01-05 0
NA
1.05
1.31 -2.04
## # A tibble: 3 x 6
# #
Date
P_AAN P_IBN p_MSFT p_SBUX p_WMT
##
<date>
<dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2017-06-01 4.35 -1.31
0.372 0.220 1.54
## 2 2017-06-02 2.73 0. 102 2.37
1.29
-0.238
## 3 2017-06-05 -0.613 -0. 102 0. 725 -0.465 0.804
4

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Econometrics tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors