“;
$nextFriday = date(‘Y-m-d’, strtotime(‘next Friday’, strtotime($startDate)));
$monthlyExpDate = date(‘Y-m-d’, strtotime(“third friday of 2016-12″));
if ($orderby)
{
if ($orderby == acqVal OR $orderby == acqdate OR $orderby == expdate)
$orderby = $orderby.” desc”;
else
{
$myrand = rand ();
if ($myrand % 2 ==1)
$orderby = $orderby.” desc”;
}
}
else
$orderby = ” (acqVal) DESC “;
$url = basename(__FILE__);
$startYear = date(‘Y’, strtotime($nextFriday)) ;
$startMon = date(‘m’, strtotime($nextFriday))+1 ;
$startDay = date(‘d’, strtotime($nextFriday)) ;
$secondFriday = date(‘Y-m-d’, strtotime(“second friday”,strtotime($startYear.”-“.$startMon.”-01″)));
$thirdFirday = date(‘Y-m-d’, strtotime(“third friday”,strtotime($startYear.”-“.$startMon.”-01″)));
if (date(‘d’, strtotime($secondFriday)) >=15 and date(‘d’, strtotime($secondFriday)) <23) $monthlyExpDate=$secondFriday; else $monthlyExpDate=$thirdFirday; $url = $url."?tickName=$tickName&expdays=$expdays"; for($j=0; ($nextFriday<$monthlyExpDate) ; $j++) { // echo "
Weekly Option expired on $nextFriday\n”;
$within30day = date(‘Y-m-d’, strtotime(‘-30 days’, strtotime($nextFriday)));
if (NULL== $tickName AND NULL== $etfName)
{
$statement= “SELECT tick, acqdate,expdate, corp, strike, acqVol,acqOI,acqVal,acqOPrice,lOPrice, oPnL as optionGain FROM options inner join sstk using (tick) WHERE expDate =’$nextFriday’ ORDER BY “.$orderby;//AND acqDate <'$nextFriday' and acqdate>=’$within30day’
}
else
if ($tickName)
{
$statement= “SELECT tick, acqdate,expdate, corp, strike, acqVol,acqOI,acqVal,acqOPrice,lOPrice, oPnL as optionGain FROM options inner join sstk using (tick) WHERE tick=’$tickName’ AND expDate =’$nextFriday’ AND acqDate <'$nextFriday' ORDER BY ".$orderby;//and acqdate>=’$within30day’
}
else
{
$statement= “SELECT tick, acqdate,expdate, corp, strike, acqVol,acqOI,acqVal,acqOPrice,lOPrice, oPnL as optionGain FROM options inner join setf using (tick) WHERE tick=’$etfName’ AND expDate =’$nextFriday’ ORDER BY “.$orderby;//AND acqDate <'$nextFriday' and acqdate>=’$within30day’
$url = $url.”?etfName=$etfName&expdays=$expdays”;
}
optQuery($url, $statement, “optTiming”);
$nextFriday = date(‘Y-m-d’, strtotime(‘+7 days’, strtotime($nextFriday)));
}
for($j=0; $j<12; $j++)
{
// $monthlyExpDate = date('Y-m-d', strtotime("third friday",strtotime($startYear."-".$startMon."-01")));
$secondFriday = date('Y-m-d', strtotime("second friday",strtotime($startYear."-".$startMon."-01")));
$thirdFirday = date('Y-m-d', strtotime("third friday",strtotime($startYear."-".$startMon."-01")));
if (date('d', strtotime($secondFriday)) >=15 and date(‘d’, strtotime($secondFriday)) <23)
$monthlyExpDate=$secondFriday;
else
$monthlyExpDate=$thirdFirday;
// echo "
monthly Option expired on $monthlyExpDate\n”;
$within30day = date(‘Y-m-d’, strtotime(‘-30 days’, strtotime($monthlyExpDate)));
if (NULL== $tickName AND NULL== $etfName)
{
$statement= “SELECT tick, expdate, corp, strike, acqVol,acqOI,acqVal,acqOPrice,lOPrice, oPnL as optionGain FROM options inner join sstk using (tick) WHERE expDate =’$monthlyExpDate’ ORDER BY “.$orderby;//AND acqDate <'$monthlyExpDate' and acqdate>=’$within30day’
}
else
if ($tickName)
{
$statement= “SELECT tick, acqdate,expdate, corp, strike, acqVol,acqOI,acqVal,acqOPrice,lOPrice, oPnL as optionGain FROM options inner join sstk using (tick) WHERE tick=’$tickName’ AND expDate =’$monthlyExpDate’ ORDER BY “.$orderby;//AND acqDate <'$monthlyExpDate' and acqdate>=’$within30day’
}
else
{
$statement= “SELECT tick, acqdate,expdate, corp, strike, acqVol,acqOI,acqVal,acqOPrice,lOPrice, oPnL as optionGain FROM options inner join setf using (tick) WHERE tick=’$etfName’ AND expDate =’$monthlyExpDate’ ORDER BY “.$orderby;//AND acqDate <'$monthlyExpDate' and acqdate>=’$within30day’
}
optQuery($url, $statement, “optTiming”);
$startMon++;
if ($startMon>12)
{
$startMon=1;
$startYear++;
}
$nextFriday = date(‘Y-m-d’, strtotime(‘+7 days’, strtotime($nextFriday)));
}
?>