ANLY515_HW1_Code_and_Plots.pdf
docx
keyboard_arrow_up
School
Harrisburg University of Science and Technology *
*We aren’t endorsed by this school
Course
515
Subject
Business
Date
Feb 20, 2024
Type
docx
Pages
28
Uploaded by ConstableCrown17410
ANLY515HW1
01/29/2024
Plot the data for each security to check for missing data
1. Citi (Financials)
data.C <- read.csv
(
"C.csv"
, header = TRUE
) head
(data.C)
##
Date Open High Low Close Adj.Close
Volume
## 1 2011-01-03 47.8 49.0 47.8 49.0 43.09877 65798900
## 2 2011-01-04 49.1 49.4 48.3 49.0 43.09877 58340430
## 3 2011-01-05 48.8 50.0 48.8 49.7 43.71446 66673580
## 4 2011-01-06 50.0 50.5 49.3 49.5 43.53856 71529750
## 5 2011-01-07 49.6 50.0 48.4 49.4 43.45059 68069720
## 6 2011-01-10 49.2 49.3 48.7 49.1 43.18671 46153210
class
(data.C)
## [1] "data.frame"
date <- as.Date
(data.C
$
Date, format = "%Y-%m-%d"
) head
(date)
## [1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
## [6] "2011-01-10"
data.C <- cbind
(date, data.C[, -1
]) data.C <- data.C[
order
(data.C
$
date), ] class
(data.C)
## [1] "data.frame"
library
(xts)
## Warning: package ’xts’ was built under R version 4.0.3
## Loading required package: zoo
## Warning: package ’zoo’ was built under R version 4.0.3
##
## Attaching package: ’zoo’
1
## The following objects are masked from ’package:base’:
##
##
as.Date, as.Date.numeric
data.C <- xts
(data.C[, 2
:
7
], order.by = data.C[, 1
]) class
(data.C)
## [1] "xts" "zoo"
names
(data.C)
## [1] "Open"
"High"
"Low"
"Close"
"Adj.Close" "Volume"
names
(data.C) <- paste
(
c
(
"C.Open"
, "C.High"
, "C.Low"
, "C.Close"
,
"C.Adjusted"
, "C.Volume"
)) head
(data.C)
##
C.Open C.High C.Low C.Close C.Adjusted C.Volume
## 2011-01-03
47.8
49.0 47.8
49.0
43.09877 65798900
## 2011-01-04
49.1
49.4 48.3
49.0
43.09877 58340430
## 2011-01-05
48.8
50.0 48.8
49.7
43.71446 66673580
## 2011-01-06
50.0
50.5 49.3
49.5
43.53856 71529750
## 2011-01-07
49.6
50.0 48.4
49.4
43.45059 68069720
## 2011-01-10
49.2
49.3 48.7
49.1
43.18671 46153210
plot
(data.C
$
C.Close)
data.C$C.Close
2011−01−03 / 2015−12−31
2
Jan 03 2011
Jan 03 2012
Jan 02 2013
Jan 02 2014
Jan 02 2015
Dec 31 2015
dim
(data.C)
## [1] 1258
6
summary
(data.C)
##
Index
C.Open
C.High
C.Low
## Min.
:2011-01-03
Min.
:22.56
Min.
:24.10
Min.
:21.40
## 1st Qu.:2012-04-02
1st Qu.:36.70
1st Qu.:37.16
1st Qu.:36.25
## Median :2013-07-04
Median :47.88
Median :48.25
Median :47.4
7
## Mean
:2013-07-02
Mean
:44.29
Mean
:44.74
Mean
:43.80
## 3rd Qu.:2014-10-01
3rd Qu.:51.65
3rd Qu.:52.11
3rd Qu.:51.12
## Max.
:2015-12-31
Max.
:60.29
Max.
:60.95
##
C.Close
C.Adjusted
C.Volume
## Min.
:23.11
Min.
:20.34
Min.
: 4671200
## 1st Qu.:36.71
1st Qu.:32.33
1st Qu.: 17777825
## Median :47.81
Median :42.20
Median : 26960950
## Mean
:44.27
Mean
:39.05
Mean
: 31295855
## 3rd Qu.:51.65
3rd Qu.:45.59
3rd Qu.: 39677100
## Max.
:60.34
Max.
:53.33
Max.
:180960580
Max.
:59.73
2. Blackrock (Financials)
3
30
40
50
60
30
40
50
60
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
data.BLK <- read.csv
(
"BLK.csv"
, header = TRUE
) head
(data.BLK)
##
Date
Open
High
Low Close Adj.Close Volume
## 1 2011-01-03 191.52 195.00 189.53 190.19 145.7494 1085200
## 2 2011-01-04 191.26 191.50 188.71 190.04 145.6343 794400
## 3 2011-01-05 190.03 192.84 189.25 192.00 147.1364 925300
## 4 2011-01-06 192.68 192.79 188.36 189.93 145.5501 727300
## 5 2011-01-07 191.52 191.52 185.46 188.36 144.3469 886200 ## 6 2011-01-10 188.11 191.54 187.43 191.17 146.5003 898300
class
(data.BLK)
## [1] "data.frame"
date <- as.Date
(data.BLK
$
Date, format = "%Y-%m-%d"
) head
(date)
## [1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
## [6] "2011-01-10"
data.BLK <- cbind
(date, data.BLK[, -1
]) data.BLK <- data.BLK[
order
(data.BLK
$
date), ] class
(data.BLK)
## [1] "data.frame"
library
(xts) data.BLK <- xts
(data.BLK[, 2
:
7
], order.by = data.BLK[, 1
]) class
(data.BLK)
## [1] "xts" "zoo"
names
(data.BLK)
## [1] "Open"
"High"
"Low"
"Close"
"Adj.Close" "Volume"
names
(data.BLK) <- paste
(
c
(
"BLK.Open"
, "BLK.High"
, "BLK.Low"
,
"BLK.Close"
, "BLK.Adjusted"
, "BLK.Volume"
)) head
(data.BLK)
##
BLK.Open BLK.High BLK.Low BLK.Close BLK.Adjusted BLK.Volume
## 2011-01-03
191.52
195.00 189.53
190.19
145.7494
1085200
## 2011-01-04
191.26
191.50 188.71
190.04
145.6343
794400
## 2011-01-05
190.03
192.84 189.25
192.00
147.1364
925300
## 2011-01-06
192.68
192.79 188.36
189.93
145.5501
727300
4
2011−01−03 / 2015−12−31
## 2011-01-07
191.52
191.52 185.46
188.36
144.3469
886200
## 2011-01-10
188.11
191.54 187.43
191.17
146.5003
898300
plot
(data.BLK
$
BLK.Close)
data.BLK$BLK.Close
Jan 03 2011
Jan 03 2012
Jan 02 2013
Jan 02 2014
Jan 02 2015
Dec 31 2015
dim
(data.BLK)
## [1] 1258
6
summary
(data.BLK)
##
Index
BLK.Open
BLK.High
BLK.Low
## Min.
:2011-01-03
Min.
:140.1
Min.
:145.4
Min.
:137.0
## 1st Qu.:2012-04-02
1st Qu.:190.5
1st Qu.:191.9
1st Qu.:188.7
## Median :2013-07-04
Median :269.2
Median :271.8
Median :266.7
## Mean
:2013-07-02
Mean
:260.3
Mean
:262.7
Mean
:257.7
## Max.
Max.
5
150
200
250
300
350
150
200
250
300
350
## 3rd Qu.:2014-10-01
3rd Qu.:319.6
3rd Qu.:321.6
3rd Qu.:316.5
## Max.
:2015-12-31
Max.
:380.5
Max.
:382.8
Max.
:377.8
##
BLK.Close
BLK.Adjusted
BLK.Volume
## Min.
:141.8
Min.
:111.1
Min.
: 123500
## 1st Qu.:190.0
1st Qu.:149.7
1st Qu.: 494750
## Median :269.8
Median :223.1
Median : 659550
## Mean
:260.3
Mean
:216.5
Mean
: 752086
## 3rd Qu.:318.8 3rd Qu.:272.2 3rd Qu.: 854975
:380.3 Max. :326.5 :22888000
3. Starbucks (Consumer Discretionary)
data.SBUX <- read.csv
(
"SBUX.csv"
, header = TRUE
) head
(data.SBUX)
##
Date
Open
High
Low Close Adj.Close
Volume
## 1 2011-01-03 16.245 16.710 16.230 16.625 14.08596 12764600
## 2 2011-01-04 16.625 16.645 16.220 16.240 13.75975 13306000
## 3 2011-01-05 16.130 16.420 16.125 16.175 13.70468 11501800
## 4 2011-01-06 16.185 16.250 15.895 15.980 13.53946 13253400
## 5 2011-01-07 16.020 16.430 15.930 16.390 13.88684 19791400 ## 6 2011-01-
10 16.240 16.475 16.065 16.385 13.88261 15540600
class
(data.SBUX)
## [1] "data.frame"
date <- as.Date
(data.SBUX
$
Date, format = "%Y-%m-%d"
) head
(date)
## [1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
## [6] "2011-01-10"
data.SBUX <- cbind
(date, data.SBUX[, -1
]) data.SBUX <- data.SBUX[
order
(data.SBUX
$
date), ] class
(data.SBUX)
## [1] "data.frame"
library
(xts) data.SBUX <- xts
(data.SBUX[, 2
:
7
], order.by = data.SBUX[, 1
]) class
(data.SBUX)
## [1] "xts" "zoo"
6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
2011−01−03 / 2015−12−31
names
(data.SBUX)
## [1] "Open"
"High"
"Low"
"Close"
"Adj.Close" "Volume"
names
(data.SBUX) <- paste
(
c
(
"SBUX.Open"
, "SBUX.High"
, "SBUX.Low"
,
"SBUX.Close"
, "SBUX.Adjusted"
, "SBUX.Volume"
)) head
(data.SBUX)
##
SBUX.Open SBUX.High SBUX.Low SBUX.Close SBUX.Adjusted SBUX.Volume
## 2011-01-03
16.245
16.710
16.230
16.625
14.08596
127646
00
## 2011-01-04
16.625
16.645
16.220
16.240
13.75975
133060
00
## 2011-01-05
16.130
16.420
16.125
16.175
13.70468
115018
00
## 2011-01-06
16.185
16.250
15.895
15.980
13.53946
132534
00
## 2011-01-07
16.020
16.430
15.930
16.390
13.88684
197914
00
## 2011-01-10
16.240
16.475
16.065
16.385
13.88261
155406
00
plot
(data.SBUX
$
SBUX.Close)
data.SBUX$SBUX.Close
## Max.
Max.
7
20
30
40
50
60
20
30
40
50
60
Jan 03 2011
Jan 03 2012
Jan 02 2013
Jan 02 2014
Jan 02 2015
Dec 31 2015
dim
(data.SBUX)
## [1] 1258
6
summary
(data.SBUX)
##
Index
SBUX.Open
SBUX.High
SBUX.Low
## Min.
:2011-01-03
Min.
:15.77
Min.
:15.87
Min.
:15.38
## 1st Qu.:2012-04-02
1st Qu.:24.20
1st Qu.:24.39
1st Qu.:24.00
## Median :2013-07-04
Median :33.49
Median :33.92
Median :33.2
0
## Mean
:2013-07-02
Mean
:33.87
Mean
:34.17
Mean
:33.55
## 3rd Qu.:2014-10-01
3rd Qu.:39.56
3rd Qu.:39.79
3rd Qu.:39.26
## Max.
:2015-12-31
Max.
:63.69
Max.
:64.00
##
SBUX.Close
SBUX.Adjusted
SBUX.Volume
## Min.
:15.77
Min.
:13.36
Min.
: 2204300
## 1st Qu.:24.20
1st Qu.:20.91
1st Qu.: 7526825
## Median :33.60
Median :29.53
Median : 9999700
## Mean
:33.87
Mean
:29.98
Mean
:11647537
## 3rd Qu.:39.56 3rd Qu.:35.14 3rd Qu.:13912800 :63.51
Max. :57.56 :72206200
Max.
:62.97
4. Nike (Consumer Discretionary)
data.NKE <- read.csv
(
"NKE.csv"
, header = TRUE
) head
(data.NKE)
##
Date
Open
High
Low
Close Adj.Close
Volume
## 1 2011-01-03 21.4575 21.6450 21.3150 21.5225 19.05092 8566400
## 2 2011-01-04 21.4000 21.4375 20.9375 20.9925 18.58179 13797600
## 3 2011-01-05 20.9125 21.2075 20.8775 21.1300 18.70350 11598800
## 4 2011-01-06 21.1125 21.1250 20.8900 20.9400 18.53532 8057200
## 5 2011-01-07 20.9250 20.9875 20.8175 20.8825 18.48442 8174400 ## 6 2011-01-10 20.8125 21.1225 20.7650 21.0425 18.62605 8914400
class
(data.NKE)
## [1] "data.frame"
date <- as.Date
(data.NKE
$
Date, format = "%Y-%m-%d"
) head
(date)
## [1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
## [6] "2011-01-10"
8
2011−01−03 / 2015−12−31
data.NKE <- cbind
(date, data.NKE[, -1
]) data.NKE <- data.NKE[
order
(data.NKE
$
date), ] class
(data.NKE)
## [1] "data.frame"
library
(xts) data.NKE <- xts
(data.NKE[, 2
:
7
], order.by = data.NKE[, 1
]) class
(data.NKE)
## [1] "xts" "zoo"
names
(data.NKE)
## [1] "Open"
"High"
"Low"
"Close"
"Adj.Close" "Volume"
names
(data.NKE) <- paste
(
c
(
"NKE.Open"
, "NKE.High"
, "NKE.Low"
,
"NKE.Close"
, "NKE.Adjusted"
, "NKE.Volume"
)) head
(data.NKE)
##
NKE.Open NKE.High NKE.Low NKE.Close NKE.Adjusted NKE.Volume
## 2011-01-03 21.4575 21.6450 21.3150
21.5225
19.05092
85664
00
## 2011-01-04 21.4000 21.4375 20.9375
20.9925
18.58179
137976
00
## 2011-01-05 20.9125 21.2075 20.8775
21.1300
18.70350
115988
00
## 2011-01-06 21.1125 21.1250 20.8900
20.9400
18.53532
80572
00
## 2011-01-07 20.9250 20.9875 20.8175
20.8825
18.48442
81744
00
## 2011-01-10 20.8125 21.1225 20.7650
21.0425
18.62605
89144
00
plot
(data.NKE
$
NKE.Close)
## Max.
Max.
9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
data.NKE$NKE.Close
Jan 03 2011
Jan 03 2012
Jan 02 2013
Jan 02 2014
Jan 02 2015
Dec 31 2015
dim
(data.NKE)
## [1] 1258
6
summary
(data.NKE)
##
Index
NKE.Open
NKE.High
NKE.Low
## Min.
:2011-01-03
Min.
:18.80
Min.
:19.15
Min.
:17.36
## 1st Qu.:2012-04-02
1st Qu.:24.04
1st Qu.:24.29
1st Qu.:23.85
## Median :2013-07-04
Median :31.75
Median :31.94
Median :31.5
6
## Mean
:2013-07-02
Mean
:34.98
Mean
:35.27
Mean
:34.69
## 3rd Qu.:2014-10-01
3rd Qu.:43.46
3rd Qu.:43.98
3rd Qu.:43.19
## Max.
:2015-12-31
Max.
:68.12
Max.
:68.19
##
NKE.Close
NKE.Adjusted
NKE.Volume
## Min.
:18.86
Min.
:16.76
Min.
: 2439600
## 1st Qu.:24.08
1st Qu.:21.70
1st Qu.: 5995850
## Median :31.71
Median :29.09
Median : 7691600
## Mean
:34.99
Mean
:32.27
Mean
: 9038119
## 3rd Qu.:43.57 3rd Qu.:40.63 3rd Qu.:10177200 :67.17
Max. :63.33 :86339600
Max.
:66.67
10
20
30
40
50
60
20
30
40
50
60
2011−01−03 / 2015−12−31
5. Netflix (Technology)
data.NFLX <- read.csv
(
"NFLX.csv"
, header = TRUE
) head
(data.NFLX)
##
Date
Open
High
Low
Close Adj.Close
Volume
## 1 2011-01-03 25.00000 25.83857 24.78571 25.48714 25.48714 39956000
## 2 2011-01-04 25.90714 26.41429 25.47000 25.91000 25.91000 44065700
## 3 2011-01-05 25.87857 26.11286 25.53000 25.67571 25.67571 31799600
## 4 2011-01-06 25.16857 25.67000 25.09286 25.42714 25.42714 31991400
## 5 2011-01-07 25.52429 25.79286 25.19714 25.61429 25.61429 22155000 ## 6 2011-01-
10 25.67143 26.85000 25.59714 26.84000 26.84000 43674400
class
(data.NFLX)
## [1] "data.frame"
date <- as.Date
(data.NFLX
$
Date, format = "%Y-%m-%d"
) head
(date)
## [1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
## [6] "2011-01-10"
data.NFLX <- cbind
(date, data.NFLX[, -1
]) data.NFLX <- data.NFLX[
order
(data.NFLX
$
date), ] class
(data.NFLX)
## [1] "data.frame"
library
(xts) data.NFLX <- xts
(data.NFLX[, 2
:
7
], order.by = data.NFLX[, 1
]) class
(data.NFLX)
## [1] "xts" "zoo"
names
(data.NFLX)
## [1] "Open"
"High"
"Low"
"Close"
"Adj.Close" "Volume"
names
(data.NFLX) <- paste
(
c
(
"NFLX.Open"
, "NFLX.High"
, "NFLX.Low"
,
"NFLX.Close"
, "NFLX.Adjusted"
, "NFLX.Volume"
)) head
(data.NFLX)
##
NFLX.Open NFLX.High NFLX.Low NFLX.Close NFLX.Adjusted NFLX.Volume
## 2011-01-03 25.00000 25.83857 24.78571
25.48714
25.48714
399560
00
## Max.
Max.
11
## 2011-01-04 25.90714 26.41429 25.47000
25.91000
25.91000
440657
00
## 2011-01-05 25.87857 26.11286 25.53000
25.67571
25.67571
317996
00
## 2011-01-06 25.16857 25.67000 25.09286
25.42714
25.42714
319914
00
## 2011-01-07 25.52429 25.79286 25.19714
25.61429
25.61429
221550
00
## 2011-01-10 25.67143 26.85000 25.59714
26.84000
26.84000
436744
00
12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
2011−01−03 / 2015−12−31
plot
(data.NFLX
$
NFLX.Close)
data.NFLX$NFLX.Close
Jan 03 2011
Jan 03 2012
Jan 02 2013
Jan 02 2014
Jan 02 2015
Dec 31 2015
dim
(data.NFLX)
## [1] 1258
6
summary
(data.NFLX)
##
Index
NFLX.Open
NFLX.High
NFLX.Low
## Min.
:2011-01-03
Min.
: 7.713
Min.
: 7.926
Min.
: 7.544
## 1st Qu.:2012-04-02
1st Qu.: 17.487
1st Qu.: 17.750
1st Qu.: 16.911
## Median :2013-07-04
Median : 37.449
Median : 38.154
Median : 36.959
## Mean
:2013-07-02
Mean
: 44.831
Mean
: 45.597
Mean
: 44.055
## 3rd Qu.:2014-10-01
3rd Qu.: 61.532
3rd Qu.: 62.638
3rd Qu.: 61.071
## Max.
:2015-12-31
Max.
:131.190
Max.
:133.270
##
NFLX.Close
NFLX.Adjusted
NFLX.Volume
## Min.
: 7.686
Min.
: 7.686
Min.
: 3531300
Max.
:126.390
## Max.
13
20
40
60
80
100
120
20
40
60
80
100
120
## 1st Qu.: 17.409
1st Qu.: 17.409
1st Qu.: 15593550
## Median : 37.648
Median : 37.648
Median : 22808800
## Mean
: 44.855
Mean
: 44.855
Mean
: 30124902
## 3rd Qu.: 61.936
3rd Qu.: 61.936
3rd Qu.: 34767425 :130.930
Max.
:130.930Max.
:315541800
6. Apple (Technology)
data.AAPL <- read.csv
(
"AAPL.csv"
, header = TRUE
) head
(data.AAPL)
##
Date
Open
High
Low
Close Adj.Close
Volume
## 1 2011-01-03 11.63000 11.79500 11.60143 11.77036 10.13856 445138400
## 2 2011-01-04 11.87286 11.87500 11.71964 11.83179 10.19147 309080800
## 3 2011-01-05 11.76964 11.94071 11.76786 11.92857 10.27484 255519600
## 4 2011-01-06 11.95429 11.97321 11.88929 11.91893 10.26653 300428800
## 5 2011-01-07 11.92821 12.01250 11.85357 12.00429 10.34005 311931200 ## 6 2011-01-
10 12.10107 12.25821 12.04179 12.23036 10.53478 448560000
class
(data.AAPL)
## [1] "data.frame"
date <- as.Date
(data.AAPL
$
Date, format = "%Y-%m-%d"
) head
(date)
## [1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
## [6] "2011-01-10"
data.AAPL <- cbind
(date, data.AAPL[, -1
]) data.AAPL <- data.AAPL[
order
(data.AAPL
$
date), ] class
(data.AAPL)
## [1] "data.frame"
library
(xts) data.AAPL <- xts
(data.AAPL[, 2
:
7
], order.by = data.AAPL[, 1
]) class
(data.AAPL)
## [1] "xts" "zoo"
names
(data.AAPL)
## [1] "Open"
"High"
"Low"
"Close"
"Adj.Close" "Volume"
names
(data.AAPL) <- paste
(
c
(
"AAPL.Open"
, "AAPL.High"
, "AAPL.Low"
,
"AAPL.Close"
, "AAPL.Adjusted"
, "AAPL.Volume"
)) head
(data.AAPL)
14
2011−01−03 / 2015−12−31
##
AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Adjusted AAPL.Volume
## 2011-01-03 11.63000 11.79500 11.60143
11.77036
10.13856
4451384
00
## 2011-01-04 11.87286 11.87500 11.71964
11.83179
10.19147
3090808
00
## 2011-01-05 11.76964 11.94071 11.76786
11.92857
10.27484
2555196
00
## 2011-01-06 11.95429 11.97321 11.88929
11.91893
10.26653
3004288
00
## 2011-01-07 11.92821 12.01250 11.85357
12.00429
10.34005
3119312
00
## 2011-01-10 12.10107 12.25821 12.04179
12.23036
10.53478
4485600
00
plot
(data.AAPL
$
AAPL.Close)
data.AAPL$AAPL.Close
Jan 03 2011
Jan 03 2012
Jan 02 2013
Jan 02 2014
Jan 02 2015
Dec 31 2015
dim
(data.AAPL)
## [1] 1258
6
summary
(data.AAPL)
15
15
20
25
30
15
20
25
30
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
##
Index
AAPL.Open
AAPL.High
AAPL.Low
## Min.
:2011-01-03
Min.
:11.31
Min.
:11.35
Min.
:11.09
## 1st Qu.:2012-04-02
1st Qu.:15.42
1st Qu.:15.55
1st Qu.:15.27
## Median :2013-07-04
Median :19.69
Median :19.84
Median :19.4
1
## Mean
:2013-07-02
Mean
:20.72
Mean
:20.91
Mean
:20.51
## 3rd Qu.:2014-10-01
3rd Qu.:25.31
3rd Qu.:25.55
3rd Qu.:25.13
## Max.
:2015-12-31
Max.
:33.62
Max.
:33.63
##
AAPL.Close
AAPL.Adjusted
AAPL.Volume
## Min.
:11.26
Min.
: 9.70
Min.
:5.219e+07
## 1st Qu.:15.37
1st Qu.:13.48
1st Qu.:2.211e+08
## Median :19.61
Median :17.33
Median :3.266e+08
## Mean
:20.71
Mean
:18.44
Mean
:3.771e+08
## 3rd Qu.:25.31
3rd Qu.:22.93
3rd Qu.:4.722e+08
## Max.
:33.25
Max.
:30.38
Max.
:1.881e+09
Max.
:32.85
16
Plot candlestick charts for one stock from each sector
Apple
wk <- data.AAPL data.weekly <- to.weekly
(wk) data.weekly[
c
(
1
:
3
, nrow
(data.weekly)), ]
##
wk.Open wk.High
wk.Low wk.Close wk.Volume wk.Adjusted
## 2011-01-07 11.63000 12.01250 11.60143 12.00429 1622098800
311931200
## 2011-01-14 12.10107 12.44571 12.04179 12.44571 1800878800
308840000
## 2011-01-21 11.76857 12.45000 11.64286 11.66857 4535801200 754401200 ## 2015-12-31 26.89750 27.35750 26.20500 26.31500 495046000 163649200
library
(quantmod)
## Warning: package ’quantmod’ was built under R version 4.0.3
## Loading required package: TTR
## Warning: package ’TTR’ was built under R version 4.0.3
## Registered S3 method overwritten by ’quantmod’:
##
method
from
##
as.zoo.data.frame zoo
OHLC <- data.weekly[
-
1
, -6
] AAPL.ohlc <- as.quantmod.OHLC
(OHLC, col.names = c
(
"Open"
, "High"
,
"Low"
, "Close"
, "Volume"
))
AAPL.ohlc[
c
(
1
:
3
, nrow
(AAPL.ohlc)), ]
##
OHLC.Open OHLC.High OHLC.Low OHLC.Close OHLC.Volume
## 2011-01-14 12.10107 12.44571 12.04179
12.44571 1800878800
## 2011-01-21 11.76857 12.45000 11.64286
11.66857 4535801200
## 2011-01-28 11.67393 12.34286 11.6685712.00357 2505510000 ## 2015-12-31 26.89750 27.35750 26.20500
26.31500
495046000
chartSeries
(AAPL.ohlc, name = "AAPL OHLC"
, theme = "white.mono"
)
17
AAPL OHLC
[2011−01−14/2015−12−31]
Jan 14 2011
Jul 06 2012
Jan 03 2014
Jul 02 2015
Citi
wk1 <- data.C data.weekly1 <- to.weekly
(wk1) data.weekly1[
c
(
1
:
3
, nrow
(data.weekly1)), ]
18
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
##
wk1.Open wk1.High wk1.Low wk1.Close wk1.Volume wk1.Adjusted
## 2011-01-07
47.80
50.50
47.80
49.40 330412380
680697
20
## 2011-01-14
49.20
51.50
48.70
51.30 308851080
1036343
70
## 2011-01-21
49.30
49.50
47.20
48.90 380564110
655077
70
## 2015-12-31
52.57
53.22
51.75
51.75
38961900
112818
00
library
(quantmod) OHLC1 <- data.weekly1[
-
1
, -6
]
C.ohlc <- as.quantmod.OHLC
(OHLC1, col.names = c
(
"Open"
, "High"
,
"Low"
, "Close"
, "Volume"
))
C.ohlc[
c
(
1
:
3
, nrow
(C.ohlc)), ]
##
OHLC1.Open OHLC1.High OHLC1.Low OHLC1.Close OHLC1.Volume
## 2011-01-14
49.20
51.50
48.70
51.30
3088510
80
## 2011-01-21
49.30
49.50
47.20
48.90
3805641
10
## 2011-01-28
49.10
49.20
47.20
47.20
2155085
40
## 2015-12-31
52.57
53.22
51.75
51.75
389619
00
## 2011-01-14
16.240
16.475
16.030
16.350
705610
00
## 2011-01-21
16.365
16.860
16.235
16.600
704356
00
## 2011-01-28
16.580
16.890
15.760
15.865
1272306
00
## 2015-12-31
60.020
61.400
59.580
60.030
188493
00
chartSeries
(C.ohlc, name = "C OHLC"
, theme = "white.mono"
)
C OHLC
[2011−01−14/2015−12−31]
19
Jan 14 2011
Jul 06 2012
Jan 03 2014
Jul
02
2015
Starbucks
wk2 <- data.SBUX data.weekly2 <- to.weekly
(wk2) data.weekly2[
c
(
1
:
3
, nrow
(data.weekly2)), ]
20
##
wk2.Open wk2.High wk2.Low wk2.Close wk2.Volume wk2.Adjusted
## 2011-01-07
16.245
16.710 15.895
16.39
70617200
197914
00
## 2011-01-14
16.240
16.475 16.030
16.35
70561000
112658
00
## 2011-01-21
16.365
16.860 16.235
16.60
70435600
231298
00
## 2015-12-31
60.020
61.400 59.580
60.03
18849300
49609
00
library
(quantmod) OHLC2 <- data.weekly2[
-
1
, -6
] SBUX.ohlc <- as.quantmod.OHLC
(OHLC2, col.names = c
(
"Open"
, "High"
,
"Low"
, "Close"
, "Volume"
))
SBUX.ohlc[
c
(
1
:
3
, nrow
(SBUX.ohlc)), ]
##
OHLC2.Open OHLC2.High OHLC2.Low OHLC2.Close OHLC2.Volume chartSeries
(SBUX.ohlc, name
= "SBUX OHLC"
, theme = "white.mono"
)
SBUX OHLC
[2011−01−14/2015−12−31]
Jan 14 2011
Jul 06 2012
Jan 03 2014
Jul 02 2015
Develop a plot comparing the capital gains by sector
AAPL
.2013 <- subset
(data.AAPL[, 4
], +
index
(data.AAPL) >= "2013-01-01" & +
index
(data.AAPL) <= "2013-12-31"
)
21
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
NFLX
.2013 <- subset
(data.NFLX[, 4
], +
index
(data.NFLX) >= "2013-01-01" & +
index
(data.NFLX) <= "2013-12-31"
)
BLK
.2013 <- subset
(data.BLK[, 4
], +
index
(data.BLK) >= "2013-01-01" & +
index
(data.BLK) <= "2013-12-31"
)
C
.2013 <- subset
(data.C[, 4
], +
index
(data.C) >= "2013-01-01" &
+
index
(data.C) <= "2013-12-31"
)
SBUX
.2013 <- subset
(data.SBUX[, 4
], +
index
(data.SBUX) >= "2013-01-01" & +
index
(data.SBUX) <= "2013-12-31"
)
NKE
.2013 <- subset
(data.NKE[, 4
], +
index
(data.NKE) >= "2013-01-01" &
+
index
(data.NKE) <= "2013-12-31"
)
22
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Close.Prices <- cbind
(AAPL
.2013
$
AAPL.Close, NFLX
.2013
$
NFLX.Close,
BLK
.2013
$
BLK.Close, C
.2013
$
C.Close, SBUX
.2013
$
SBUX.Close, NKE
.2013
$
NKE.Close)
Close.Prices[
c
(
1
:
3
, nrow
(Close.Prices)), ]
##
AAPL.Close NFLX.Close BLK.Close C.Close SBUX.Close NKE.Close
## 2013-
01-02
19.60821
13.14429
212.77
41.25
27.500
25.9
20
## 2013-
01-03
19.36071
13.79857
213.35
41.39
27.685
26.1
85
## 2013-
01-04
18.82143
13.71143
218.03
42.43
27.845
26.4
40
## 2013-
12-31
20.03643
52.59571
316.47
52.11
39.195
39.3
20
multi.df <- cbind
(
index
(Close.Prices), data.frame
(Close.Prices)) names
(multi.df)
<- paste
(
c
(
"date"
, "AAPL"
, "NFLX"
, "BLK"
, "C"
,
"SBUX"
, "NKE"
)) rownames
(multi.df) <- seq
(
1
, nrow
(multi.df), 1
) multi.df[
c
(
1
:
3
, nrow
(multi.df)), ]
##
date
AAPL
NFLX
BLK
C
SBUX
NKE
## 1
2013-01-02 19.60821 13.14429 212.77 41.25 27.500 25.920
## 2
2013-01-03 19.36071 13.79857 213.35 41.39 27.685 26.185
## 3
2013-01-04 18.82143 13.71143 218.03 42.43 27.845 26.440
## 252 2013-12-31 20.03643 52.59571 316.47 52.11 39.195 39.320
multi.df
$
Tech.idx <- (multi.df
$
AAPL + multi.df
$
NFLX)
/
(multi.df
$
AAPL[
1
] + multi.df
$
NFLX[
1
])
multi.df
$
Financials.idx <- (multi.df
$
C + multi.df
$
BLK)
/
(multi.df
$
C[
1
] + multi.df
$
BLK[
1
])
multi.df
$
Consumer.idx <- (multi.df
$
SBUX + multi.df
$
NKE)
/
(multi.df
$
SBUX[
1
] + multi.df
$
NKE[
1
])
options
(
digits = 5
) multi.df[
c
(
1
:
3
, nrow
(multi.df)), ]
##
date
AAPL
NFLX
BLK
C
SBUX
NKE Tech.idx Financials.idx
## 1
2013-01-02 19.608 13.144 212.77 41.25 27.500 25.920 1.00000
1.0000
## 2
2013-01-03 19.361 13.799 213.35 41.39 27.685 26.185 1.01242
1.0028
## 3
2013-01-04 18.821 13.711 218.03 42.43 27.845 26.440 0.99329
1.0254
## 252 2013-12-31 20.036 52.596 316.47 52.11 39.195 39.320 2.21761
##
Consumer.idx
## 1
1.0000
## 2
1.0084
## 3
1.0162
## 252
1.4698
1.4510
plot
(
x = multi.df
$
date, y = multi.df
$
Tech.idx, type = "l"
, xlab = "Date"
, ylab = "Value of Investment ($)"
, col = "red"
, lty = 1
, lwd = 2
,
main = "Value of $1 Investment in Tech, Financials, and Consumer Discretionary sectors
January 2, 2013 - January 31, 2013"
, cex.main
= 0.8
)
23
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
lines
(
x = multi.df
$
date, y = multi.df
$
Financials.idx, col = "blue"
, lty = 2
, lwd = 1
)
lines
(
x = multi.df
$
date, y = multi.df
$
Consumer.idx, col = "green"
, lty = 2
, lwd = 1
) abline
(
h = 1
, lty = 1
, col = "black"
)
legend
(
"topleft"
, c
(
"Tech"
, "Financials"
, "Consumer"
), col = c
(
"red"
,
"blue"
, "green"
), lty = c
(
1
, 2
, 2
, 1
), lwd = c
(
2
, 1
, 1
, 1
))
Value of $1 Investment in Tech, Financials, and Consumer Discretionary sectors January 2, 2013 − January 31, 2013
Date
Calculate the Rolling 50-Day and 200-Day Average Price
AAPL
.2015 <- subset
(data.AAPL[, 4
], +
index
(data.AAPL) >= "2015-01-01" &
+
index
(data.AAPL) <= "2015-12-31"
)
NFLX
.2015 <- subset
(data.NFLX[, 4
], +
index
(data.NFLX) >= "2015-01-01" &
+
index
(data.NFLX) <= "2015-12-31"
)
Close.Prices
.2015 <- cbind
(AAPL
.2015
$
AAPL.Close, NFLX
.2015
$
NFLX.Close)
Close.Prices
.2015
[
c
(
1
:
3
, nrow
(Close.Prices)), ]
##
AAPL.Close NFLX.Close
## 2015-01-02
27.332
49.849
## 2015-01-05
26.562
47.311
24
Jan
Mar
May
Jul
Sep
Nov
Jan
1.0
1.2
1.4
1.6
1.8
2.0
2.2
Value of Investment ($)
Tech
Financials
Consumer
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
## 2015-01-06
26.565
46.501
## 2015-12-31
26.315
114.380
Close.Prices
.2015
$
Tech.Close <- Close.Prices
.2015
$
AAPL.Close + Close.Prices
.2015
$
NFLX
Close.Prices
.2015
$
sma50 <- rollmeanr
(Close.Prices
.2015
$
AAPL.Close +
Close.Prices
.2015
$
NFLX.Close, k = 50
)
Close.Prices
.2015
$
sma200 <- rollmeanr
(Close.Prices
.2015
$
AAPL.Close +
Close.Prices
.2015
$
NFLX.Close, k = 200
)
Close.Prices
.2015
[
c
(
1
:
5
, nrow
(Close.Prices
.2015
))]
##
AAPL.Close NFLX.Close Tech.Close sma50 sma200
## 2015-01-02
27.332
49.849
77.181
NA
NA
## 2015-01-05
26.562
47.311
73.874
NA
NA
## 2015-01-06
26.565
46.501
73.066
NA
NA
## 2015-01-07
26.938
46.743
73.680
NA
NA
## 2015-01-08
27.973
47.780
75.752
NA
NA
## 2015-12-31
26.315
114.380
140.695 145.01 130.02
y.range <- range
(Close.Prices
.2015
, na.rm = TRUE
)
y.range
## [1] 25.78 160.69
Janua
Tech Sector−
Simple
Moving
Average
January 1, 2015 − December 31, 2015
25
Jan
Mar
May
Jul
Sep
Nov
Jan
40
60
80
120
160
Price ($)
Tech Sector Price
Day Moving Average
50−
200−Day Moving Average
par
(
mfrow = c
(
1
, 1
)) plot
(
x = index
(Close.Prices
.2015
), xlab = "Date"
, y = Close.Prices
.2015
$
Tech.Close, ylim = y.range,
ylab = "Price ($)"
, type = "l"
, main = "Tech Sector- Simple Moving Average cex.main = 0.9
)
lines
(
x = index
(Close.Prices
.2015
), y = Close.Prices
.2015
$
sma50) lines
(
x = index
(Close.Prices
.2015
), y = Close.Prices
.2015
$
sma200, lty = 2
)
legend
(
"topleft"
, c
(
"Tech Sector Price"
, "50-Day Moving Average"
,
"200-Day Moving Average"
), lty = c
(
1
, 1
, 2
))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Date
Bollinger BandsPlot
AAPL <- subset
(data.AAPL[, 4
], +
index
(data.AAPL) >= "2011-01-01"
)
NFLX <- subset
(data.NFLX[, 4
], +
index
(data.NFLX) >= "2011-01-01"
)
C <- subset
(data.C[, 4
], +
index
(data.C) >= "2011-01-01"
)
BLK <- subset
(data.BLK[, 4
], +
index
(data.BLK) >= "2011-01-01"
)
SBUX <- subset
(data.SBUX[, 4
], +
index
(data.SBUX) >= "2011-01-01"
)
NKE <- subset
(data.NKE[, 4
], +
index
(data.NKE) >= "2011-01-01"
)
Portfolio <- cbind
(AAPL
$
AAPL.Close, NFLX
$
NFLX.Close, BLK
$
BLK.Close,
C
$
C.Close, SBUX
$
SBUX.Close, NKE
$
NKE.Close)
Portfolio[
c
(
1
:
3
, nrow
(Portfolio)), ]
##
AAPL.Close NFLX.Close BLK.Close C.Close SBUX.Close NKE.Close
## 2011-01-03
11.770
25.487
190.19
49.00
16.625
21.5
22
## 2011-01-04
11.832
25.910
190.04
49.00
16.240
20.9
92
## 2011-01-05
11.929
25.676
192.00
49.70
16.175
21.1
30
## 2015-12-31
26.315
114.380
340.52
51.75
60.030
62.5
00
Portfolio
$
All <- AAPL
$
AAPL.Close + NFLX
$
NFLX.Close + BLK
$
BLK.Close +
C
$
C.Close + SBUX
$
SBUX.Close + NKE
$
NKE.Close
Portfolio[
c
(
1
:
3
, nrow
(Portfolio)), ]
##
AAPL.Close NFLX.Close BLK.Close C.Close SBUX.Close NKE.Close
All
## 2011-01-03
11.770
25.487
190.19
49.00
16.625
21.522
314.60
## 2011-01-04
11.832
25.910
190.04
49.00
16.240
20.992
314.01
## 2011-01-05
11.929
25.676
192.00
49.70
16.175
21.130
316.61
## 2015-12-31
26.315
114.380
340.52
51.75
60.030
62.500
655.49
Portfolio
$
avg <- rollmeanr
(Portfolio
$
All, k = 20
)
Portfolio
$
sd <- rollapply
(Portfolio
$
All, width = 20
, FUN = sd, fill = NA
)
Portfolio[
c
(
1
:
3
, nrow
(Portfolio)), ]
##
AAPL.Close NFLX.Close BLK.Close C.Close SBUX.Close NKE.Close
All
## 2011-01-03
11.77
0
25.487
190.19
49.00
16.625
21.522
314.60
## 2011-01-04
11.83
2
25.910
190.04
49.00
16.240
20.992
314.01
## 2011-01-05
11.92
25.676
192.00
49.70
16.175
21.130
26
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
9
316.61
## 2015-12-31
26.31
5
114.380
340.52
51.75
60.030
62.500
655.49
##
avg
sd
## 2011-01-03
NA
NA
## 2011-01-04
NA
NA
## 2011-01-05
NA
NA
## 2015-12-31 664.26 17.673
Portfolio
$
sd2up <- Portfolio
$
avg + 2 * Portfolio
$
sd Portfolio
$
sd2down <- Portfolio
$
avg - 2 * Portfolio
$
sd
Portfolio[
c
(
1
:
3
, nrow
(Portfolio)), ]
##
AAPL.Close NFLX.Close BLK.Close C.Close SBUX.Close NKE.Close
All
## 2011-01-03
11.77
0
25.487
190.19
49.00
16.625
21.522
314.60
## 2011-01-04
11.83
2
25.910
190.04
49.00
16.240
20.992
314.01
## 2011-01-05
11.92
9
25.676
192.00
49.70
16.175
21.130
316.61
## 2015-12-31
26.31
5
114.380
340.52
51.75
60.030
62.500
655.49
##
avg
sd sd2up sd2down
## 2011-01-03
NA
NA
NA
NA
January 1, 2011-
December
31,2015"
,
27
y.range <- range
(Portfolio[, -3
], na.rm = TRUE
)
plot
(
x = index
(Portfolio), xlab = "Date"
, y = Portfolio
$
All, ylim = y.range, ylab = "Price ($)"
, type = "l"
, lwd = 3
, main = "Portfolio - Bollinger Bands (20 days, 2 deviations) cex.main = 0.9
)
lines
(
x = index
(Portfolio), y = Portfolio
$
avg, lty = 2
) lines
(
x = index
(Portfolio), y = Portfolio
$
sd2up, col = "gray40"
) lines
(
x = index
(Portfolio), y = Portfolio
$
sd2down, col
= "gray40"
) legend
(
"topleft"
, c
(
"Portfolio Price"
, "20-Day Moving Average"
,
"Upper Band"
, "Lower Band"
), lty = c
(
1
, 2
, 1
, 1
), lwd = c
(
3
,
1
, 1
, 1
), col = c
(
"black"
, "black"
, "gray40"
, "gray40"
))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Portfolio − Bollinger Bands (20 days, 2 deviations) January 1, 2011− December 31,20
Date
28
2011
2012
2013
2014
2015
2016
0
200
400
600
Price ($)
Portfolio Price
20−Day Moving Average
Upper Band
Lower Band
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Documents
Recommended textbooks for you

