即将报ER的公司!

(.*) price

#’, $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 “

“;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;

}

function printHeaderISC()
{
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 ‘
“;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;

}
function printTable($tick,$price,$pctChange,$avgVol,$volRatio, $cScore, $lscore, $sector,$marketCapM,$outstandM,$floatM,$shortRatio,$shortScore,$pe, $peg, $fa,$institution,$insider,$mfi,$maScore,$cash,$debt,$optRate,$index )
{
$maScore = $maScore/2;

// echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
printf( “

“,$volRatio);
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
printf( “

“,$pe);
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
if ($marketCapM!=0)
$debtPerSh = round( $debt * $price /$marketCapM, 2);
else
$debtPerSh =0;
echo “

“;
echo “

“;
echo “

“;

}

function printERHeader()
{

echo “

“;

echo “

Tick

‘;
echo ‘

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.”
“;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;
}

function printTableER($tick,$price,$erDate,$avgVol,$volRatio,$pctChange, $cScore, $lscore, $sector,$marketCapM,$outstandM,$floatM,$shortRatio,$shortScore,$pe, $peg, $fa,$institution,$insider,$mfi,$erMove,$avgChg,$erChange,$openchg,$highchg,$lowchg,$index,$topOwner,$pctOwned,$estChg )
{

echo “

“;
echo “

“;
echo “

“;
echo “

“;
printf( “

“,$volRatio);
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
printf( “

“,$pe);
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
// echo “

“;
echo “

“;
echo “

“;
echo “

“;

}
function printTableISC($tick,$date,$action,$acquirer,$dealer,$pctOwned, $pctChange, $price, $MFI,$marketCapM,$floatM,$outstandM,$industry)
{

echo “

“;
echo “

“;
echo “

“;
echo “

“;
printf( “

“,$dealer);
printf( “

“,$pctOwned);
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;
}

/*
$date = “2012-10-26″;
echo $date.” next day=”.getNextTradingdate($date);
echo $date.” previous day=”.getLastClosedTradingdate($date);
*/

function queryDB($url, $statement, $table)
{
$conn=open_db();
$num = 0;
$skipped = $updated = $deleted = 0;
$selection_sstk=$conn->query($statement);
if (!$selection_sstk) {
echo $statement.”\n”;
trigger_error(‘Wrong SQL: ‘ . $statement . ‘ Error: ‘ . $conn->error, E_USER_ERROR);
}
else
{
if ( 0 == $conn->affected_rows)
{
$conn->close();
return 0;
}

$fields_num = $selection_sstk->field_count;

echo ‘

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.”
‘;//
// echo “

“;
// printing table headers
$num_tick = $num_industry=$num_topOwner=$num_optRate=0;
for($i=0; $i<$fields_num; $i++) { $field = $selection_sstk->fetch_field();
// echo “

“;
echo “

“;
}
else
if ( ($cnt == $num_optRate))
{
echo “

“;
}
else
echo “

“;

}

echo “

\n”;
}
$num = $num +1;
}
if ($num ==0 )
{
$conn->close();
return 0;
}
$selection_sstk->free();
}
echo “

Table: {$table}

“;
echo “

Total “.$num.” records!

“;
echo “

{$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 ‘

‘;//
// echo ‘

‘;//
// printing table headers
$num_stockgain =$num_optionGain =$num_bullbear=$num_acqVol=0;
for($i=0; $i<$fields_num; $i++) { $field = $selection_sstk->fetch_field();
echo “

“;
// echo “

“;
$cnt=0;
// $row is array… foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
{
$cnt++;
// if ($table == ‘ERbyDate’ AND ($cnt ==1))
if ( ($cnt ==1))
{
echo “

“;
}
else
if ($cnt ==$num_acqVol)
{
if ($row[‘corp’]==’P’ ||$row[‘corp’]==’C’ )
echo “

“;
else
echo “

“;

}
else
if ( $cnt == $num_stockgain )
{
if ($row[‘stockgain’] !=0 )
echo “

“;
else
echo “

“;
}
else
if ( $cnt == $num_optionGain )
{
if ($row[‘optionGain’] !=0 )
echo “

“;
else
echo “

“;
}
else
/*
if ($cnt ==$num_bullbear)
{
echo “

“;
}
else */
echo “

“;

}

echo “

\n”;
}
$num = $num +1;
}
$selection_sstk->free();
}

