Getting financial data

Financial Trading in R

Ilya Kipnis

Professional Quantitative Analyst and R programmer

Obtaining data from Yahoo!

  • Every trading system relies on data (often costly)
  • Yahoo! Finance has free data
  • Use the getSymbols() command in quantmod
Financial Trading in R

2 ETFs in this course

  • LQD:
getSymbols("LQD", from = "1990-01-01", src = "yahoo", adjusted = TRUE)
           LQD.Open LQD.High LQD.Low LQD.Close LQD.Volume LQD.Adjusted
2002-07-30   101.30   102.00  101.25    101.37      21200     43.28410
2002-07-31   101.80   102.25  101.55    101.99     272000     43.54886
2002-08-01   102.40   103.10  102.30    102.99     111700     43.97582
2002-08-02   102.90   103.30  102.45    103.20      29200     44.06552
2002-08-05   103.65   103.65  102.51    102.95     166500     43.95879
2002-08-06   102.50   102.65  102.10    102.60     430100     43.80931
  • Spy: see exercises
Financial Trading in R

quantmod functions

  • Op(): Opening day prices
  • Hi(): Maximum value traded during the day
  • Lo(): Minimum value traded during the day
  • Cl(): Last price that was traded
  • Vo(): Number of trades that day
  • Ad(): Adjusted closing price, adjust for dividends & splits
Financial Trading in R

Plotting financial data

Plot data using the plot() command

plot(Cl(LQD))

Financial Trading in R

Let's practice!

Financial Trading in R

Preparing Video For Download...