-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtidyquant_Tutorial.Rmd
87 lines (67 loc) · 1.22 KB
/
tidyquant_Tutorial.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
title: "tidyquant Tutorial Workthrough"
subtitle: Work through the tidyquant Tutorial
output:
html_document:
df_print: paged
---
This is a work through of the tutorial at
source: https://quantdev.ssri.psu.edu/sites/qdev/files/tidyquant_tutorial_Gray.html .
# Install needed Libraries
```{r}
library(tidyquant)
library(ggplot2)
```
Download data using tq_get
```{r}
google <- tq_get(x = "GOOG")
head(google)
```
```{r}
syse <- tq_exchange("NYSE")
```
```{r}
head(syse)
```
```{r}
nyse <- syse
```
```{r}
nyse$symbol
```
```{r}
nyse$symbol[1]
```
```{r}
full <- tq_get(x = nyse$symbol[1], get = "stock.prices") %>%
add_column(symbol = nyse$symbol[1])
```
```{r}
for (s in nyse$symbol[2:20]){
single <- try(tq_get(x = s, get = "stock.prices") %>%
add_column(symbol = s))
full <- try(rbind(full, single))
}
```
```{r}
head(full)
```
```{r}
str(full)
```
```{r}
unique(full$symbol)
```
```{r}
ggplot(data = full) +
aes(x = date, y = adjusted, color = symbol) +
geom_line(aes(group = symbol)) +
theme_classic() +
theme(legend.position = "none") +
ylab("Adjusted Price") +
ggtitle("10 Years of NYSE Stock Prices")
```
```{r}
getwd()
write.csv(full, file = "nyse_stock_prices.csv")
```