-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantmod_usage.R
More file actions
59 lines (39 loc) · 1.3 KB
/
quantmod_usage.R
File metadata and controls
59 lines (39 loc) · 1.3 KB
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
library(quantmod)
getSymbols("YNDX")
tail(YNDX)
# Import QQQ data from Alpha Vantage
getSymbols("QQQ", src="av")
# Look at the structure of QQQ
str(QQQ)
# Import GDP data from FRED
getSymbols("GDP", src="FRED")
# Look at the structure of GDP
str(GDP)
# Assign SPY data to 'spy' using auto.assign argument
spy <- getSymbols('SPY', auto.assign=F)
# Look at the structure of the 'spy' object
str(spy)
# Assign JNJ data to 'jnj' using env argument
jnj <- getSymbols("JNJ", env=NULL)
# Look at the structure of the 'jnj' object
str(jnj)
# Currency #### only for last 180 days :\
# Create a currency_pair object
currency_pair <- "GBP/CAD"
# Load British Pound to Canadian Dollar exchange rate data
getSymbols(currency_pair, src='oanda')
# Examine object using str()
str(GBPCAD)
# Try to load data from 190 days ago
getSymbols(currency_pair, from = Sys.Date() - 190, to = Sys.Date(), src = "oanda")
# OHLC ####
help("OHLC.Transformations")
# CME ####
# Download CME data for CL and BZ as an xts object
oil_data <- Quandl(code = c("CME/CLH2016", "CME/BZH2016"), type = "xts")
# Look at the column names of the oil_data object
colnames(oil_data)
# Extract the Open price for CLH2016
cl_open <- getPrice(oil_data, symbol = "CLH2016", prefer = "Open$")
# Look at January, 2016 using xts' ISO-8601 subsetting
cl_open["2016-01"]