#’, $content, $match);
//#$price = $match[1];
//#preg_match(‘##’, $content, $match);
//#$in_stock = $match[1];
//#echo “Price: $price – Availability: $in_stock\n”;
return $values;
}
function getHistNdPctChg($tick, $date, &$ndpctchg)
{
if (NULL == $date)
{
echo “Invalid date input”;
return 0;
}
$date = date(“Y-m-d”, strtotime($date));
$conn = open_db();
$statement = “SELECT ndpctchg FROM tastk WHERE tick=’$tick’ and date=’$date’ “;
// $selection =$conn->query($statement);
if(($selection =$conn->query($statement)) === false)
{
echo “$statement failed \n”;
close_db($conn);
return;
}
if ( $selection->num_rows==0)
{
// echo “$statement empty selection\n”;
$ndpctchg =0;
$conn->close();
return 0;
}
else
{
$row = $selection->fetch_assoc() ;
$ndpctchg = $row[‘ndpctchg’];
// echo $ndpctchg;
}
$selection->free();
$conn->close();
return 1;
}
function getLastClosedTradingdate($date)
{
$hour = date(‘H’);
// echo “Hour=”.$hour.”\n”;
if ($hour <13)
$date = date("Y-m-d",strtotime("-1 day", strtotime($date)));
if (in_array($date, $GLOBALS['marketHoliday'])) {
echo "skip holiday";
$date = date ("Y-m-d", strtotime("-1 day", strtotime($date)));
}
$day = date('D', strtotime($date));
if ($day =='Sat')
$date = date("Y-m-d",strtotime("-1 day", strtotime($date)));
if ($day =='Sun')
$date = date("Y-m-d",strtotime("-2 day", strtotime($date)));
if (in_array($date, $GLOBALS['marketHoliday'])) {
echo "skip holiday";
$date = date ("Y-m-d", strtotime("-1 day", strtotime($date)));
}
// echo "date=".$date."\n";
return $date;
}
function getNextTradingdate($date)
{
$nbdate = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
$day = date('D', strtotime($nbdate));
// echo "day=".$day."\n";
if ($day =='Sat')
$nbdate = date("Y-m-d",strtotime("+2 day", strtotime($nbdate)));
if ($day =='Sun')
$nbdate = date("Y-m-d",strtotime("+1 day", strtotime($nbdate)));
if (in_array($nbdate, $GLOBALS['marketHoliday'])) {
// echo "skip holiday";
$nbdate = date ("Y-m-d", strtotime("+1 day", strtotime($nbdate)));
}
if (in_array($nbdate, $GLOBALS['marketHoliday'])) {
echo "skip holiday";
$nbdate = date ("Y-m-d", strtotime("+1 day", strtotime($nbdate)));
}
$day = date('D', strtotime($nbdate));
// echo "day=".$day."\n";
if ($day =='Sat')
$nbdate = date("Y-m-d",strtotime("+2 day", strtotime($nbdate)));
if ($day =='Sun')
$nbdate = date("Y-m-d",strtotime("+1 day", strtotime($nbdate)));
$nbdate = date ("Y-m-d", strtotime("+1 day", strtotime($nbdate)));
return $nbdate;
}
function printHeader()
{
echo "
“;
echo “
Tick
‘; echo ‘ | price’; echo ‘ | pctChge’; echo ‘ | avgVol’; echo ‘ | Vol_Ratio’; echo ‘ | industry’; echo ‘ | marketCp’; echo ‘ | outstand’; echo ‘ | float’; echo ‘ | cScore’; echo ‘ | LTScore’; echo ‘ | taScore’; echo ‘ | ShortRatio’; echo ‘ | ShortScore’; echo ‘ | _PE_’; echo ‘ | _PEG_’; echo ‘ | _FA_’; echo ‘ | institution’; echo ‘ | insider’; echo ‘ | MFI’; echo ‘ | cash’; echo ‘ | debt’; echo ‘ | optRate’; echo ‘ | index’; echo ‘ ‘; | ‘;
---|
Tick
‘; | date’; echo ‘ | action’; echo ‘ | acquirer’; echo ‘ | dealer’; echo ‘ | pctOwn’; echo ‘ | pctChg’; echo ‘ | price’; echo ‘ | MFI’; echo ‘ | marketCap’; echo ‘ | floatM’; echo ‘ | outstandM’; echo ‘ | indutry’; echo ‘ ‘; | ‘;
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
“.$tick.” | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$tick | “.$price.” | “.$pctChange.” | “.$avgVol.” | %1.2f | “.$sector.” | “.$marketCapM.” | “.$outstandM.” | “.$floatM.” | “.$cScore.” | “.$lscore.” | “.$maScore.” | “.$shortRatio.” | “.$shortScore.” | %1.2f | “.$peg.” | “.$fa.” | “.$institution.”% | “.$insider.”% | “.$mfi.” | “.$cash.” | “.$debtPerSh.” | $optRate | “.$index.” |
Tick
‘; echo ‘ | price’; echo ‘ | ERDate’; echo ‘ | avgVol’; echo ‘ | Vol_Ratio’; echo ‘ | marketCp’; echo ‘ | outstand’; echo ‘ | float’; echo ‘ | pctChg’; echo ‘ | cScore’; echo ‘ | LTScore’; echo ‘ | estChange’; echo ‘ | estRange’; echo ‘ | closeChg’; echo ‘ | openChg’; echo ‘ | highChg’; echo ‘ | lowChg’; echo ‘ | shtRatio’; echo ‘ | shtScor’; echo ‘ | _PE_’; echo ‘ | _PEG_’; echo ‘ | _FA_’; echo ‘ | institution’; echo ‘ | insider’; echo ‘ | MFI’; echo ‘ | index’; echo ‘ | dealer’; echo ‘ | PctDLR’; echo ‘ | EstChg’; echo ‘ ‘; | ‘;|||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
$tick | “.$price.” | “.$erDate.” | “.$avgVol.” | %1.2f | “.$marketCapM.” | “.$outstandM.” | “.$floatM.” | “.$pctChange.” | “.$cScore.” | “.$lscore.” | “.$avgChg.”% | “.$erMove.”% | “.$erChange.”% | “.$openchg.”% | “.$highchg.”% | “.$lowchg.”% | “.$shortRatio.” | “.$shortScore.” | %1.2f | “.$peg.” | “.$fa.” | “.$institution.”% | “.$insider.”% | “.$mfi.” | “.$index.” | “.$topOwner.” | $topOwner | “.$pctOwned.” | “.$estChg.” | ||||||||||||||||||||||||||||||||||||||||||||||
“.$tick.” | “.date(“Ymd”,strtotime($date)).” | “.$action.” | “.$acquirer.” | %d | %1.2f | “.$pctChange.” | “.$price.” | “.$MFI.” | “.$marketCapM.” | “.$floatM.” | “.$outstandM.” | “.$industry.” |
{$field->name} | $cell “; // echo “ | $cell “; } else if ( ($cnt == $num_topOwner)) { echo “ | $cell | “;$cell | “;$cell |
---|
“;
$conn->close();
return $num;
}
function optQuery($url, $statement,$table)
{
//echo $url;
$conn=open_db();
$num = 0;
$skipped =0;
$skipped = $updated = $deleted = 0;
$day =date(“D”);
$selection_sstk=$conn->query($statement);
if (!$selection_sstk) {
echo $statement.”\n”;
trigger_error(‘Wrong SQL: ‘ . $statement . ‘ Error: ‘ . $conn->error, E_USER_ERROR);
}
else
{
$fields_num = $selection_sstk->field_count;
/*
echo “
“;
*/
echo ‘
tick | price | avgVol | All Call | All Put | weight% | ND Chg% | marketCapM | Industry | Index | winRate | $cell | “;
‘. $URL[‘tick’].” | $cell | ‘. $URL[‘price’].’ | ‘. $URL[‘avgVol’].’ | ‘. $URL[‘sumCall’].’ | ‘. $URL[‘sumPut’].’ | ‘. $URL[‘weight’].” | “;‘. $ndpctchg.’ | ‘. $URL[‘marketCapM’].’ | ‘. $URL[‘industry’].’ | ‘. $URL[‘index’].’ | ‘. $URL[‘optRate’].’ |
‘;
$conn->commit();
$conn->close();
}
function optSummaryLargeValueStk($date)
{
$conn=open_db();
$num = 0;
$skipped =0;
$skipped = $updated = $deleted = 0;
$day =date(“D”);
$statement= “SELECT tick,corp,acqVol,acqVal, acqPrice, avgVol, marketCapM,industry,indexMember, optRate FROM options INNER JOIN sstk using (tick) WHERE acqDate =’$date’ ORDER BY (tick) “;
$selection_opt=$conn->query($statement);
if (!$selection_opt) {
echo $statement.”\n”;
trigger_error(‘Wrong SQL: ‘ . $statement . ‘ Error: ‘ . $conn->error, E_USER_ERROR);
}
else
{
$ii=0;
$prevTick=NULL;
$sumCall = $sumPut = $totalVal = 0;
while ($row = $selection_opt->fetch_assoc())
{
$ii++;
// print_r( $row) ;
if ($prevTick != $row[‘tick’])
{
if ($prevTick)
{
if ($price*$avgVol)
$weight= round(($sumCall-$sumPut) *100/($price*$avgVol),2);
else
$weight = 0;
// $price = $row[‘acqPrice’];
// $avgVol = $row[‘avgVol’];
$new_array[] = array(‘tick’=>$prevTick, ‘price’ => $price, ‘avgVol’ => $avgVol,’marketCapM’=>$marketCapM,’sumCall’ => $sumCall, ‘sumPut’ => $sumPut, ‘industry’ => $industry, ‘index’ => $indexMember,’weight’ => $weight, ‘optRate’ => $optRate );
}
$sumCall = $sumPut = $totalVal = $ii = 0;
$prevTick = $row[‘tick’];
$industry = $row[‘industry’];
$indexMember=$row[‘indexMember’];
$price = $row[‘acqPrice’];
$avgVol = $row[‘avgVol’];
$marketCapM = $row[‘marketCapM’];
$optRate = $row[‘optRate’];
}
if ($row[‘corp’]==’C’ )
{
if ($row[‘acqVol’]>0)
{
$sumCall += $row[‘acqVal’];
$class = ‘#00FF00’;
}
else
{
$sumCall -= $row[‘acqVal’];
$class = ‘#FF0066’;
}
}
if ($row[‘corp’]==’P’ )
{
if ($row[‘acqVol’]>0)
{
$sumPut += $row[‘acqVal’];
$class = ‘#FF0000’;
}
else
{
$sumPut -= $row[‘acqVal’];
$class = ‘#00FF66’;
}
}
$totalVal += $row[‘acqVal’];
// echo $row[‘tick’].$row[‘acqVal’].”: Call=$sumCall PUT=$sumPut $ii\n”;
$num = $num +1;
}
if ($prevTick)
{
if ($row[‘price’]*$row[‘avgVol’] >0)
$weight= $row[‘acqVal’]*100/($row[‘price’]*$row[‘avgVol’]);
else
$weight =0;
$new_array[] = array(‘tick’=>$row[‘tick’], ‘price’ => $price, ‘avgVol’ => $avgVol,’marketCapM’=>$marketCapM, ‘sumCall’ => $sumCall, ‘sumPut’ => $sumPut, ‘industry’ => $industry, ‘index’ => $indexMember,’weight’ => $weight, ‘optRate’ => $optRate );
}
$selection_opt->free();
}
usort($new_array, function($a, $b) { return ($b[‘sumCall’]-$b[‘sumPut’]) > ($a[‘sumCall’]-$a[‘sumPut’]) ? 1 : -1;});
// print_r($new_array);
echo “
tick | price | avgVol | marketCapM | All Call | All Put | ND Chg% | Industry | Index | weight% | winRate | $cell | “;
‘. $URL[‘tick’].” | $cell | ‘. $URL[‘price’].’ | ‘. $URL[‘avgVol’].’ | ‘. $URL[‘marketCapM’].’ | ‘. $URL[‘sumCall’].’ | ‘. $URL[‘sumPut’].’ | ‘. $ndpctchg.’ | ‘. $URL[‘industry’].’ | ‘. $URL[‘index’].’ | ‘. $URL[‘weight’].” | “;‘. $URL[‘optRate’].’ |
‘;
$conn->commit();
$conn->close();
}
function optSummaryETF($date)
{
$conn=open_db();
$num = 0;
$skipped =0;
$skipped = $updated = $deleted = 0;
$day =date(“D”);
$statement= “SELECT tick,corp,acqVol,acqVal, acqPrice, avgVol, marketCapM,industry, indexMember,optRate FROM options INNER JOIN setf using (tick) WHERE acqDate =’$date’ ORDER BY (tick) “;
$selection_opt=$conn->query($statement);
if (!$selection_opt) {
echo $statement.”\n”;
trigger_error(‘Wrong SQL: ‘ . $statement . ‘ Error: ‘ . $conn->error, E_USER_ERROR);
}
else
{
$ii=0;
$prevTick=NULL;
$sumCall = $sumPut = $totalVal = 0;
while ($row = $selection_opt->fetch_assoc())
{
$ii++;
// print_r( $row) ;
if ($prevTick != $row[‘tick’])
{
if ($prevTick)
{
if (($price*$avgVol))
$weight= round(($sumCall-$sumPut) *100/($price*$avgVol),2);
else
$weight= 0;
$new_array[] = array(‘tick’=>$prevTick, ‘price’ => $price, ‘avgVol’ => $avgVol,’marketCapM’=>$marketCapM, ‘sumCall’ => $sumCall, ‘sumPut’ => $sumPut, ‘index’ => $indexMember, ‘weight’ => $weight, ‘optRate’ => $optRate );
// statement=”update tastk set call=$sumCall,put=$sumPut where date=$date and tick=$tick”;
// $result=$conn->query($statement);
// echo “$prevTick: Call=$sumCall PUT=$sumPut Weight=$weight cnt $ii\n”;
}
$sumCall = $sumPut = $totalVal = $ii = 0;
$prevTick = $row[‘tick’];
$indexMember=$row[‘indexMember’];
$price = $row[‘acqPrice’];
$avgVol = $row[‘avgVol’];
$marketCapM = $row[‘marketCapM’];
$optRate = $row[‘optRate’];
}
if ($row[‘corp’]==’C’ )
{
if ($row[‘acqVol’]>0)
{
$sumCall += $row[‘acqVal’];
$class = ‘#00FF00’;
}
else
{
$sumCall -= $row[‘acqVal’];
$class = ‘#FF0066’;
}
}
if ($row[‘corp’]==’P’ )
{
if ($row[‘acqVol’]>0)
{
$sumPut += $row[‘acqVal’];
$class = ‘#FF0000’;
}
else
{
$sumPut -= $row[‘acqVal’];
$class = ‘#00FF66’;
}
}
$totalVal += $row[‘acqVal’];
// echo $row[‘tick’].$row[‘acqVal’].”: Call=$sumCall PUT=$sumPut $ii\n”;
$num = $num +1;
}
if ($prevTick)
{
if ($row[‘price’]*$row[‘avgVol’] >0)
$weight= $row[‘acqVal’]*100/($row[‘price’]*$row[‘avgVol’]);
else
$weight =0;
$new_array[] = array(‘tick’=>$prevTick, ‘price’ => $price, ‘avgVol’ => $avgVol,’marketCapM’=>$marketCapM,’sumCall’ => $sumCall, ‘sumPut’ => $sumPut, ‘index’ => $indexMember,’weight’ => $weight, ‘optRate’ => $optRate );
}
$selection_opt->free();
}
if ($new_array != NULL)
{
usort($new_array, function($a, $b) { return ($b[‘sumCall’]-$b[‘sumPut’]) > ($a[‘sumCall’]-$a[‘sumPut’]) ? 1 : -1;});
// print_r($new_array);
echo “
tick | price | avgVol | marketCapM | All Call | All Put | ND Chg% | Index | weight% | winRate | $cell | “;
‘. $URL[‘tick’].” | $cell | ‘. $URL[‘price’].’ | ‘. $URL[‘avgVol’].’ | ‘. $URL[‘marketCapM’].’ | ‘. $URL[‘sumCall’].’ | ‘. $URL[‘sumPut’].’ | ‘. $ndpctchg.’ | ‘. $URL[‘index’].’ | ‘. $URL[‘weight’].” | “;‘. $URL[‘optRate’].’ |
‘;
}
$conn->commit();
$conn->close();
}
function tastkDOWCalcChg($tick, $sdate, $edate)
{
if ($tick)
$statement = “select tick,b.adjclose as YE2015, a.close as YE2016, if (b.close, 100*(a.close/b.adjclose-1), 0) as pctChg from tastk as a inner join tastk as b using (tick) where a.date=’$edate’ and b.date=’$sdate’ and indexMember like ‘%DIA%’ order by pctChg DESC”;
// echo $statement;
if (1)
{
$table =”Common ETF 2016″;
$url = basename(__FILE__);
queryDB($url,$statement, $table);
}
}
function tastkCalcChg($tick, $sdate, $edate)
{
if ($tick)
$statement = “select tick,b.adjclose as YE2015, a.close as YE2016, if (b.close, 100*(a.close/b.adjclose-1), 0) as pctChg from tastk as a inner join tastk as b using (tick) where a.date=’$edate’ and b.date=’$sdate’ and tick in (‘$tick’) order by pctChg DESC”;
// echo $statement;
if (1)
{
$table =”Common ETF 2016″;
$url = basename(__FILE__);
queryDB($url,$statement, $table);
}
}
function tastkEtfChg($tick, $sdate, $edate)
{
$statement = “select tick,b.adjclose as YE2014, a.close as YE2015, if (b.close, 100*(a.close/b.adjclose-1), 0) as pctChg from tastk as a inner join tastk as b using (tick) where a.date=’2015-12-31′ and b.date=’2014-12-31′ and tick in (‘$tick’) order by pctChg DESC”;
// echo $statement;
if (1)
{
$table =”Common ETF 2015″;
$url = basename(__FILE__);
queryDB($url,$statement, $table);
}
$statement = “select tick,b.adjclose as YE2015, a.close as YE2016, if (b.close, 100*(a.close/b.adjclose-1), 0) as pctChg from tastk as a inner join tastk as b using (tick) where a.date=’$edate’ and b.date=’$sdate’ and tick in (select tick from setf) order by pctChg DESC limit 10″;
if (1)
{
$table =”TOP ETF 2016”;
$url = basename(__FILE__);
queryDB($url,$statement, $table);
}
$statement = “select tick,b.adjclose as YE2015, a.close as YE2016, if (b.close, 100*(a.close/b.adjclose-1), 0) as pctChg from tastk as a inner join tastk as b using (tick) where a.date=’$edate’ and b.date=’$sdate’ and tick in (select tick from setf) order by pctChg ASC limit 10″;
// echo $statement;
if (1)
{
$table =”Bottom 10 ETF 2016”;
$url = basename(__FILE__);
queryDB($url,$statement, $table);
}
$statement = “select tick,b.adjclose as YE2014, a.close as YE2015, if (b.close, 100*(a.close/b.adjclose-1), 0) as pctChg from tastk as a inner join tastk as b using (tick) where a.date=’2015-12-31′ and b.date=’2014-12-31′ and tick in (select tick from setf) order by pctChg DESC limit 10″;
// echo $statement;
if (1)
{
$table =”Top 10 ETF 2015”;
$url = basename(__FILE__);
queryDB($url,$statement, $table);
}
$statement = “select tick,b.adjclose as YE2014, a.close as YE2015, if (b.close, 100*(a.close/b.adjclose-1), 0) as pctChg from tastk as a inner join tastk as b using (tick) where a.date=’2015-12-31′ and b.date=’2014-12-31′ and tick in (select tick from setf) order by pctChg ASC limit 10″;
// echo $statement;
if (1)
{
$table =”Bottom 10 ETF 2015”;
$url = basename(__FILE__);
queryDB($url,$statement, $table);
}
}
include (“template.html.ertrack.php”);
?>