1
$\begingroup$

I was wondering if it were possible to use the FinancialData function to return a list of stocks based on a price filter, ie. return all NYSE stocks, that had a closing price between \$10-\$12?

Thank you.

$\endgroup$
4
$\begingroup$
stocks=FinancialData["NYSE:UN*", "Lookup"];
prices=FinancialData[#,"Close"]&/@stocks;
data=Map[<|"symbol"->#1,"price"->#2|>&@@#&,Thread[List[stocks,prices]]];


data//Dataset

f=Function[{data,lower,upper},
Cases[data,KeyValuePattern["price"->x_/;lower<=QuantityMagnitude@x<=upper]]//Dataset];
f[data,5,10]

enter image description here

By the way

Mathematica graphics
Is it possible without an API limitation?

$\endgroup$
  • 1
    $\begingroup$ +1 Note, that FinancialData[ "name" ] does not necessarily give the closing price. $\endgroup$ – gwr Jul 11 '19 at 10:52
  • $\begingroup$ Thanks! I've fixed the post just now :) $\endgroup$ – Xminer Jul 11 '19 at 11:01
3
$\begingroup$

A variation to Xminer's answer:

With[
    {
        names = FinancialData["NYSE:UN*", "Lookup"], (* use "NYSE:*" for more *)
        lower = 10,
        upper = 100 (* use 12 for your example *)
    }
    ,
    FinancialData[ #, {"Name", "Close"} ]& /@ names // RightComposition[
        Map[ AssociationThread[ {"Name", "Price"} -> ## ] & ],
        Query[ Select[ lower <= QuantityMagnitude[#Price] <= upper & ], "Name" ]
    ]
]

{Unilever, Unum, Univar Inc}

$\endgroup$

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.