I've been practicing R for about several months, and have begun transitioning from text book examples to what actually interests me. I'm currently participating in the CFA program, but my programming skills are lackluster. Not asking for code, but a push in the right direction!

I was able to pull the stock data for DJIA, but am having trouble getting a handle on the data. Questions:

  • What is the easy way to get a hand on the data?
  • How can I quickly write a function to pull daily returns from each 30 XTS Objects -> apply? lapply? Create a new function?
  • Should I be focusing on trying to aggregate all price points into one data frame?

Anything else or other resources you might share would be highly beneficial.

  • $\begingroup$ When you say "data" do you mean price data? If so look around for published examples of R code such as r-bloggers.com/r-code-yahoo-finance-data-loading $\endgroup$ – Alex C Oct 1 '16 at 0:08
  • $\begingroup$ Great - Thank you Alex! I have started looking at tutorials on dplyr - I think this might be what I'm looking for. Ideally, I was looking to merge the adjusted price data (multiple stocks) into 1 table, and then transform them into price returns as to calculate covariance, variance, etc etc. $\endgroup$ – Munckinn Oct 2 '16 at 21:13

It is simple once you get the hang of it. I suggest you research the apply() family of functions. If you want to pull data from yahoo simply use the following example:

# use lapply- notice each ticker is separated by ';'
A <-  lapply("AAPL;AMZN;GOOGL", getSymbols)

# just add the tickers within the quotation marks separated by semi colons. Also, if the ticket you entered is incorrect or does not exist, it will break so make sure your tickers are correct. 

# I wrote this on my phone, but i believe that the function will get you OHLCV for each ticker and return them into A
  • $\begingroup$ What I was considering was how to move from XYX.Adjusted to -> ABC through XYZ.Adjusted Returns. Would you use lapply(symbols, DailyReturns)? $\endgroup$ – Munckinn Oct 2 '16 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.