1
$\begingroup$

I would like to extract the RSI data of a certain stock, let just say the SPX index. How to do that? Or, alternatively, how to calculate the RSI from FinancialData?

FinancialData["^SPX", "OHLCV", {DateList[{2016, 12}], Today}]

$\endgroup$
2
  • $\begingroup$ Have you seen RelativeStrengthIndex and FinancialIndicator ? It appears they're only for the trading charts though. You'll probably need to use MovingMap to compute it yourself from the prices given by FinancialData $\endgroup$
    – flinty
    Apr 6 '21 at 9:42
  • $\begingroup$ indeed, I can visualize RelativeStrengthIndex in a chart. But I would like to work on the data too. $\endgroup$
    – Luigi
    Apr 6 '21 at 10:22
1
$\begingroup$

You can use FinancialIndicator["RelativeStrengthIndex", n] @ data to get a time series of "the ratio of n-period exponential moving averages for gains and losses rescaled to be between 0 and 100" or FinancialIndicator["RelativeStrengthIndex"] to get the same with default n = 14:

data = FinancialData["^SPX", "OHLCV", {DateList[{2016, 12}], Today}]

rsi = FinancialIndicator["RelativeStrengthIndex"]@ data;

rsi["Path"] // Short[#, 5] &

enter image description here

DateListPlot[rsi]

enter image description here

Alternatively, you use FinancialIndicator["RelativeStrengthIndex"] with the "Close" series as input:

closes = data[[All, 2, 4]];

rsib = FinancialIndicator["RelativeStrengthIndex"] @ closes;

ListLinePlot[rsib]

enter image description here

Using n = 60:

rsi60 = FinancialIndicator["RelativeStrengthIndex", 60]@ data;

DateListPlot[rsi60]

enter image description here

$\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.