First problem is that blk is undefined. Maybe you want:
blk = load('small.block');
Second problem, having blk defined as above, it is shorter
than the list of indices given in ff. The only way this
would have worked before is if accessing an index beyond
the end of an array were to return zero instead of generating
an error. Somebody with a longer memory is going to have to
let you know if that was the case.
A possible solution in do_x_day_perc:
...
n = rows(blk);
for i=1:max(size(inst))
if (inst(i) <= n && blk(inst(i),buysell_col) != 0)
...
There are other solutions, such as extending blk to be the length
of max(inst) using:
blk = postpad(blk,max(inst),0);
You will next have the problem that 'us' is undefined in
ten_day_percs.
- Paul
On Dec 8, 2004, at 1:05 AM, charles sugihara wrote:
wow! you guys are really nice and responsive, here are the scripts
and a short description, i am happy to go into detail but will try
and keep it as brief as possible here, i am hoping you will see a
basic syntax error and not have to be too bothered with the actual
program...
the input is modified for this example but the "block" is actually
close to 6000 lines each with over 300 columns, for this test i made
it 1657 lines by 3 columns. there are 2 subsets within the 1657
lines ("ff" and "gg") denoted by "real_ranges.m" and for both sets
the first column is a date value, the second is a return and the
third is a buy, sell or no action (1, -1, 0 respectively).
the two scripts are "make_10_percs.m" and "do_x_day_perc.m", the
purpose is to make a 10 day sliding window (incremented by 1) of
percentage correct based on columns 2 and 3 of "small.block", the
output is a single column of percentage values in decimal form.
----------------------------------------------------------------------
----------------------------------------------
here is what i have got out of octave so far...
octave:1> load small.block
octave:2> global blk
octave:3> make_10_percs
error: invalid row index = 1
error: invalid column index = 3
error: evaluating binary operator `!=' near line 11, column 35
error: if: error evaluating conditional expression
error: evaluating if command near line 11, column 5
error: evaluating for command near line 10, column 3
error: called from `do_x_day_perc' in file
`/Users/sugi/work/PERC/test.percs/do_x_day_perc.m'
error: near line 11 of file
`/Users/sugi/work/PERC/test.percs/make_10_percs.m'
octave:3>
----------------------------------------------------------------------
----------------------------------------
here is a sample of "small.block"
19850819 0.46875 0
19850820 0.28125 0
19850821 0.34375 -1
19850822 -0.15625 -1
19850823 -0.1875 1
19850826 -0.15625 1
19850827 0.625 0
19850828 -0.375 0
19850829 -0.1875 0
19850830 -1.03125 0
19850903 0.53125 0
19850904 0 -1
19850905 -0.59375 0
19850906 -0.625 0
19850909 0.0625 1
19850910 -0.15625 -1
19850911 -0.03125 1
19850912 -0.125 0
----------------------------------------------------------------------
----------------------------
here is "make_10_percs.m"
# load up the real ranges.
real_ranges;
ten_day_percs = zeros(max(size(blk)), 1);
# 2 and 3 are the return, and buysell columns of the block
count = 1;
[percs, ranges] = do_x_day_perc(ff, 10, 3, 2);
ten_day_percs(us) = percs;
lib(count, 1) = ranges(1);
lib(count, 2) = ranges(2);
count++;
----------------------------------------------------------------------
--------
here is "real_ranges.m"
(note: i realize there is a 1 line gap between libraries, and an
extra line at the end)
ff=[1:1032];
gg=[1034:1656];
----------------------------------------------------------------------
---------
here is do_x_day_perc.m"
function [retval,newrange] = do_x_day_perc(inst, x, buysell_col,
ret_col)
global blk;
retval = zeros(max(size(inst)),1);
window = zeros(x,1);
num_in_window = 0;
firstindex = 0;
for i = 1:max(size(inst))
if (blk(inst(i), buysell_col) != 0)
window(++num_in_window) = inst(i);
if (num_in_window == x)
if (firstindex == 0)
firstindex = inst(i);
endif
# calculate a perc and store it in retval
returns = blk(window, buysell_col) .* blk(window, ret_col);
wins = max(size(find(returns>0)));
losses = max(size(find(returns < 0)));
if ((wins + losses) != 0)
retval(i) = wins/(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(max(size(inst)))];
endfunction
----------------------------------------------------------------------
------------------------------------
thank you again, i am extremely grateful for any input into getting
this to work again.
-max
-------------------------------------------------------------
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
-------------------------------------------------------------
-------------------------------------------------------------
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
-------------------------------------------------------------