Benvenuto al corso!

Importare e gestire dati finanziari in R

Joshua Ulrich

Quantitative Analyst & quantmod Co-Author and Maintainer

Chi sono

  • Autore e/o maintainer di vari pacchetti
    • TTR, xts, quantmod, blotter, quantstrat
  • Comitato organizzatore R/Finance Conference
  • St. Louis R User Group
Importare e gestire dati finanziari in R

Cos'è getSymbols()?

  • Accesso a più fonti dati
  • Restituisce un oggetto xts per default
  • Può importare dati in due modi:
    • Restituisce dati come una funzione normale
    • Crea un oggetto come load() in base R
Importare e gestire dati finanziari in R
getSymbols(Symbols = "AAPL", src = "yahoo")
"AAPL"
getSymbols("AAPL")
"AAPL"
head(AAPL)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2007-01-03     86.29     86.58    81.90      83.80   309579900      10.85709
2007-01-04     84.05     85.95    83.82      85.66   211815100      11.09807
2007-01-05     85.77     86.20    84.40      85.05   208685400      11.01904
2007-01-08     85.96     86.53    85.28      85.47   199276700      11.07345
2007-01-09     86.45     92.98    85.15      92.57   837324600      11.99333
2007-01-10     94.75     97.80    93.45      97.00   738220000      12.56728
Importare e gestire dati finanziari in R

Fonti dati di getSymbols()

Yahoo! Finance Logo di Yahoo Finance
Google Finance Logo di Google Finance
FRED Logo FRED
Oanda Logo OANDA
CSV CSV
Importare e gestire dati finanziari in R

Altre fonti dati di getSymbols()

  • Yahoo! Finance Japan
  • MySQL
  • SQLite
  • RData
  • rds (creato con saveRDS())
Importare e gestire dati finanziari in R

Esempio di getSymbols()

# Carica dati come load()
getSymbols("AAPL", auto.assign = TRUE)
"AAPL"
head(AAPL, n = 3)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2007-01-03     86.29     86.58    81.90      83.80   309579900      10.85709
2007-01-04     84.05     85.95    83.82      85.66   211815100      11.09807
2007-01-05     85.77     86.20    84.40      85.05   208685400      11.01904
Importare e gestire dati finanziari in R

Esempio di getSymbols()

# Restituisce dati come una normale funzione
aapl <- getSymbols("AAPL", auto.assign = FALSE)
head(aapl, n = 3)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2007-01-03     86.29     86.58    81.90      83.80   309579900      10.85709
2007-01-04     84.05     85.95    83.82      85.66   211815100      11.09807
2007-01-05     85.77     86.20    84.40      85.05   208685400      11.01904
Importare e gestire dati finanziari in R

Ayo berlatih!

Importare e gestire dati finanziari in R

Preparing Video For Download...