ID)
{
$message = ” 登陆用户可用此项功能, 请注册用户并登陆 “;
echo ““;
exit;
}
$tickName = $etfName =$expDate=NULL;
$conditionExp =$conditionETF=$conditionTick=$orderby=NULL;
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
if (isset($_POST[‘tickName’]))
$tickName = test_input($_POST[‘tickName’]);
if (isset($_POST[‘etfName’]))
$etfName= test_input($_POST[‘etfName’]);
if (isset($_POST[‘expDate’]))
$expDate= test_input($_POST[‘expDate’]);
if (isset($_POST[‘orderby’]))
{
$orderby= test_input($_POST[‘orderby’]);
if ($orderby)
$orderby = $orderby.” DESC”;
}
}
else
{
if (isset($_GET[‘tickName’]))
$tickName = test_input($_GET[‘tickName’]);
if (isset($_GET[‘etfName’]))
$etfName= test_input($_GET[‘etfName’]);
if (isset($_GET[‘expDate’]))
$expDate= test_input($_GET[‘expDate’]);
if (isset($_GET[‘orderby’]))
{
$orderby= test_input($_GET[‘orderby’]);
}
}
if ($orderby)
{
if ($orderby == ‘acqVal’ OR $orderby == ‘acqOPrice’)
$orderby = $orderby.” desc”;
else
{
$myrand = rand ();
if ($myrand % 2 ==1)
$orderby = $orderby.” desc”;
}
}
else
$orderby = ” abs(acqVol)*lOPrice DESC “;
//echo $tickName;
$tickName = preg_replace(“/[\s,]+/”,”,”,$tickName);
$url = basename(__FILE__);
if (NULL != $tickName)
{
$conditionTick = “tick=’$tickName’ AND “;
// optGetGreeks($tickName);
}
else
if (NULL != $etfName)
$conditionETF =” (indexMember LIKE ‘$etfName’ OR tick=’$etfName’ ) AND “;
if (NULL != $expDate)
{
$conditionTick = $conditionTick.”expDate=’$expDate’ AND “;
$conditionETF = $conditionETF.”expDate=’$expDate’ AND “;
}
echo date(“Y-m-d”).”\n”;
if ($etfName)
{
$url = $url.”?etfName=”.$etfName;
if (NULL != $expDate)
$url = $url.”&expDate=”.$expDate;
$statement = “SELECT count(date), avg(netValue), avg(CallVal) as avgCall, avg(PutVal) as avgPut,avg(ndpctchg), covariance(netValue, ndpctchg)/(STDDEV(netValue)*STDDEV(ndpctchg)) as Correlation from optstat where tick=’$etfName’ “;
// optQuery($url, $statement, “optionETFStat”);
$statement= “SELECT count(tick) as cnt, avg(netPrem) as avgNet, avg(NetPremCall) as avgCall, avg(NetPremPut) as avgPut,avg(ndpctchg),covariance(netPrem, ndpctchg)/(STDDEV(netPrem)*STDDEV(ndpctchg)) as Correlation FROM lifan.optSummary INNER JOIN setf USING (tick) WHERE tick=’$etfName’ “;
optQuery($url, $statement, “optionETFSummt”);
if ($orderby)
$statement= “SELECT tick,acqDate,expDate,corp, strike,acqVal,acqVol,acqOI ,acqOPrice,bidPrice,askPrice,acqPrice,lPrice as curPrice, pnl as stockgain, lOPrice,oPnL as optionGain, bullbear,industry,indexMember FROM options INNER JOIN setf USING (tick) WHERE “.$conditionETF.” expDate>=’$today’ AND corp!=’N’ ORDER BY “.$orderby;
// optQuery($url, $statement, “optionTickOpen”);
// echo “Back test result: \n”;
$statement= “SELECT tick,acqDate,expDate,corp, strike,acqVal,acqVol,acqOI,acqOPrice,bidPrice,askPrice, acqPrice ,lPrice as ExpDayPrice, pnl as stockgain,lOPrice, oPnL as optionGain, bullbear FROM options INNER JOIN setf USING (tick) WHERE tick=’$etfName’ AND expDate<='$today' AND corp!='N' ORDER BY ".$orderby;
// optQuery($url, $statement, "optionTickExp");
$statement= "SELECT tick,Date,callVal,putVal,netValue,weight, netRatio , score, ndpctChg,weekday(date)+1 as weekday FROM optstat WHERE tick='$etfName' and date >=’2016-11-21′ ORDER BY (date) DESC limit 30 “;
// optQuery($url, $statement, “optionStat”);
$statement= “SELECT tick,Date,netPremCall,netPremPut,netPrem,weight, netRatio , score, ndpctChg,weekday(date)+1 as weekday FROM lifan.optSummary WHERE tick=’$etfName’ and date >=’2016-11-21′ ORDER BY (date) DESC limit 30 “;
// optQuery($url, $statement, “optionStat”);
}
else
{
$url = $url.”?tickName=”.$tickName;
if (NULL != $expDate)
$url = $url.”&expDate=”.$expDate;
// $statement= “SELECT options.*,sstk.industry as industry FROM options INNER JOIN sstk using (tick) WHERE FIND_IN_SET(options.tick,’$tickName’) ORDER BY (acqDate) DESC “;
//echo “[“.$conditionTick.”]\n”;
$statement = “SELECT count(date), avg(netValue), avg(CallVal) as avgCall, avg(PutVal) as avgPut,avg(ndpctchg), covariance(netValue, ndpctchg)/(STDDEV(netValue)*STDDEV(ndpctchg)) as Correlation from optstat where tick=’$tickName’ “;
// optQuery($url, $statement, “optionTickStat”);
$statement= “SELECT count(tick) as cnt, avg(netPrem) as avgNet, avg(NetPremCall) as avgCall, avg(NetPremPut) as avgPut,avg(ndpctchg),covariance(netPrem, ndpctchg)/(STDDEV(netPrem)*STDDEV(ndpctchg)) as Correlation FROM lifan.optSummary INNER JOIN sstk USING (tick) WHERE tick=’$tickName’ “;
optQuery($url, $statement, “optionTickSumm”);
$statement= “SELECT tick,acqDate,acqTime,expDate,corp, strike,acqVal,acqVol,acqOI ,lastOI,acqOPrice,bidPrice,askPrice,acqPrice,lPrice as curPrice, pnl as stockgain, lOPrice,oPnL as optionGain, bullbear,industry,indexMember FROM options INNER JOIN sstk USING (tick) WHERE “.$conditionTick.” expDate>=’$today’ AND corp!=’N’ AND bullbear not like ‘Spread’ ORDER BY “.$orderby;
// echo “$statement \n”;
optQuery($url, $statement, “optionTickOpen”);
// echo “Back test result: \n”;
$statement= “SELECT tick,acqDate,acqTime,expDate,corp, strike,acqVal,acqVol,acqOI,acqOPrice,bidPrice,askPrice,acqPrice ,lPrice as ExpDayPrice, pnl as stockgain, lOPrice, bullbear,oPnL as optionGain FROM options INNER JOIN sstk USING (tick) WHERE tick=’$tickName’ AND expDate<='$today' AND corp!='N' ORDER BY ".$orderby;
// optQuery($url, $statement, "optionTickExp");
$statement= "SELECT tick,Date,callVal,putVal,netValue,weight, netRatio , score, ndpctChg,weekday(date)+1 as weekday FROM optstat WHERE tick='$tickName' and date >=’2016-11-21′ ORDER BY (date) DESC limit 30 “;
// optQuery($url, $statement, “optionStat”);
}
?>