⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmac.m

📁 A technical trading system comprises a set of trading rules that can be used to generate trading sig
💻 M
字号:
function H = DMAC(eIndex,stocktype,speriod,lperiod,mxargus)
%---------------------------------------------------------------------------------------------
% H=DMAC(Index, Stock type,Short period,Long period, Data Matrix)
% Dual Moving Average Crossover
% Moving average based trading systems are the simplest and most popular trend- following
% systems among practitioners (Taylor and Allen 1992; Lui and Mole 1998). According to Neftci
% (1991), the (dual) moving average method is one of the few technical trading procedures that is
% statistically well defined. The Dual Moving Average Crossover system generates trading signals
% by identifying when the short-term trend rises above or below the long-term trend.
%
%   Usage Examples,
%
%   Trade Rule = movingaverage(3, 5, 3, 5, Argus); 
%   Created by Champ Mendis <champake@ieee.org>
%   Version 1.00
%   31 Octobeer, 2006
%   Copyright Reserved  
%  
%--------------------------------------------------------------------------
TRule=-1;
% Calculate Short & Long Averages
for i=1:eIndex
    sAverage = subAverage(mxargus,stocktype,i,speriod);
    lAverage = subAverage(mxargus,stocktype,i,lperiod);
end
% Apply Trading Rules
    if sAverage>lAverage
        TRule = 1; % Buy
    else
        TRule = 0; % Sell
    end
TDecision = TRule; 

% Return Trade Rule
H = TDecision;



% Utilities
function vAverage = subAverage(margus,stype,aIndex,period)    
sTotal = 0;
lBound = aIndex - floor(period /2);
if lBound<1  
   lBound = 1;sTotal = sTotal + margus(lBound,stype); 
end
uBound = aIndex + floor(period/2);
if uBound>length(margus)
   uBound = length(margus); sTotal + margus(uBound,stype);
end
    for j = lBound:uBound
        sTotal = sTotal + margus(j,stype);
    end
vAverage=sTotal/period;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -