ewmacorr.m
来自「统计工具软件」· M 代码 · 共 50 行
M
50 行
function [delta,dev,cor,C] = ewmacorr(DX,DR,legame,lambda)%EWMACORR correlation between risk factors and assets (EWMA).%% [delta,dev,cor,C] = ewmacorr(DX,DR,legame,lambda) calculates the standard% deviations of risk factors and the correlation matrix with exponential% ponderation of data with lambda value. Delta coefficients are% calculated whitout ponderation. It needs the DX matrix of assets% yields, the DR matrix of risk factors yields.% The vector legame set the relations between assets and risk factors.% Given 2 risk factors and 4 assets the vector (1 1 1 2) means that the% first three assets are related with the first risk factors, the fourth% asset with the second risk factor.% All data must be in column.%% See RENDIMENTI%% Copyright (c) 2004 by Flavio Bazzana% Department of Computer and Management Sciences% University of Trento% 38100 - Trento ITALY% flavio.bazzana@economia.unitn.it% calculation of the correlation matrix and the standard deviations% of risk factors with null average[n,m] = size(DR);for l=1:n la(l)=lambda^(n-l);endfor f=1:m LA(:,f)=la';endR2 = (DR.*LA)'*DR;C = (1-lambda).*R2;dev = sqrt(diag(C));cor = C./(dev*dev');% calculation of delta coefficientsn = size(DX,2);for i=1:n h = legame(i); p = polyfit(DR(:,h),DX(:,i),1); delta(i) = p(1);enddelta = delta';
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?