Message Boards Message Boards

0
|
5381 Views
|
9 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Confusion about suitable Entity types for certain functions

Posted 2 years ago

It is very confusing and a tremendous waste of time trying to figure out which type of entity is needed for a function to work -- is there any resources in Financial Data / Company Data that explains what works and what does not??? I would post the code but it blowups, lines 1, 3, work giving the price of the stock, line 2 does not work. line 4 and 6 do not work, but line 4 does giving the company name and a tag

enter image description here

"fb" and "facebook" work for FinancialData, but "fb" does not work for CompanyData, but "facebook" does work in CompanyData

below is from an article in The Mathematica Journal enter image description here

In[82]:= Interpreter["Company"]["FB"]
Interpreter["Company"]["facebook"]

Out[82]= Failure["InterpretationFailure", 
Association[
 "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
  "MessageParameters" -> Association[
   "Type" -> "company", "Input" -> "FB"], "Type" -> "Company", 
  "Input" -> "FB"]]

Out[83]= Entity["Company", "Facebook::79qbc"]

"FB" does not work, "FaceBook" works in Interpreter

In[62]:= CompanyData[
 EntityValue[Interpreter["Company"]["FaceBook"], "Company"], "Dataset"]

During evaluation of In[62]:= CompanyData::notent: Missing[UnknownProperty,{Company,Company}] is not a known entity, class, or tag for CompanyData. Use CompanyData[] for a list of entities.

Out[62]= CompanyData[
 Missing["UnknownProperty", {"Company", "Company"}], "Dataset"]

But there is something else wrong with the code - I do not know what it is -- just tried following the article

trying to create a list of stocks is a problem as one non-entity cashes the whole program

any good resources for FinancialDate / CompanyDate -- thanks

POSTED BY: Raymond Low
9 Replies
Posted 2 years ago

Again Thanks Rohit -- I am two thirds of the way there, for some reason EntityClass would not take nine of the company names provided by FinancialData, By chance is there another way???

d = FinancialData["^DJI", "Members"] 

