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

Re: next 3rd friday code for TS 4



PureBytes Links

Trading Reference Links

This TS4 ela attached is from Omega Research

{TS4 Function  Next3rdFriday}
{Calculates days to next stock/index option expiration
Input - Series: the current date
Related functions -  BlackScholes( )  DaysToExpiration( )  Implied
Volatility( )}

Inputs: Series(NUMERIC);
Vars:daysLeft1(0), daysToTarget(0), wd1(0), year2(0), month1(0), year1(0),
monthTarget(0), dayTarget(0), yearTarget(0), third_friday1(0),
first_friday1(0), julianTarget(0), julianNow(0), szmonth(0), szday(0),
szyear(0), SeriesRotation(0);

daysLeft1=0;
daysToTarget=0;
wd1=0;
year2=0;
month1=0;
year1=0;
monthTarget=0;
dayTarget=0;
yearTarget=0;
third_friday1=0;
first_friday1=0;
julianTarget=0;
julianNow=0;
szmonth=0;
szday=0;
szyear=0;
SeriesRotation=1; {SeriesRotation}
SeriesRotation=Series-1;

szday=@xxxxxxxxxx(Date);
szmonth=@xxxxx(Date);
szyear=@xxxx(Date);

year2=szyear;
wd1=@xxxxxxxxx((szyear*10000)+(100*szmonth)+1);

if wd1=0 then first_friday1=6;
if wd1=1 then first_friday1=5;
if wd1=2 then first_friday1=4;
if wd1=3 then first_friday1=3;
if wd1=4 then first_friday1=2;
if wd1=5 then first_friday1=1;
if wd1=6 then first_friday1=7;

third_friday1=first_friday1+14;

if third_friday1>szday then begin
 month1=szmonth;
 year1=szyear;
End
Else begin
 month1=szmonth+1;
 if month1=13 then begin
  month1=1;
  year1=szyear+1;
 End
 else begin
  year1=szyear;
 End;
End;

monthTarget=month1+SeriesRotation;

{ ***Study  : Next3rdFriday
Last Edit : 7/7/95
Provided By : Omega Research, Inc. (c) Copyright 1995***}
if monthTarget > 12
then begin
 monthTarget=monthTarget-12;
 yearTarget=year1+1;
end
else
begin
 yearTarget=year1;
end;

wd1=@xxxxxxxxx((yearTarget*10000)+(100*monthTarget)+1);

if wd1=0 then first_friday1=6;
if wd1=1 then first_friday1=5;
if wd1=2 then first_friday1=4;
if wd1=3 then first_friday1=3;
if wd1=4 then first_friday1=2;
if wd1=5 then first_friday1=1;
if wd1=6 then first_friday1=7;

dayTarget=first_friday1+14;
julianNow=DateToJulian((10000*szyear)+(100*szmonth)+szday);
julianTarget=DateToJulian((10000*yearTarget)+(100*monthTarget)+dayTarget);

Next3rdFriday=julianTarget-julianNow;
{*** end of Function: Next3rdFriday code ***}

Neville

-----Original Message-----
From: Snosnosnow@xxxxxxx <Snosnosnow@xxxxxxx>
To: omega-list@xxxxxxxxxx <omega-list@xxxxxxxxxx>
Date: Sunday, November 19, 2000 8:16 PM
Subject: next 3rd friday code for TS 4


>Does anyone have the code or ela for next 3rd friday for ts 4?
>
>I have it for 2K but not able to convert it to ts 4. I am looking to
>reference the H, L , C of that day.
>
>It is attached thanks to Clyde Lee.
>
>Thanks
>Sno
>
>
>
>{*******************************************************************
>Description : This Function returns Next3rdFriday
>Provided By : Omega Research, Inc. (c) Copyright 1999
>********************************************************************}
>
>Inputs: Series(Numeric);
>Variables: WorkDay(0), Month1(0), Year1(0), MonthTarget(0), DayTarget(0),
>YearTarget(0), FirstFriday(0), ThirdFriday(0), JulianTarget(0),
julianNow(0),
>SZMonth(0), SZDay(0), SZYear(0), SeriesRotation(1);
>
>SeriesRotation = Series - 1;
>SZDay = DayOfMonth(Date);
>SZMonth = Month(Date);
>SZYear = Year(Date);
>
>WorkDay = DayOfWeek((SZYear * 10000) + (100 * SZMonth) + 1);
>
>If WorkDay = 0 Then
> FirstFriday = 6;
>If WorkDay = 1 Then
> FirstFriday = 5;
>If WorkDay = 2 Then
> FirstFriday = 4;
>If WorkDay = 3 Then
> FirstFriday = 3;
>If WorkDay = 4 Then
> FirstFriday = 2;
>If WorkDay = 5 Then
> FirstFriday = 1;
>If WorkDay = 6 Then
> FirstFriday = 7;
>
>ThirdFriday = FirstFriday + 14;
>
>If ThirdFriday > SZDay Then Begin
> Month1 = SZMonth;
> Year1 = SZYear;
>End
>Else Begin
> Month1 = SZMonth + 1;
> If Month1 = 13 Then Begin
>  Month1 = 1;
>  Year1 = SZYear + 1;
> End
> Else Begin
>  Year1 = SZYear;
> End;
>End;
>
>MonthTarget = Month1+SeriesRotation;
>
>If MonthTarget > 12 Then Begin
> MonthTarget = MonthTarget - 12;
> YearTarget = Year1 + 1;
>End
>Else Begin
> YearTarget = Year1;
>End;
>
>WorkDay = DayOfWeek((YearTarget * 10000) + (100 * MonthTarget) + 1);
>
>If WorkDay = 0 Then
> FirstFriday = 6;
>If WorkDay = 1 Then
> FirstFriday = 5;
>If WorkDay = 2 Then
> FirstFriday = 4;
>If WorkDay = 3 Then
> FirstFriday = 3;
>If WorkDay = 4 Then
> FirstFriday = 2;
>If WorkDay = 5 Then
> FirstFriday = 1;
>If WorkDay = 6 Then
> FirstFriday = 7;
>
>DayTarget = FirstFriday + 14;
>
>julianNow = DateToJulian((10000 * SZYear) + (100 * SZMonth) + SZDay);
>JulianTarget = DateToJulian((10000 * YearTarget) + (100 * MonthTarget) +
>DayTarget);
>
>Next3rdFriday = JulianTarget-JulianNow;
>
>

Attachment: Description: "Next3rdf.ela"