if ($table ==’optionTickExp’)
{
if ($num >0)
{
$ratio = round( $numGain*100/$num,2) ;
$avgVal = round($totalVal/$num,2) ;
}
else
$ratio = $avgVal =0;
if ($totalVal >0)
$gainRatio = round($totalGain/$totalVal*100,2) ;
else
$gainRatio =0;
echo “

Total “.$num.” records: Winning ratio = $ratio % Total Gain = $gainRatio%; AvgValue= $avgVal

“;

}
else
{
if ($totalVal >0)
$avgVal = round($totalVal/$num,2) ;
else
$avgVal = 0;
if ($sumCall != 0 )
$ratio=round( $sumPutNow*100/$sumCall, 2);
else
$ratio =0;
if ($sumCallNow != 0 )
$ratioNow=round( $sumPutNow*100/$sumCallNow, 2);
else
$ratioNow =0;
$Net= $sumCall-$sumPut;
$NetNow= $sumCallNow-$sumPutNow;
echo “

Total Original “.$num.” records: net direction Call = $sumCall Put= $sumPut net= $Net; P/C ratio = $ratio %; AvgValue= $avgVal

“;
echo “

Total Current “.$num.” records: net direction CallNow = $sumCallNow PutNow= $sumPutNow netNow= $NetNow; P/C ratio = $ratioNow %

“;
}

echo “

1000000)
{
echo “

$cell $cell $cell $cell $cell $cell $cell Buy Sell $cell

“;

$conn->commit();
$conn->close();
}

/*
update optstat inner join sstk using (tick) set weight=round( (netValue) *100/(price*avgVol),2) where Date=’2016-07-13′;
*/
function optSummary($date)
{
$conn=open_db();
$num = 0;
$skipped =0;
$skipped = $updated = $deleted = 0;
// $new_array[] =NULL;
$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, ‘sumCall’ => $sumCall, ‘sumPut’ => $sumPut, ‘weight’ => $weight, ‘marketCapM’=>$marketCapM, ‘industry’ => $industry, ‘index’ => $indexMember, ‘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’];
$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[‘acqPrice’]*$row[‘avgVol’] >0)
$weight= $row[‘acqVal’]*100/($row[‘acqPrice’]*$row[‘avgVol’]);
else
$weight =0;
$new_array[] = array(‘tick’=>$prevTick,’price’ => $price, ‘avgVol’ => $avgVol, ‘sumCall’ => $sumCall, ‘sumPut’ => $sumPut, ‘weight’ => $weight, ‘marketCapM’=>$marketCapM, ‘industry’ => $industry, ‘index’ => $indexMember, ‘optRate’ => $optRate );
}
$selection_opt->free();
}
if ($new_array == NULL)
{
$conn->close();
return;

}
usort($new_array, function($a, $b) { return $b[‘weight’] > $a[‘weight’] ? 1 : -1;});
// print_r($new_array);

echo “

“;
echo “

“;
// echo “

“;

foreach ($new_array as $URL){
if ($URL[‘weight’]>1 or $URL[‘weight’]<-1) { if ($URL['weight']>0)
$OptionDirection= ‘#00FF66’;
else
$OptionDirection= ‘#FF0066’;
getHistNdPctChg($URL[‘tick’], $date, $ndpctchg);
$cell=$URL[‘tick’];
echo “

“;
// echo’

“;
echo “

“;

echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo ‘

“;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
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 “

“;
echo “

“;
// echo “

“;

foreach ($new_array as $URL){
if (($URL[‘sumCall’]- $URL[‘sumPut’] )>=1000000 OR ($URL[‘sumCall’]- $URL[‘sumPut’] )<= -1000000 ) { if (($URL['sumCall']- $URL['sumPut'] )>0)
$OptionDirection= ‘#00FF66’;
else
$OptionDirection= ‘#FF0066’;
getHistNdPctChg($URL[‘tick’], $date, $ndpctchg);
$cell=$URL[‘tick’];
echo “

“;
// echo’

“;
echo “

“;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo ‘

“;
echo’

‘;
}
}
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 “

“;
echo “

“;
// echo “

“;

foreach ($new_array as $URL){
if (($URL[‘sumCall’]- $URL[‘sumPut’] )>100000 OR ($URL[‘sumCall’]- $URL[‘sumPut’] )< -100000 ) { if (($URL['sumCall']- $URL['sumPut'] )>0)
$OptionDirection= ‘#00FF66’;
else
$OptionDirection= ‘#FF0066’;
getHistNdPctChg($URL[‘tick’], $date, $ndpctchg);
$cell=$URL[‘tick’];
echo “

“;
// echo’

“;
echo “

“;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo’

‘;
echo ‘

“;
echo’

‘;
}
}
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”);
?>

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

19 − 1 =

季报追踪网 ERTrack.com
滚动至顶部