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

Re: calling on all maths gurus .....Algorythm / formula needed



PureBytes Links

Trading Reference Links

Cameron:

>i have these 5 datastreams
>data2 , data3 , data4 , data5 , data6
>
>and i want every possible combination of [up to 3 of] these

That's simple IF you want only every permutation of three of them.
You just have a triple nested loop like so:

---------------------------------------------------------------------
vars: N(0), d1(0), d2(0), d3(0);
{N = number of data streams (data1 ... dataN)}

for d1 = 1 to N-2 begin
   for d2 = d1+1 to N-1 begin
      for d3 = d2+1 to N begin

         {your code goes here, and you reference the three
          data streams as data(d1), data(d2) and data(d3),
          instead of explicityly referencing data3, data7, etc.}

      end;
   end;
end;
---------------------------------------------------------------------

However, if you want to get single and pair combos as well as triple
combos, you need to change the loop bounds to allow for duplicates,
and then make comparisons to check when 2 or more are duplicated,
and have separate code sections to handle singles, pairs of values,
and three values.  Like this:

---------------------------------------------------------------------

for d1 = 1 to N begin
   for d2 = d1 to N begin
      for d3 = d2 to N begin

         if d1=d2 AND d2=d3 then begin
            {code for single value goes here, just use data(d1)}
         end

         else if d1=d2 OR d2=d3
            {code for pair combos goes here; use data(d1) and data(d3)
             as your data streams}
         end

         else
            {code for triple combos goes here; use
             data(d1), data(d2) and data(d3)}
         end;

      end;
   end;
end;
---------------------------------------------------------------------

-Alex