0
$\begingroup$

Sorry, very silly newbie question.. regarding FinancialData, how to return multiple specified properties.

eg. if I want Open & Close properties , or perform an operation such as Open-Close

FinancialData["SP500","Open",{2015}]
FinancialData["SP500","Close",{2015}]

return daily Opening and Closing property values but as separate lists.

$\endgroup$
4
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Commented Mar 23, 2015 at 1:42
  • $\begingroup$ Tried using 'Union' but it seems a bit long winded to combine the lists.. is that the best? Need output with 3 columns, - date, open, close. $\endgroup$ Commented Mar 23, 2015 at 3:04
  • $\begingroup$ Thanks a lot! Can I use the MapIndexed & Join to add the Open-Close column too? Wish it was not so cryptic. I expected an SQL like language. $\endgroup$ Commented Mar 23, 2015 at 8:48
  • $\begingroup$ Easier to use Table[{o[[i, 1]], o[[i, 2]], c[[i, 2]], o[[i, 2]] - c[[i, 2]]}, {i, Length[o]}] to add the Open-Close column. $\endgroup$
    – bbgodfrey
    Commented Mar 23, 2015 at 12:08

1 Answer 1

2
$\begingroup$

Defining, for convenience,

o = FinancialData["SP500", "Open", {2015}]
c = FinancialData["SP500", "Close", {2015}]

the two can be combined into 3 columns, - date, open, close" with

MapIndexed[Join[#, c[[#2, 2]]] &, o]
(* {{{2015, 1, 2}, 2058.9, 2058.2}, {{2015, 1, 5}, 2054.44, 2020.58}, {{2015, 1, 6}, 2022.15, 2002.61}, ...} *)

Other methods include

Cases[MapThread[Join, {o, c}], {l1_, l2_, l3_, l4_} -> {l1, l2, l4}, Infinity]

Table[{o[[i, 1]], o[[i, 2]], c[[i, 2]]}, {i, Length[o]}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.