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

Re: Top step



PureBytes Links

Trading Reference Links

Well, since this *is* the omega list, here are a couple of tidbits.
Enjoy.

-- 
  Dennis

{************************************************
function: SP_DaysToExpiration

Returns the number of calendar days until the
expiration of the top step contract, i.e. the
third Friday of expiration month.

DH, 2001
*************************************************}

var: count(0), jdate(0), dat(0), expfound(false); 

if d > d[1] or currentbar = 1 then begin
  count = 0;
  jdate = datetojulian(date);
  expfound = false;
  while expfound = false begin
    dat = juliantodate(jdate + count);
    if mod(month(dat),3) = 0
      and dayofweek(dat) = 5
      and dayofmonth(dat) <= 21
      and dayofmonth(dat) >= 15
      then begin
        expfound = true;
        sp_daystoexpiration = count;
      end;
    count = count + 1;
  end;
end;


{************************************************
function: SP_DaysToRoll

Returns the number of calendar days until the
last trading day of the top step contract, i.e. the
Wednesday before the second Friday of expiration
month.

DH, 2001
*************************************************}

var: count(0), jdate(0), dat(0), rollfound(false); 

if d > d[1] or currentbar = 1 then begin
  count = 0;
  jdate = datetojulian(date);
  rollfound = false;
  while rollfound = false begin
    dat = juliantodate(jdate + count);
    if mod(month(dat),3) = 0
      and dayofweek(dat) = 3
      and dayofmonth(dat) <= 12
      and dayofmonth(dat) >= 6
      then begin
        rollfound = true;
        sp_daystoroll = count;
      end;
    count = count + 1;
  end;
end;