2

I can display various metrics for one stock and want to know if I can do it easily for many stocks. In my example, I used Microsoft and the code works. Is there a way of setting up another list like techstocks={"MSFT","AMZN","CSCO","ORCL"} and then having the code below altered to cycle through each of the elements in techstocks to display each of the values in Stockstats?

Stockstats = {"BookValuePerShare","PriceToBookRatio","EarningsPerShare","PERatio"}
FinancialData["MSFT", #] & /@ Stockstats

1 Answers1

2

Here is one way to do it.

stockstats =
  {"BookValuePerShare", "PriceToBookRatio", "EarningsPerShare"};
techstocks = {"MSFT", "AMZN", "CSCO", "ORCL"};
FinancialData[#1, #2]& @@@ Catenate @ Outer[List, techstocks, stockstats]

{8.9, 7.25, 2.12, 40.43, 20.69, 4.9, 12.62, 2.56, 2.09, 11.81, 3.48, 2.1}

Or if you want labeling.

{#1, #2, FinancialData[#1, #2]} & @@@ Catenate @ Outer[List, techstocks, stockstats]
{{"MSFT", "BookValuePerShare", 8.9}, 
 {"MSFT", "PriceToBookRatio", 7.25}, 
 {"MSFT", "EarningsPerShare", 2.12}, 
 {"AMZN", "BookValuePerShare", 40.43}, 
 {"AMZN", "PriceToBookRatio", 20.69}, 
 {"AMZN", "EarningsPerShare", 4.9}, 
 {"CSCO", "BookValuePerShare", 12.62}, 
 {"CSCO", "PriceToBookRatio", 2.56}, 
 {"CSCO", "EarningsPerShare", 2.09}, 
 {"ORCL", "BookValuePerShare", 11.81}, 
 {"ORCL", "PriceToBookRatio", 3.48}, 
 {"ORCL", "EarningsPerShare", 2.1}}
m_goldberg
  • 107,779
  • 16
  • 103
  • 257