Mengimpor dan Mengelola Data Keuangan di R
Joshua Ulrich
Quantitative Analyst & quantmod Co-Author and Maintainer
setSymbolLookup(AAPL = "google")
aapl <- getSymbols("AAPL", auto.assign = FALSE)
str(aapl) # perhatikan atribut 'src'
Objek ‘xts’ pada 2007-01-03/2017-02-22 berisi:
Data: num [1:2552, 1:5] 12.3 12 12.2 12.3 12.3 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:5] "AAPL.Open" "AAPL.High" "AAPL.Low" "AAPL.Close" ...
Diindeks oleh objek kelas: [Date] TZ: UTC
Atribut xts:
List of 2
$ src : chr "google"
$ updated: POSIXct[1:1], format: "2017-02-23 14:16:55"
setSymbolLookup(MSFT = list(src = "google", from = "2016-01-01"))
msft <- getSymbols("MSFT", auto.assign = FALSE)
str(msft) # perhatikan atribut 'src' dan tanggal pertama
Objek ‘xts’ pada 2016-01-04/2017-02-27 berisi:
Data: num [1:290, 1:5] 54.3 54.9 54.3 52.7 52.4 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:5] "MSFT.Open" "MSFT.High" "MSFT.Low" "MSFT.Close" ...
Diindeks oleh objek kelas: [Date] TZ: UTC
Atribut xts:
List of 2
$ src : chr "google"
$ updated: POSIXct[1:1], format: "2017-02-23 14:20:21"
# Set default
setSymbolLookup(AAPL = "google")
# Verifikasi default berubah
getSymbolLookup()
$AAPL
$AAPL$src
"google"
# Simpan lookup
saveSymbolLookup("symbol_lookup.rda")
# Hapus lookup
setSymbolLookup(AAPL = NULL)
# Verifikasi default dihapus
getSymbolLookup()
named list()
# Muat lookup
loadSymbolLookup("symbol_lookup.rda")
# Verifikasi default dipulihkan
getSymbolLookup()
$AAPL
$AAPL$src
"google"
Mengimpor dan Mengelola Data Keuangan di R