1
$\begingroup$

If I correctly understand, here I have all the existing companies listed in every market and identified by each real name:

assets = FinancialData["Stocks"];
names = FinancialData[assets, "Name"];

How could I order the element of names vector within an other vector where elements are ordered by "MarketCap" property of FinancialData?

$\endgroup$
1
$\begingroup$
names = FinancialData[{"GE", "GOOGL", "MSFT", "AAPL", "HPQ"}, "Name"];
mcaps = FinancialData[{"GE", "GOOGL", "MSFT", "AAPL", "HPQ"}, "MarketCap"];

sortednames = names[[Ordering[mcaps]]]
{"HP Inc", "General Electric Co", "Alphabet Inc", "Apple Inc", "Microsoft Corp"}

Alternatively, you can construct a list of name and market cap pairs and sort by the second column:

sortednamesmcaps = SortBy[Last] @
 FinancialData[{"GE", "GOOGL", "MSFT", "AAPL", "HPQ"}, {"Name",  "MarketCap"}] 

Grid @ sortednamesmcaps 

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you kglr, the second solution was exactly what I was looking for! Any ideas why it doesn't work with this? sortednamesmcaps = SortBy[Last] @ FinancialData["Stocks", {"Name", "MarketCap"}][[;;100]]; Grid @ sortednamesmcaps Doesn't any company has MarketCap property? My final goal would be from all stocks select those whose MarketCap value is Greater than a fixed value.. $\endgroup$ – Nate Apr 25 at 16:12

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.