Hello,
 
I have written a new function 'cov2corr()' to the financial package in Octave, 
based on MatLab's financial toolbox manual.  Basically cov2corr() convert 
covariance to standard deviation and correlation coefficient.  For example, 

ExpCovariance = [0.25 -0.5
                -0.5   4.0];


[ExpSigma, ExpCorrC] = cov2corr(ExpCovariance)

Expected results:  ExpSigma =

    0.5000    2.0000

ExpCorrC =

    1.0000   -0.5000
   -0.5000    1.0000
 
Wish for suggestions.  Thanks a lot!
 
Best regards,
 
Hong Yu
                                          
## Copyright (C) 2011 		Hong Yu
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {} cov2corr (@var{cov})
## Convert covariance input to output standard deviation and correlation 
## coefficient.
##
##
## @seealso{corr2cov, corrcoef, cov, cov2corr, ewstats, std}
## @end deftypefn

## Author: Hong Yu <hyu0...@hotmail.com>
## Description: Convert covariance to standard deviation and correlation 
## coefficients

function [sigma, corr] = cov2corr (cov)

  if ( nargin != 1 )
    print_usage ();
  endif

  csize = size(cov);

  if ( csize(2) != csize(1) )
    error("covariance: must be nxn");    
  endif

  corr = cov;
  sigma = 1:csize(2);

  for i = 1 : csize(2)
    sigma(i) = sqrt(cov(i,i));
    corr(i,i) = 1.0;

    for j = 1 : (i-1)
      corr(j,i) /= (sigma(j) * sigma(i));
      corr(i,j) = corr(j,i);
    endfor

  endfor

endfunction

------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to