BUSN 11 Introduction to Business Student Edition
Business
ISBN:9781337407137
Author:Kelly
Publisher:Cengage Learning

Essentials of Business Communication (MindTap Cou...
Business
ISBN:9781337386494
Author:Mary Ellen Guffey, Dana Loewy
Publisher:Cengage Learning

Accounting Information Systems (14th Edition)
Business
ISBN:9780134474021
Author:Marshall B. Romney, Paul J. Steinbart
Publisher:PEARSON


International Business: Competing in the Global M...
Business
ISBN:9781259929441
Author:Charles W. L. Hill Dr, G. Tomas M. Hult
Publisher:McGraw-Hill Education

Recommended textbooks for you
- BUSN 11 Introduction to Business Student EditionBusinessISBN:9781337407137Author:KellyPublisher:Cengage LearningEssentials of Business Communication (MindTap Cou...BusinessISBN:9781337386494Author:Mary Ellen Guffey, Dana LoewyPublisher:Cengage LearningAccounting Information Systems (14th Edition)BusinessISBN:9780134474021Author:Marshall B. Romney, Paul J. SteinbartPublisher:PEARSON
- International Business: Competing in the Global M...BusinessISBN:9781259929441Author:Charles W. L. Hill Dr, G. Tomas M. HultPublisher:McGraw-Hill Education

BUSN 11 Introduction to Business Student Edition
Business
ISBN:9781337407137
Author:Kelly
Publisher:Cengage Learning

Essentials of Business Communication (MindTap Cou...
Business
ISBN:9781337386494
Author:Mary Ellen Guffey, Dana Loewy
Publisher:Cengage Learning

Accounting Information Systems (14th Edition)
Business
ISBN:9780134474021
Author:Marshall B. Romney, Paul J. Steinbart
Publisher:PEARSON


International Business: Competing in the Global M...
Business
ISBN:9781259929441
Author:Charles W. L. Hill Dr, G. Tomas M. Hult
Publisher:McGraw-Hill Education
