[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sliding window problem
From: |
Miroslaw Kwasniak |
Subject: |
Re: sliding window problem |
Date: |
Wed, 15 Dec 2004 03:22:13 +0100 |
User-agent: |
Mutt/1.5.6+20040907i |
On Tue, Dec 14, 2004 at 03:19:13PM -0800, charles sugihara wrote:
> ---------------------------------------------------------
> here are the errors...
> octave:1> global blk
> octave:2> blk = load('small.block');
> octave:3> make_64_averages
> error: `do_x_day_averages' undefined near line 6 column 21
> error: near line 6 of file
> `/Users/sugi/work/octave/help/make_64_averages.m'
didn't you save m-file???
> octave:3> make_64_averages
> error: A(I) = X: X must be a scalar or a vector with same length as I
> error: assignment failed, or no method for `matrix = matrix'
returns =
-0.062500
-0.656250
0.218750
0.812500
0.281250
wins = 3
losses = 2
returns = blk(window, action_col) .* blk(window, return_col)
wins = max(size(find(returns>0)))
losses = max(size(find(returns < 0)))
if ((wins + losses) != 0)
-----> retval(i) = returns/(wins+losses);
else
retval(i) = 0;
end
Maybe you want:
retval(i) = sum(returns)/(wins+losses);
or
retval(i) = mean(returns)/(wins+losses);
or even
retval(i) = mean(returns);
????
If third option (equivalent to first) then you can do whithout a loop:
function [retval,newrange] = do_x_day_averages(inst_range, x, action_col,
return_col)
global blk;
i = find (blk(inst_range(i), action_col) != 0);
if isempty(i); warning('isempty'); return; endif
returns = blk(i, action_col) .* blk(i, return_col)
returns = returns(1:fix(end/x)*x); % unfinished window problem
returns = reshape( returns, x, length(returns)/x );
% wins = sum(returns > 0);
% losses = sum(returns < 0);
retval_i = mean( returns )';
% indexing trick
if i(1) > 1;
retval_i = [ 0; retval_i ];
i = [ 1; i ];
endif
ni = 1:length(i);
n = zeros( length(inst_range), 1 );
n(i) = ni;
n(i(2:end)) -= ni(1:end-1);
n = cumsum(n); % Here is a magic :)
retval = retval_i(n);
newrange=[ inst_range(i(1)), inst_range(end)];
% again how deal with unfinished window problem ????
endfunction
Mirek
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------