dd = FinancialData[#, "Name"] & /@ d

In[99]:= ddd = 
 EntityValue[EntityList[EntityClass["Company", {"Name" -> #}]], 
    "CanonicalName"] & /@ dd

Out[99]= {{"3MCompany::k67x2"}, {"AmericanExpressCompany::9d6vt"}, \
{"Amgen::6yq5w"}, {"Apple::5zkjq"}, {"Boeing::374s8"}, \
{"Caterpillar::48f69"}, {"ChevronCorporation::tj685"}, {}, \
{"CocaCola::78tc4"}, {}, {"DowHoldings::7wkrd"}, {}, \
{"HomeDepot::cb9gp"}, {}, \
{"InternationalBusinessMachinesCorporation::vq88c"}, \
{"IntelCorporation::vj6f2"}, {"Johnson&Johnson::7z9hd"}, \
{"JPMorganChase&Company::258fx"}, {"McDonaldsCorporation::92mv4"}, \
{}, {"MicrosoftCorporation::j3gxm"}, {"Nike::4b7r6"}, \
{"Procter&GambleCompany::sy7qs"}, {"SalesforceDotCom::zbp4j"}, {}, \
{}, {"VerizonCommunications::g84hj"}, {"Visa::r2fcs"}, {}, {}}
POSTED BY: Raymond Low
Posted 2 years ago

Hi Rohit,
Thanks so much for your help, I tried again with better success, but it is real madness trying to guess what name Mathematica wants for their name. I had to go to StockCharts to get various names and even then had to play around with the names to see what worked. Dow Holding did not work, but Dow did, Verizon did not work, but Verizon Communications did. I never figured out what name they wanted for 3M Company -- tried several variations but never found the secret.

In[89]:= EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "Apple"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "IBM"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass[
   "Company", {"Name" -> "Eastman Kodak"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "3M Co"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass[
   "Company", {"Name" -> "Verizon Communications"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "Microsoft"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "Dow"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "Facebook"}]], "CanonicalName"]

Out[89]= {"Apple::5zkjq"}

Out[90]= {"InternationalBusinessMachinesCorporation::vq88c"}

Out[91]= {"EastmanKodakCompany::g2j5c"}

Out[92]= {}

Out[93]= {"VerizonCommunications::g84hj"}

Out[94]= {"MicrosoftCorporation::j3gxm"}

Out[95]= {"DowHoldings::7wkrd"}

Out[96]= {"Facebook::79qbc"} 

I would like to work with the companies in the DJIA and got the symbols from FinanceData, but that will not work in CompanyData

dd = FinancialData["^DJI", "Members"]

{"NYSE:MMM", "NYSE:AXP", "NASDAQ:AMGN", "NASDAQ:AAPL", "NYSE:BA", \
"NYSE:CAT", "NYSE:CVX", "NASDAQ:CSCO", "NYSE:KO", "NYSE:DIS", \
"NYSE:DOW", "NYSE:GS", "NYSE:HD", "NASDAQ:HON", "NYSE:IBM", \
"NASDAQ:INTC", "NYSE:JNJ", "NYSE:JPM", "NYSE:MCD", "NYSE:MRK", \
"NASDAQ:MSFT", "NYSE:NKE", "NYSE:PG", "NYSE:CRM", "NYSE:TRV", \
"NYSE:UNH", "NYSE:VZ", "NYSE:V", "NASDAQ:WBA", "NYSE:WMT"}

any suggestions in how to download the names for these 30 stocks that is compatible with CompanyData????

POSTED BY: Raymond Low
Posted 2 years ago

3M is just 3M

EntityValue[
 EntityList[EntityClass["Company", {"Name" -> "3M"}]], "CanonicalName"]

Agree that the naming is not obvious sometimes, but at least it is internally consistent in WL.

To get names usable by CompanyData or EntityClass["Company", ...]

FinancialData[#, "Name"] & /@ dd
(* {"3M", "American Express", "Amgen", "Apple", "Boeing", "Caterpillar", 
"Chevron", "Cisco", "Coca-Cola", "Disney", "Dow", "Goldman Sachs", 
"Home Depot", "Honeywell International Inc", "IBM", "Intel", "Johnson 
& Johnson", "JPMorgan Chase", "McDonald's", "Merck & Co.", 
"Microsoft", "Nike", "Procter & Gamble", "Salesforce.com", \
"Travelers", "UnitedHealth", "Verizon Communications", "Visa", 
"Walgreens Boots Alliance Inc", "Wal-Mart Stores"} *)
POSTED BY: Rohit Namjoshi
Posted 2 years ago

Hi Rohit, I tried your code sometimes it worked and sometimes it did not

In[719]:= EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "aapl"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "ibm"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "kodk"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "3M Company"}]], "CanonicalName"]
EntityValue[
 EntityList[EntityClass["Company", {"Name" -> "vz"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "microsoft"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "dow"}]], "CanonicalName"]
EntityValue[
 EntityList[
  EntityClass["Company", {"Name" -> "Facebook"}]], "CanonicalName"]

Out[719]= {}

Out[720]= {}

Out[721]= {}

Out[722]= {}

Out[723]= {}

Out[724]= {}

Out[725]= {}

Out[726]= {"Facebook::79qbc"} 

I changed the names as many ways as I could remember, but with no better results, so I just don't know what to do????

POSTED BY: Raymond Low
Posted 2 years ago

Hi Raymond,

In an earlier response, I said "WL is case sensitive, facebook is not the same as Facebook. Try that e.g.

EntityValue[
 EntityList[EntityClass["Company", {"Name" -> "Microsoft"}]], "CanonicalName"]
(* {"MicrosoftCorporation::j3gxm"} *)
POSTED BY: Rohit Namjoshi
Posted 2 years ago

One more thing: looks like you are using a companies stock symbol for its name. That will not work, FinancialData takes symbol name.

EntityValue[
 EntityList[EntityClass["Company", {"Name" -> "Apple"}]], "CanonicalName"]
(* {"Apple::5zkjq"} *)

symbols = EntityValue[EntityList[EntityClass["Company", {"Name" -> "Apple"}]], 
  "CommonShares"] // CanonicalName // First
(* {"NASDAQ:AAPL", "DE:APC", "F:APC"} *)

FinancialData[#, "OHLCV"] & /@ symbols

FinancialData[#, "Exchange"] & /@ symbols
POSTED BY: Rohit Namjoshi
Posted 2 years ago

HI Sean, I am using Wolfram code used in their documentation, but sometimes it works (ibm, vz, dow) and sometimes it does not work (aapl, kodk, mmm, msft)

In[608]:= Interpreter["Company"]["aapl"]
Interpreter["Company"]["ibm"]
Interpreter["Company"]["kodk"]
Interpreter["Company"]["mmm"]
Interpreter["Company"]["vz"]
Interpreter["Company"]["msft"]
Interpreter["Company"]["dow"]

Out[608]= Failure["InterpretationFailure", 
Association[
 "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
  "MessageParameters" -> Association[
   "Type" -> "company", "Input" -> "aapl"], "Type" -> "Company", 
  "Input" -> "aapl"]]

Out[609]= Entity["Company", \
"InternationalBusinessMachinesCorporation::vq88c"]

Out[610]= Failure["InterpretationFailure", 
Association[
 "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
  "MessageParameters" -> Association[
   "Type" -> "company", "Input" -> "kodk"], "Type" -> "Company", 
  "Input" -> "kodk"]]

Out[611]= Failure["InterpretationFailure", 
Association[
 "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
  "MessageParameters" -> Association[
   "Type" -> "company", "Input" -> "mmm"], "Type" -> "Company", 
  "Input" -> "mmm"]]

Out[612]= Entity["Company", "VZHolding::286x4"]

Out[613]= Failure["InterpretationFailure", 
Association[
 "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
  "MessageParameters" -> Association[
   "Type" -> "company", "Input" -> "msft"], "Type" -> "Company", 
  "Input" -> "msft"]]

Out[614]= Entity["Company", "DowHoldings::7wkrd"]

I tried your code and sometimes it works (ibm, dow, facebook) and sometimes it does not work (aapl, kodk, mmm, msft and now vz does not work)

In[633]:= CompanyData[Interpreter["Company"]["aapl"], "CommonShares"]
CompanyData[Interpreter["Company"]["ibm"], "CommonShares"]
CompanyData[Interpreter["Company"]["kodk"], "CommonShares"]
CompanyData[Interpreter["Company"]["mmm"], "CommonShares"]
CompanyData[Interpreter["Company"]["vz"], "CommonShares"]
CompanyData[Interpreter["Company"]["dow"], "CommonShares"]
CompanyData[Interpreter["Company"]["FaceBook"], "CommonShares"]


During evaluation of In[633]:= CompanyData::notent: Failure[\[WarningSign]  Message:     No company interpretation found. Try again.
Tag:    InterpretationFailure

] is not a known entity, class, or tag for CompanyData. Use CompanyData[] for a list of entities.

Out[633]= CompanyData[Failure["InterpretationFailure", 
Association[
  "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
   "MessageParameters" -> Association[
    "Type" -> "company", "Input" -> "aapl"], "Type" -> "Company", 
   "Input" -> "aapl"]], "CommonShares"]

Out[634]= {Entity["Financial", "NYSE:IBM"], 
 Entity["Financial", "DE:IBM"], Entity["Financial", "F:IBM"], 
 Entity["Financial", "L:IBM"]}

During evaluation of In[633]:= CompanyData::notent: Failure[\[WarningSign]  Message:     No company interpretation found. Try again.
Tag:    InterpretationFailure

] is not a known entity, class, or tag for CompanyData. Use CompanyData[] for a list of entities.

Out[635]= CompanyData[Failure["InterpretationFailure", 
Association[
  "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
   "MessageParameters" -> Association[
    "Type" -> "company", "Input" -> "kodk"], "Type" -> "Company", 
   "Input" -> "kodk"]], "CommonShares"]

During evaluation of In[633]:= CompanyData::notent: Failure[\[WarningSign]  Message:     No company interpretation found. Try again.
Tag:    InterpretationFailure

] is not a known entity, class, or tag for CompanyData. Use CompanyData[] for a list of entities.

Out[636]= CompanyData[Failure["InterpretationFailure", 
Association[
  "MessageTemplate" :> MessageName[Interpreter, "semantictype"], 
   "MessageParameters" -> Association[
    "Type" -> "company", "Input" -> "mmm"], "Type" -> "Company", 
   "Input" -> "mmm"]], "CommonShares"]

Out[637]= {}

Out[638]= {Entity["Financial", "NYSE:DOW"], 
 Entity["Financial", "F:2OY"], Entity["Financial", "DE:2OY"]}

Out[639]= {Entity["Financial", "NASDAQ:FB"], 
 Entity["Financial", "DE:FB2A"], Entity["Financial", "F:FB2A"]}  

the capricious nature of the code is tiresome, FaceBook works, but FB does not -- what is the secret in getting this code to work???? VZ works in Interpreter but not when wrapped with CompanyData???

POSTED BY: Updating Name
Posted 2 years ago

Hi Raymond,

FinancialData requires the stock symbol name, not the company name. The stock for a company may be traded on different exchanges. WL is case sensitive, facebook is not the same as Facebook.

One way to get the stock symbol names for a company

EntityValue[EntityList[EntityClass["Company", {"Name" -> "Facebook"}]], "CommonShares"] //
  CanonicalName
(* {{"NASDAQ:FB", "DE:FB2A", "F:FB2A"}} *)

FinancialData["DE:FB2A"]
(* Quantity[310.3500061035156, "Euros"] *)

FinancialData["F:FB2A", "Exchange"]
(* "FrankfurtStockExchange" *)

To get names that can be used with CompanyData

EntityValue[EntityList[EntityClass["Company", {"Name" -> "Facebook"}]], "CanonicalName"]
(* {"Facebook::79qbc"} *)

CompanyData["Facebook::79qbc", "Dataset"]

Some more examples

EntityValue[
  EntityList[EntityClass["Company", {"Name" -> "Alphabet"}]], 
  "CommonShares"] // CanonicalName
(* {{"NASDAQ:GOOGL", "NASDAQ:GOOG", "DE:ABEA", "DE:ABEC", "F:ABEA", "F:ABEC"}} *)

FinancialData["NASDAQ:GOOGL", "OHLCV", {2021, 8, 1}] // TradingChart

enter image description here

POSTED BY: Rohit Namjoshi

These are related entities, but they aren't exactly interchangeable. A company can have multiple associated Financial entities. So for FinancialData, you will want to give it Financial entities. For CompanyData, you want to give it a Company entity.

It's best to just try following the documentation examples, which should largely work as they're written without adjustment.

https://reference.wolfram.com/language/ref/CompanyData.html https://reference.wolfram.com/language/ref/FinancialData.html

You also noted this isn't working:

Interpreter["Company"]["FB"]

It is probably no longer considered unambiguous enough. Less ambiguous input like "Facebook" should work.

In your other example... "Company" isn't a property. So this doesn't work:

EntityValue[Interpreter["Company"]["FaceBook"], "Company"]

You're effectively asking for a Company entity that corresponds to "FaceBook" and then asking that Company entity be turned into a Company entity... which you don't need to do. It's already a company entity. You can give a Company Entity directly to CompanyData:

CompanyData[Interpreter["Company"]["FaceBook"], "Dataset"]
POSTED BY: Sean Clarke
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