1
$\begingroup$

How can i get a list of all the entries in FinancialData["SP500", {{2014, 10, 23}, {2016, 10, 22}}] ? I would like to read the actual entries but examples i am seeing has been plotting the data. How can print out the TimeSeries data for the object. Is there a command which will print the properties of an object also?

$\endgroup$
2
  • 3
    $\begingroup$ try ts = FinancialData["SP500", {{2014, 10, 23}, {2016, 10, 22}}]; Normal @ts or use ts["DatePath"] (See TimeSeries >> Details and Options for the properties you can extract.) $\endgroup$
    – kglr
    Commented Nov 8, 2021 at 0:20
  • 1
    $\begingroup$ use percentchange instead of percent_change. (Blank (_) has a very special meaning/role in Mathematica.) $\endgroup$
    – kglr
    Commented Nov 8, 2021 at 1:40

2 Answers 2

5
$\begingroup$

You can also use the property "FractionalChange" as the second argument to FinancialData to get a time series of percent changes:

fractionalChange = FinancialData["SP500", 
  "FractionalChange", 
  {{2014, 10, 23}, {2016, 10, 22}}]

enter image description here

The first 10 rows of fractionalChange:

Take[Normal @ fractionalChange, 10] // Column

enter image description here

DateListPlot[fractionalChange]

enter image description here

Yet another way is to use built-in FinancialIndicator "RateOfChange" to get a time series object of percent changes:

ts = FinancialData["SP500", {{2014, 10, 23}, {2016, 10,   22}}];

rateOfChange = FinancialIndicator["RateOfChange", 2] @ ts 

enter image description here

First 10 rows:

Take[Normal @ rateOfChange, 10] // Column

enter image description here

The two series rateOfChange and fractionalChange have the same path of {time, value} pairs if we take the QuantityMagnitude of values in fractionalChange:

rateOfChange["Path"] == 
  TimeSeriesMap[QuantityMagnitude, fractionalChange]["Path"]
True
$\endgroup$
3
$\begingroup$
Clear["Global`*"]

$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)

ts = FinancialData["SP500", {{2014, 10, 23}, {2016, 10, 22}}];

data = Normal[ts][[All, 2]];

Note that variable names cannot contain a Blank (_)

percentChange = 100 Differences[#]/Most[#] & @data;

DateListPlot[
 Transpose[{Rest[Normal[ts][[All, 1]]], percentChange}],
 ImageSize -> Large]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks for your detailed answer. I have 1 question, in percentChange there is a space between 100 and Differences. Why is there no * (multiplication sign there). Just trying to understand the syntax which is used in Mathematica $\endgroup$
    – JaneDoe
    Commented Nov 8, 2021 at 1:40
  • 2
    $\begingroup$ A space is an implied multiplication. $\endgroup$
    – Bob Hanlon
    Commented Nov 8, 2021 at 1:43

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.