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?
2 Answers
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}}]
The first 10 rows of fractionalChange
:
Take[Normal @ fractionalChange, 10] // Column
DateListPlot[fractionalChange]
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
First 10 rows:
Take[Normal @ rateOfChange, 10] // Column
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
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]
-
$\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$– JaneDoeCommented Nov 8, 2021 at 1:40 -
2$\begingroup$ A space is an implied multiplication. $\endgroup$ Commented Nov 8, 2021 at 1:43
ts = FinancialData["SP500", {{2014, 10, 23}, {2016, 10, 22}}]; Normal @ts
or usets["DatePath"]
(See TimeSeries >> Details and Options for the properties you can extract.) $\endgroup$percentchange
instead ofpercent_change
. (Blank (_) has a very special meaning/role in Mathematica.) $\endgroup$