Has anyone seen any other code to determine the expiry code for futures?
I made this up and wonder if I have it close to right. I looked up the Thursday before the 3rd Friday for each expiration month, made and array, and then figured out if this month is expiration and then is it before or after expiration.
Comments appreciated, thanks.
// 2009 expiry 1 2 3 4 5 6 7 8 9 10 11 12
var MM = new Array( 3, 3, 3, 6, 6, 6, 9, 9, 9,12,12,12,13)
var DD = new Array(12,12,12,11,11,11,10,10,10,11,11,11,99)
var init = 0.0;
var d = new Date();
debugClear();
var exp = "";
function main() {
if ( init == 0 ) {
exp = ""+d.getFullYear()+MM[d.getMonth()];//basic logic
if ( d.getMonth() == MM[d.getMonth()] && d.getDate() < MM[d.getMonth()] )//before expiry
exp = ""+d.getFullYear()+MM[d.getMonth()];
if ( d.getMonth() == MM[d.getMonth()] && d.getDate() >= MM[d.getMonth()] )//after expiry
exp = ""+d.getFullYear()+MM[d.getMonth()+1];
if ( d.getMonth() == 12 && d.getDate() >= MM[d.getMonth()] )//december rule
exp = ""+(d.getFullYear()+1)+MM[0];
debugPrintln(exp)
init = 1;
}
return;}
I made this up and wonder if I have it close to right. I looked up the Thursday before the 3rd Friday for each expiration month, made and array, and then figured out if this month is expiration and then is it before or after expiration.
Comments appreciated, thanks.
// 2009 expiry 1 2 3 4 5 6 7 8 9 10 11 12
var MM = new Array( 3, 3, 3, 6, 6, 6, 9, 9, 9,12,12,12,13)
var DD = new Array(12,12,12,11,11,11,10,10,10,11,11,11,99)
var init = 0.0;
var d = new Date();
debugClear();
var exp = "";
function main() {
if ( init == 0 ) {
exp = ""+d.getFullYear()+MM[d.getMonth()];//basic logic
if ( d.getMonth() == MM[d.getMonth()] && d.getDate() < MM[d.getMonth()] )//before expiry
exp = ""+d.getFullYear()+MM[d.getMonth()];
if ( d.getMonth() == MM[d.getMonth()] && d.getDate() >= MM[d.getMonth()] )//after expiry
exp = ""+d.getFullYear()+MM[d.getMonth()+1];
if ( d.getMonth() == 12 && d.getDate() >= MM[d.getMonth()] )//december rule
exp = ""+(d.getFullYear()+1)+MM[0];
debugPrintln(exp)
init = 1;
}
return;}
Comment