4
$\begingroup$

I try to use EntityValue to get the returns of a stock from January 1st 2019 to today. When I use

EntityValue[Entity["Financial", StringJoin["NYSE:", "BMY"]], "Return"]

I obtain the latest return.

What syntax should I use for the third argument in EntityValue to get a time period?

$\endgroup$
3
$\begingroup$

Use EntityProperty to add a qualifier:

ts = EntityValue[
    Entity["Financial",StringJoin["NYSE:","BMY"]],
    EntityProperty["Financial","Return",{"Date"->{DateObject@{2019,1,1}, Today}}]
]

enter image description here

You can extract the data using "DatePath":

ts["DatePath"] //Short[#, 5]&

enter image description here

$\endgroup$
  • $\begingroup$ Is it possible to obtain the actual data and not an interpolation? $\endgroup$ – Neutral Element Mar 22 at 18:02
  • $\begingroup$ @NeutralElement See update. $\endgroup$ – Carl Woll Mar 22 at 18:23
2
$\begingroup$

Using Interpreter and appropriate ids from here, we can make it more general. Here is a short function.

plotCompanyFundamentalData[symbol_, startDate_, endDate_, ids_] := 
 Module[{mycompany, mycompanydata},
mycompany = EntityValue[Interpreter["Company"][symbol], "Company"];
  mycompanydata =EntityValue[mycompany,Dated[ids, 
Interval[{DateObject[startDate], DateObject[endDate]}]]];
DateListPlot[mycompanydata, PlotLabel -> symbol, PlotLegends -> ids, 
PlotTheme -> "Detailed", PlotRange -> All]]

Example:

 plotCompanyFundamentalData["AAPL", {2000, 1, 1}, {2019, 1, 1},
 {"ROA","ROE","RevenueGrowth"}]

enter image description here

$\endgroup$
1
$\begingroup$

Use FinancialData instead:

FinancialData[
  StringJoin["NYSE:", "BMY"], 
  "Return", 
  {DateObject[{2019, 1, 1}], Today}
]

{{{2019, 3, 4}, -0.00319433}, {{2019, 3, 5}, 0.0141376}, {{2019, 3, 6}, -0.0169145}, 
 {{2019, 3, 7}, -0.0283607}, {{2019, 3, 11}, -0.00953489}, {{2019, 3, 12}, -0.0102161}, 
 {{2019, 3, 13}, 0.011711}, {{2019, 3, 14}, -0.021189}, {{2019, 3, 15}, 0.00140308}, 
 {{2019, 3, 18}, -0.00200157}, {{2019, 3, 19}, -0.00521464}, {{2019, 3, 20}, -0.00826613}, 
 {{2019, 3, 21}, -0.00548893}}
$\endgroup$
  • $\begingroup$ I try to avoid FinancialData because sometimes is unavailable and is extremely slow. Your previous command did not work for me. $\endgroup$ – Neutral Element Mar 22 at 17: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.