4
$\begingroup$

After some poking around, I found how to get the price of the S&P500:

FinancialData["^SPX"]` and `FinancialData["^SPX", "Company"]

However, I am trying to illustrate the calculation of betas, so I need historical prices, but putting past dates (for example FinancialData["^SPX", DateObject[DatePlus[Today, -90]]]) gives Missing[NotAvailable]. My workaround has been to use an index fund instead, but I would strongly prefer doing this the right way. Any ideas about how to get historical data for the S&P500 with FinancialData[ ]?

By the way I did consult these answers, but

WolframAlpha["s&p500 prices from 10/23/2015 to 10/22/2016",{"DateRangeSpecified:Last:FinancialData"}]

does not produce a TimeSeries list. And, yes, I know that if I was connected to Bloomberg, then an interface exists, I am not.

$\endgroup$
2
  • 1
    $\begingroup$ Have a look at this. $\endgroup$ Oct 23, 2016 at 16:26
  • $\begingroup$ Oof, that works but doing it in four month intervals is a pain. Thanks, I upvoted your comment. $\endgroup$
    – Nicholas G
    Oct 23, 2016 at 22:15

1 Answer 1

4
$\begingroup$

Try using Entity to feed FinancialData:

ts = TimeSeries[FinancialData[EntityClass["Financial", "SP500"], {{2016, 1, 1}, Today}]]

DateListPlot[ts]

Mathematica graphics

$\endgroup$
4
  • 1
    $\begingroup$ Using "SP500" instead of EntityClass["Financial", "SP500"] returns the same data. $\endgroup$
    – Karsten7
    Oct 24, 2016 at 5:50
  • 1
    $\begingroup$ The symbol "^GSPC" also returns the same data. $\endgroup$
    – Karsten7
    Oct 24, 2016 at 5:57
  • $\begingroup$ Thanks all. Wrapping in TimeSeries[ ] would not produce a list that I could then use to calculate and graph relations with stocks. But it turns out that FinancialData["SP500", {{2014, 10, 23}, {2016, 10, 22}}] worked just fine. How could I have found the correct symbol string? I searched for all symbols containing SP with FinancialData["*SP*", "Lookup"] but it did not produce SP500. $\endgroup$
    – Nicholas G
    Oct 24, 2016 at 13:08
  • $\begingroup$ @Karsten7. This is my feeble attempt to use the Entity framework which is still almost indecipherable to me. :) $\endgroup$
    – kale
    Oct 24, 2016 at 13:48

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.