Message Boards Message Boards

0
|
5118 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to search for certain exchange traded funds?

Posted 3 years ago

My data

In[1236]:= data = FinancialData[ "ExchangeTradedFunds", "Members"]; 

In[1248]:= 
dataETF = Pick[data, StringMatchQ[data, {"NYSE:*", "NASDAQ:*"}]] ;
dataETF // Length

Out[1249]= 2497

The output gives just the ticker symbols, which is not very informative as to what the ETF represents. So "associated" the symbol with the name, which provides much more informative.

dataETFn = 
 Column[AssociationThread[dataETF, FinancialData[dataETF, "Name"]]]

But to read through 2500 entries to find the one you want is painful so tried to use StringMatchQ[] without success. Had to create another list of just the names ...

eftNames = FinancialData[dataETF, "Name"];

But StringMatchQ[] still would not work, but StringContainQ[] did work

In[1329]:= eftLumber = 
 Pick[eftNames, StringContainsQ[eftNames, {"Timber", "Forestry"}]] 
eftLumber // Length

Out[1329]= {"iShares Global Timber & Forestry ETF", "Invesco MSCI \
Global Timber ETF"}

Out[1330]= 2

But now I do not know the ticker / symbol ?? Is there a better way??

POSTED BY: Raymond Low
4 Replies
Posted 3 years ago
dataETFn = AssociationMap[FinancialData[#, "Name"] &, dataETF];
dataETFn // Select[StringContainsQ[#, {"Timber", "Forestry"}] &]
POSTED BY: Rohit Namjoshi
Posted 3 years ago

Beautiful, absolutely beautiful, Thank you very much Rohit.

But it just hurts my brain, the output of AssociationThread[] and AssociationMap[] look absolutely the same, yet StringContainsQ works with AssociationMap[] but not AssociationThread[] , just hurts my brain.

dataETFn // Select[StringContainsQ[#, {"UltraShort", "Short"}] &] worked very well in sorting out all the contra ETFs, but if I search for Ultra ETFs I get UltraShort as well. Is there a way to exclude strings -- that is, search for Ultra but not UltraShort???

POSTED BY: Raymond Low
Posted 3 years ago

Hey Raymond,

Wrapping the output of AssociationThread with Column is causing the problem. It is no longer an Association. Any StringExpression can be used as the pattern to filter on. e.g.

assoc = <|"a" -> "something Ultra something", "b" -> "something Ultrashort something"|>

assoc // Select[StringContainsQ[#, {Whitespace ~~ "ultra" ~~ Whitespace}, IgnoreCase -> True] &]
(* <|"a" -> "something Ultra something"|> *)
POSTED BY: Rohit Namjoshi
Posted 3 years ago

Raymond,

I just realized that my answer will not match "Ultra" at the beginning or end of the string. To fix that

assoc = <|"a" -> "Ultra something", "b" -> "something Ultra",  "c" -> "Ultrashort something"|>

assoc // 
 Select[StringContainsQ[#, {WordBoundary ~~ "ultra" ~~ WordBoundary}, IgnoreCase -> True] &]
(* <|"a" -> "Ultra something", "b" -> "something Ultra"|> *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract