Code covered by the BSD License  

Highlights from
RSI calculator

4.5

4.5 | 4 ratings Rate this file 15 Downloads (last 30 days) File Size: 2.28 KB File ID: #18675

RSI calculator

by Josiah Renfree

 

08 Feb 2008 (Updated 16 Apr 2008)

Calculate the RSI for a stock over any time range for any given period

| Watch this File

File Information
Description

This program is used to calculate the Relative Strength Index (RSI) technical indicator for a user-provided vector giving stock prices. The user may also specify the number of samples to use for each period. The default period is 14 samples.

RSI = calc_RSI(data,N) calculates the RSI over the stock price values found in data using a period of N samples.

RSI = calc_RSI(data) calculates the RSI using the default period of 14 samples.

The vector 'data' must be formatted so that the value corresponding to the most recent date is at the end of the vector, while the oldest price value is found at the beginning of the vector. The vector RSI is formatted in the same way.

The vector 'RSI' will not be the same length as the vector 'data', since the first N samples of 'data' need to be used to calculate the first 'RSI' sample.

NOTE: I commonly use my other program, "Historical Stock Data Downloader," to retrieve the stock data that I pass to this RSI function for RSI calculation. If you use my other program, be aware that the stock data downloader returns data with the most recent date first, and the oldest date at the end of the array. The "calc_RSI" function must take data in the reverse order, with the most recent date at the end of the array. To flip the data, you will need to use the flipud command in Matlab. Just be aware of how the data needs to be formatted.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
24 Feb 2008 ghssan dar  
29 Mar 2008 Fernando Oliveira

Josiah Renfree, correct me if I am wrong, but in lines 90 and 91 you should use (N-1)/N instead of 13 and 14 for a period of N trading days.

12 Aug 2008 venugopal ramachandran

your product is good

14 Jul 2009 Michele

A very nice, handy piece of code. All I'd add is an error check for short arrays.

Please login to add a comment or rating.
Updates
12 Feb 2008

Updated description regarding data format

16 Apr 2008

Fernando graciously pointed out that in the old code, lines 90 and 91 were hard-coded using a trading period of 14 days. The file is now updated to change accordingly with a period of N days.

Tag Activity for this File
Tag Applied By Date/Time
finance Josiah Renfree 22 Oct 2008 09:47:03
modeling Josiah Renfree 22 Oct 2008 09:47:03
technical indicator rsi relative strength index stocks Josiah Renfree 22 Oct 2008 09:47:03
analysis Josiah Renfree 22 Oct 2008 09:47:03
finance Tobias 08 Aug 2011 10:18:42

Contact us at files@mathworks.com