日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab的index函数,写论文第九天:MATLAB之rsindex函数

發布時間:2025/4/16 循环神经网络 89 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab的index函数,写论文第九天: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(dis_CLOSE);

% plot(dis_RSI);

%

% See also NEGVOLIDX, POSVOLIDX.

% Reference: Murphy, John J., Technical Analysis of the Futures Market,

% New York Institute of Finance, 1986, pp. 295-302

% Copyright 1995-2006 The MathWorks, Inc.

% $Revision: 1.1.6.3 $ $Date: 2006/03/21 07:01:38 $

% Check input arguments.

switch nargin

case 1

nperiods = 14;

case 2

if numel(nperiods) ~= 1 || mod(nperiods, 1) ~= 0

error('Ftseries:rsindex:NPERIODSMustBeScalar', ...

'NPERIODS must be a scalar integer.');

elseif nperiods > length(closep)

error('Ftseries:rsindex:NPERIODSTooLarge1', ...

'NPERIODS is too large for the number of data points.');

end

otherwise

error('Ftseries:rsindex:InvalidNumberOfInputArguments', ...

'Invalid number of input arguments.');

end

% Check to make sure closep is a column vector

if size(closep, 2) ~= 1

error('Ftseries:rsindex:ClosepMustBeColumnVect', ...

'Closing prices must be a column vector.');

end

% Check for data sufficiency.

if length(closep) < nperiods

error('Ftseries:rsindex:NPERIODSTooLarge2', ...

'NPERIODS is too large for the number of data points.');

end

% Calculate the Relative Strength index (RSI).

if (nperiods > 0) && (nperiods ~= 0)

% Determine how many nans are in the beginning

nanVals = isnan(closep);

firstVal = find(nanVals == 0, 1, 'first');

numLeadNans = firstVal - 1;

% Create vector of non-nan closing prices

nnanclosep = closep(~isnan(closep));

% Take a diff of the non-nan closing prices

diffdata = diff(nnanclosep);

priceChange = abs(diffdata);

% Create '+' Delta vectors and '-' Delta vectors

advances = priceChange;

declines = priceChange;

advances(diffdata < 0) = 0;

declines(diffdata >= 0) = 0;

% Calculate the RSI of the non-nan closing prices. Ignore first non-nan

% closep b/c it is a reference point. Take into account any leading nans

% that may exist in closep vector.

trsi = nan(size(diffdata, 1)-numLeadNans, 1);

for didx = nperiods:size(diffdata, 1)

% Gains/losses

totalGain = sum(advances((didx - (nperiods-1)):didx));

totalLoss = sum(declines((didx - (nperiods-1)):didx));

% Calculate RSI

rs = totalGain ./ totalLoss;

trsi(didx) = 100 - (100 / (1+rs));

end

% Pre allocate vector taking into account reference value and leading nans.

% length of vector = length(closep) - # of reference values - # of leading nans

rsi = nan(size(closep, 1)-1-numLeadNans, 1);

% Populate rsi

rsi(~isnan(closep(2+numLeadNans:end))) = trsi;

% Add leading nans

rsi = [nan(numLeadNans+1, 1); rsi];

elseif nperiods < 0

error('Ftseries:rsindex:NPERIODSMustBePosScalar', ...

'NPERIODS must be a positive scalar.');

else

rsi = closep;

end

% [EOF]

原文:http://blog.csdn.net/liangzuojiayi/article/details/51330602

總結

以上是生活随笔為你收集整理的matlab的index函数,写论文第九天:MATLAB之rsindex函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。