help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sliding window problem


From: charles sugihara
Subject: sliding window problem
Date: Tue, 14 Dec 2004 15:19:13 -0800

Hi All (again)-
i am having a problem getting this to work, i got it to work when calculating percentage correct windows (see my last post)... line 23 of "do_x_day_averages.m" would read "retval(i) = wins/(wins/losses);" but, in trying to replace "wins" with "returns" i expected to compute the average, actually the net/n, i.e not returns divided by 64 but returns divided by total number of actions (not necessarily 64 in a 64-day window). i suspect i am not defining "returns" correctly in "do_x_day_averages.m"? or maybe i need to create a variable like "counter" and add up the absolute value of "action_col" in the 64-day window? any comments or help is greatly appreciated
Thank You,
 Max
---------------------------------------------------------
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'
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'
error: evaluating assignment expression near line 23, column 14
error: evaluating if command near line 22, column 2
error: evaluating if command near line 13, column 7
error: evaluating if command near line 11, column 5
error: evaluating for command near line 10, column 3
error: called from `do_x_day_averages' in file `/Users/sugi/work/octave/help/do_x_day_averages.m' error: near line 6 of file `/Users/sugi/work/octave/help/make_64_averages.m'
octave:3>
------------------------------------------------------------------------ ---------
here is a sample of "small.block"
[charles-sugiharas-Computer:~/work/octave/help] sugi% head small.block
20000117 0 0.25
20000118 0 0.71875
20000119 -1 0.0625
20000120 1 -0.65625
20000121 1 0.21875
20000124 1 0.8125
20000125 -1 -0.28125
20000126 1 0.3125
20000127 1 0.09375
20000128 1 0.15625
------------------------------------------------------------------------ ----------
here is "real_ranges.m"
xx=[1:1203];
yy=[1205:2458];
------------------------------------------------------------------------ ----------
here is "mk_64_averages.m"
real_ranges;

average_64day = zeros(max(size(blk)), 1);

count = 1;
[average, ranges] = do_x_day_averages(xx, 64, 2, 3);
average_64day(xx) = average;
lib(count, 1) = ranges(1);
lib(count, 2) = ranges(2);
count++;

[average, ranges] = do_x_day_averages(yy, 64, 2, 3);
average_64day(yy) = average;
lib(count, 1) = ranges(1);
lib(count, 2) = ranges(2);
count++;
------------------------------------------------------------------------ -----------
here is "do_x_day_averages.m"
function [retval,newrange] = do_x_day_averages(inst_range, x, action_col, return_col)
  global blk;

  retval = zeros(max(size(inst_range)),1);

  window = zeros(x,1);
  num_in_window = 0;
  firstindex = 0;

  for i = 1:max(size(inst_range))
    if (blk(inst_range(i), action_col) != 0)
      window(++num_in_window) = inst_range(i);
      if (num_in_window == x)

        if (firstindex == 0)
          firstindex = inst_range(i);
        endif

        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

        window(1:(x-1)) = window(2:x);
        num_in_window--;
      endif
    else
      if (i > 1)
        retval(i) = retval(i-1);
      endif
    endif
  endfor

  newrange=[firstindex, inst_range(max(size(inst_range)))];
endfunction
------------------------------------------------------------------------ --------------------------



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]