写论文第九天:MATLAB之rsindex函数

function rsi = rsindex(closep, nperiods)
%输入价格向量、期限(默认为14日),输出rsi值
%RSINDEX Relative Strength Index (RSI).
%   RSINDEX calculates the Relative Strength Index (RSI). The RSI is calculated
%   based on a default 14-period period.
%
%   RSI = rsindex(CLOSEP)
%   RSI = rsindex(CLOSEP, NPERIODS)
%
%   Optional Inputs: NPERIODS
%
%   Inputs:
%     CLOSEP - Nx1 vector of closing prices.
%
%   Optional Inputs:
%   NPERIODS - Scalar value of the number of periods. The default is period
%   is 14.
%
%   Outputs:
%        RSI - Nx1 vector of the relative strength index
%
%   Note: The RS factor is calculated by dividing the average of the gains by
%   the average of the losses within a specified period.
%
%     RS = (average gains) / (average losses)
%
%   Also, the first value of RSI, RSI(1), is a NaN in order to preserve the
%   dimensions of CLOSEP.
%
%   Example:
%      load disney.mat
%      dis_RSI = rsindex(di

你可能感兴趣的:(写论文第九天:MATLAB之rsindex函数)