Hello,
Attached is the updated shorter "corr2cov.m". Does it look better for the
financial package? Thanks!
Best regards,
Hong Yu
> From: hyu0...@hotmail.com
> To: so...@hauberg.org
> CC: octave-dev@lists.sourceforge.net; hyu0...@hotmail.com
> Subject: Re: [OctDev] first try of improving financial package and related
> Date: Sun, 11 Sep 2011 18:03:15 -0700
>
>
> Hello,
>
> Thanks! Will update asap.
>
> Best regards,
>
> Hong Yu
>
>
>
> -----Original Message-----
> From: SørenHauberg
> Sent: Sunday, September 11, 2011 2:54 AM
> To: YuHong
> Cc: octave-dev@lists.sourceforge.net
> Subject: Re: [OctDev] first try of improving financial package and related
>
> søn, 11 09 2011 kl. 17:34 -0700, skrev YuHong:
> > I wish to add new functions to the financial package in Octave. The
> > base is MatLab’s financial toolbox manual. Attached is my first try
> > of coding the ‘corr2cov’ function. Basically corr2cov() calculates
> > and returns covariance matrix from standard deviation and correlations
> > input.
> >
> > Wish for suggestions. Thanks a lot!
>
> Can't you write
>
> ret = corr .* (sigma * sigma.');
>
> instead of
>
> ret = corr;
>
> csize = size(corr);
>
> for i = 1:csize(1)
> for j = 1:csize(2)
> ret(i,j) *= sigma(i) * sigma(j);
> endfor
> endfor
>
> (or something like that) ?
>
> Søren
>
## 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} {} corr2cov (@var{sigma}, @var{corr})
## Returns the covariance value or matrix.
##
##
## Note that the rate @var{r} is specified as a fraction (i.e., 0.05,
## not 5 percent).
## @seealso{corrcoef, cov, cov2corr, ewstats, std}
## @end deftypefn
## Author: Hong Yu <hyu0...@hotmail.com>
## Description: Convert standard deviation and correlation to covariance
function ret = corr2cov (sigma, corr)
if ( nargin != 2 )
print_usage ();
endif
ssize = size(sigma);
csize = size(corr);
if ( ssize(1) != 1 )
error ("sigma: must be 1xn");
elseif ( csize(1) != csize(2) )
error("corr: must be nxn");
elseif ( ssize(2) != csize(1) )
error("sigma: must be 1xn \ncorr: must be nxn");
endif
ret = corr .* (sigma' * sigma);
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