logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
uasish  
#1 Posted : Saturday, September 23, 2006 6:43:33 AM(UTC)
uasish

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/13/2005(UTC)
Posts: 170

Thanks: 7 times

Seniors,

The contracts expire on last Thursday of every month.Suppose today is 22nd & last thursday is 28th Sep'06 .How to calculate (28 - 22 = 6),as an indicator.

I tried the following code ,which is wrong.Guide me how to do it .

.......................................................................

a:= DayOfMonth()=22 ;
b:= ExtFml( "Forum.DateRange",a , DayOfMonth()=28 );
(b-a);

..................................................................

Asish

hayseed  
#2 Posted : Saturday, September 23, 2006 8:29:58 AM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey asish.... thats a neat idea.... kinda of a callender count down..... below is just an quick idea..... the input function was used to make the indicator flexible to other last-thursday-different-number months....

you might even want to include the month or perhaps even year....h

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

a:=Input("thursday",1,31,28);
aa:=a-DayOfMonth();

aa;

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

uasish  
#3 Posted : Monday, September 25, 2006 8:27:40 AM(UTC)
uasish

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/13/2005(UTC)
Posts: 170

Thanks: 7 times

Hayseed,

To calculate "Cost of Carry" as an indicator ,i need the No of Days left for expiry from the begining of the new series,hence this simple Input func. is not going to help much.Thanks for your reply.

Asish

wabbit  
#4 Posted : Monday, September 25, 2006 9:03:53 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Ashish,

This is something I threw together, it might be useful to you?

Code:

{Find the last Thursday in the Month}
d:=4; {Thursday}

leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;
m:=Month();

maxDaysinMonth:=
If(m=1 OR m=3 OR m=5 OR m=7 OR m=8 OR m=10 OR m=12,31,
If(m=4 OR m=6 OR m=9 OR m=11,30,28+leap));

DayOfWeek()=d AND (maxDaysinMonth-DayOfMonth())<7;



wabbit [:D]


wabbit  
#5 Posted : Monday, September 25, 2006 9:08:09 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
new idea....

tie this code in with Jose's Days Since function (http://www.metastocktools.com/MetaStock/DaysSince.txth?

This bit doesn't work.... its late here and I am going to bed, but it will give you something to think about?

Code:

{uses Jose Silvas Calendar code}
{http://www.metastocktools.com/MetaStock/DaysSince.txt}

d:=4; {Thursday}
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;
m:=Month();

maxDaysinMonth:=
If(m=1 OR m=3 OR m=5 OR m=7 OR m=8 OR m=10 OR m=12,31,
If(m=4 OR m=6 OR m=9 OR m=11,30,28+leap));

event:=DayOfWeek()=d AND (maxDaysinMonth-DayOfMonth())<7;

{Calendar counter engine}
y:=Year()*365+Int(Year()/4)
 -Int(Year()/100)+Int(Year()/400)-730484;
m:=
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
DayNr:=y+m+DayOfMonth();
DaysSince:=DayNr-ValueWhen(1,event,DayNr);

{countdown}
28-DaysSince; {refinement needed here! but you get the idea?}




wabbit [:D]


uasish  
#6 Posted : Monday, September 25, 2006 10:55:38 AM(UTC)
uasish

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/13/2005(UTC)
Posts: 170

Thanks: 7 times

Wabbit,

Thanks, now i got the idea and will be able to work out the indicator.

Asish

wabbit  
#7 Posted : Monday, September 25, 2006 7:19:11 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Asish,

Here is my take on the code.... see what you think. I think I have covered all the bases amd got it right. I haven't done any extensive testing. It works on daily plots only. It will get all screwed up if you try another periodicity!

Code:

{CountDown to the last Thursday in the Month}
{coded by wabbit :D}
{http://www.wabbit.com.au}
{26 September 2006}

{uses Jose Silvas Calendar code}
{http://www.metastocktools.com/MetaStock/DaysSince.txt}

{Event}
d:=4; {Thursday}

leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;

m:=Month();
nm:=m+1;
nm:=If(nm>12,1,nm);

DaysinThisMonth:=
If(m=1 OR m=3 OR m=5 OR m=7 OR m=8 OR m=10 OR m=12,31,
If(m=4 OR m=6 OR m=9 OR m=11,30,28+leap));

DaysinNextMonth:=
If(nm=1 OR nm=3 OR nm=5 OR nm=7 OR nm=8 OR nm=10 OR nm=12,31,
If(nm=4 OR nm=6 OR nm=9 OR nm=11,30,28+leap));

event:=DayOfWeek()=d AND (DaysinThisMonth-DayOfMonth())<7;

{Calendar counter engine}
y:=Year()*365+Int(Year()/4)
 -Int(Year()/100)+Int(Year()/400)-730484;
m:=
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
DayNr:=y+m+DayOfMonth();

{Days since event}
DaysSince:=DayNr-ValueWhen(1,event,DayNr);

{countdown}
z:=If(35-ValueWhen(1,event,DaysinThisMonth-DayOfMonth())>ValueWhen(1,event,DaysinNextMonth),28,35);
cd1:=z-DaysSince;

{No Event this month!}
event:=cd1<=0 AND Alert(cd1>0,2);
DaysSince:=DayNr-ValueWhen(1,event,DayNr-cd1-1);
z:=If(35-ValueWhen(1,event,DaysinThisMonth-DayOfMonth())>ValueWhen(1,event,DaysinNextMonth),28,35);
cd2:=z-DaysSince;

{plot}
If(cd1>0,cd1,cd2)



wabbit [:D]


uasish  
#8 Posted : Monday, September 25, 2006 8:58:32 PM(UTC)
uasish

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/13/2005(UTC)
Posts: 170

Thanks: 7 times

Wabbit,

Fantastic,this is exactly what i require,thanks.

Asish

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.