PureBytes Links
Trading Reference Links
|
Bob,
Try this:
function Greg2Jul( d, m, y )
{
/*var y = parseFloat(cd2jdform.yearf.value)
var m = parseFloat(cd2jdform.monthf.value)
var d = parseFloat(cd2jdform.dayf.value)
var uh = parseFloat(cd2jdform.uthf.value)
var um = parseFloat(cd2jdform.utmf.value)
var us = parseFloat(cd2jdform.utsf.value)*/
uh=12;
um=0;
us=0;
extra = 100.0*y + m - 190002.5;
rjd = 367.0*y;
//rjd -= floor(7.0*(y+floor((m+9.0)/12.0))/4.0);
rjd = rjd - floor(7.0*(y+floor((m+9.0)/12.0))/4.0);
//rjd += floor(275.0*m/9.0);
rjd = rjd + floor(275.0*m/9.0);
//rjd += d;
rjd = rjd + d;
//rjd += (uh + (um + us/60.0)/60.)/24.0;
rjd = rjd + (uh + (um + us/60.0)/60.)/24.0;
//rjd += 1721013.5;
rjd = rjd + 1721013.5;
//rjd -= 0.5*extra/abs(extra);
rjd = rjd - 0.5*extra/abs(extra);
//rjd += 0.5;*/
rjd = rjd + 0.5;
return rjd;
}
Filter=C>0;
AddColumn(Greg2Jul(Day(),Month(),Year()),"Javascript");
AddColumn(Greg2Jul(Day(),Month(),Year())%7+1,"Day");
Regards,
Peter
PS It seems the shorthand += and -= do not work in Amibroker (yet?)
-----Original Message-----
From: Bob Jagow [mailto:bjagow@xxxxxxxxxxx]
Sent: Wednesday, April 30, 2003 1:09 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Calendar Dates vs Trading Dates a la 4.34 BETA
Therre was an unclosed paren, Peter.
----
function HermeticJulian( d, m, y )
{
result = ( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +( 367 *
( m - 2 - 12 *( ( m - 14 ) / 12 ) ) ) / 12 -( 3 * ( ( y + 4900 + ( m -
14 ) / 12 ) / 100 ) ) / 4 + d - 32075;
return result;
}
function ScienceworldJulian( d, m, y )
{
result = 367 * y - int(7 * (y + int((m + 9) / 12)) / 4)
+ int(275* m / 9) + d + 1721013.5;
return result;
}
---
The two return different results and neither gives the correct
dayofweek(), which is needed in order to calculate ApplyStop.
The correct dayofweek() is given by -32076 and +1721015, respectively.
Bob
-----Original Message-----
From: bluesinvestor [mailto:investor@xxxxxxxxxxxxx]
Sent: Wednesday, April 30, 2003 7:27 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Calendar Dates vs Trading Dates a la 4.34 BETA
Using the new function ability of Amibroker I have tried the following:
function HermeticJulian( d, m, y )
{
result = ( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +( 367 *
( m - 2 - 12 *( ( m - 14 ) / 12 ) ) ) / 12 -( 3 * ( ( y + 4900 + ( m -
14 ) / 12 ) / 100 ) ) / 4 + d - 32075;
return result;
}
/*function ScienceworldJulian( d, m, y )
{
result = 367 * y - int(7 * (y + int((m + 9) / 12)) / 4 + int(275
* m / 9) + d + 1721013.5;
return result;
}*/
Filter=C>0;
AddColumn(HermeticJulian(Day(),Month(),Year()),"Hermetic");
//AddColumn(ScienceWorldJulian(Day(),Month(),Year()),"ScienceWorld");
While I was able to get the first formula to work, the second returned
an error (although I am not sure why).
Regards,
Peter
-----Original Message-----
From: Bob Jagow [mailto:bjagow@xxxxxxxxxxx]
Sent: Saturday, April 26, 2003 3:28 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Calendar Dates vs Trading Dates
I only promised to teach you to fish, Ken 8>)
Forgetting leapyears, the 30 days has Sept... lookup code would be
----
DaysInMonth = dim = IIf(Month()==2,28,IIf((Month()==4 OR Month()==6 OR
Month()==9 OR Month()==11),30,31));
----
Given the buy datenum , add the hold period and calculate the sell
datenum using dim.
ie, if holdP = 30 and bDate = 1030329; sDate = bDate + holdP = 1030359 =
103459 +100 -59 +59%dim = 1030528;
But I'm not sure that datenum() is what you really want. I'd prefer
ApplyStop(3,1,tradingDays), which would involve subtracting Sat
and Sun.
Comes back, therefore, to Julian Day because jd%7 is dayofweek() and you
could calc TradingDays by
---
td = holdp;
for ( i = jd; i < jd+holdP; i++)
{
m = i%7;
if (m == 0 OR m == 6) td--;
}
Googling julian days gave lots of hits:
---
http://www.hermetic.ch/cal_stud/jdn.htm
The Julian day (jd) is computed from Gregorian day, month and year (d,
m, y) as follows:
jd = ( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +( 367 * ( m - 2 - 12
*( ( m - 14 ) / 12 ) ) ) / 12
-( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 + d - 32075;
or
http://scienceworld.wolfram.com/astronomy/JulianDate.html
JD = 367*y - Int(7*(y + int((m+9)/12))/4 + int(275*m/9) +d +1721013.5
---
Haven't tried either; would recommend that you check which ever you
choose against one of the web jd calculators.
Bob
-----Original Message-----
From: Ken Close [mailto:closeks@xxxxxxxx]
Sent: Tuesday, April 29, 2003 4:26 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Calendar Dates vs Trading Dates
Thanks Bob. I hope I get something more specific. I imagine there is
some manipulation of the DateNum() function but I have not been able to
figure it out.
Ken
-----Original Message-----
From: Bob Jagow [mailto:bjagow@xxxxxxxxxxx]
Sent: Tuesday, April 29, 2003 4:34 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Calendar Dates vs Trading Dates
I don't believe AB has a clue re calendar vs. trading days; you need the
difference in Julian days.
If you don't want to use a JDay dll and only need to know, for example,
when the .75% Fido commission expires, consider a 30 days
has Sept.... lookup.
Bob
-----Original Message-----
From: Ken Close [mailto:closeks@xxxxxxxx]
Sent: Tuesday, April 29, 2003 1:10 PM
To: AmiBroker List
Subject: [amibroker] Calendar Dates vs Trading Dates
Help....I want to count the number of calendar days since a buy or
short...
I have read msg # 16104 about creating a For loop inside a Jscript, but
frankly can not understand what it is advising.
Can someone show me a simple way to determine the number of calendar
days that have elapsed? Maybe the new For loop can help?
I want to code in a "close trade" flag if there are more than x number
of calendar days since the trade was initiated. Because of other
aspects of the code, I do not want to (can not) use the dll time stop
that is in the files area.
Any help would really be appreciated.
Ken
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs Online - Over 14,500 titles.
No Late Fees & Free Shipping.
Try Netflix for FREE!
http://us.click.yahoo.com/GwtQXA/XP.FAA/AG3JAA/GHeqlB/TM
---------------------------------------------------------------------~->
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
|