public static function calcRange($start, $end, $n)
 {
     $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_' . $n . '_Good.Table.txt';
     $limiter = 2;
     $stockList = Refer::getStock();
     $stockData = array();
     foreach ($stockList as $stkL) {
         //if (--$limiter < 0 ) break;
         $stkT = array('name' => '', 'code' => '', 'MaxRange' => 0, 'DayNum' => 0);
         $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>';
         $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>';
         $dd = new DayData($stkL['code'], 'before');
         if (!$dd->prepareData()) {
             continue;
         }
         $day = $dd->getDayPeriod($start, $end, $n - 1);
         //var_dump($day);
         if (!$day) {
             continue;
         }
         $MaxRange = -2;
         for ($i = 0; $i < $n / 2; $i++) {
             $daySlice = array_slice($day, $i, $n);
             if (!$daySlice) {
                 continue;
             }
             $dMax = LogicOperation::highValue($daySlice, 'close');
             $dMin = $daySlice[0]['close'];
             $dR = ceil(($dMax - $dMin) / $dMin * 100) / 100;
             $MaxRange = $MaxRange < $dR ? $dR : $MaxRange;
         }
         $stkT['MaxRange'] = $MaxRange;
         $stkT['DayNum'] = sizeof($day);
         $tdd = new ThsDoctorData($stkL['code']);
         $t = $tdd->prepareData() ? $tdd->getDayPeriod($start, $end) : array();
         //message_score
         $stkT['message_score_max'] = LogicOperation::highValue($t, 'message_score');
         $stkT['message_score_min'] = LogicOperation::lowValue($t, 'message_score');
         $stkT['message_score_dis'] = $stkT['message_score_max'] - $stkT['message_score_min'];
         //basic_score
         $stkT['basic_score_max'] = LogicOperation::highValue($t, 'basic_score');
         $stkT['basic_score_min'] = LogicOperation::lowValue($t, 'basic_score');
         //total_score
         $stkT['total_score_max'] = LogicOperation::highValue($t, 'total_score');
         $stkT['total_score_min'] = LogicOperation::lowValue($t, 'total_score');
         //var_dump($stkT);
         $stockData[] = $stkT;
     }
     parent::putTable($resultFile, $stockData);
 }
 public static function testDayData()
 {
     $dd = new DayData('sh600010', 'normal');
     if ($dd->prepareData()) {
         //var_dump($dd->getStockData());
         //var_dump($dd->getDaySolo('2015-11-06')['time']);
         //var_dump($dd->getLastSolo(0)['time']);
         var_dump($dd->getDayPeriod('2015-10-01', '2015-11-06', 7));
         //var_dump($dd->getDayPeriod('2015-11-01', true, 7));
         //var_dump($dd->getLastPeriod(true, true));
         //var_dump($dd->getLastPeriod(5, true));
         //var_dump($dd->getLastPeriod(7, true, 6));
     }
 }
Example #3
0
 public static function show()
 {
     parent::show();
     $stockInfo = array();
     $stockInfo["code"] = $_GET["code"];
     $i = Refer::searchCode($stockInfo["code"]);
     if (!$i) {
         exit(0);
     }
     $stockInfo["name"] = $i['name'];
     $stockInfo["spell"] = $i['spell'];
     $stockInfo["period"] = null;
     /*
      *
     $stockInfo["period"] = array('start'=>strtotime("Thu May 28 00:00:00 +0800 2015")*1000,
         'end'=>strtotime("Mon Dec 23 00:00:00 +0800 2015")*1000);
     */
     $stockInfo["right"] = "before";
     $gd = new GbbqData($stockInfo["code"]);
     $gbbq = $gd->getGbbqLabel();
     $stockInfo['gbbq'] = $gbbq;
     $dd = new DdeData($stockInfo["code"]);
     $dde = $dd->getDdeData();
     $stockInfo['dde'] = $dde;
     $tdd = new ThsDoctorData($stockInfo["code"]);
     $ths = $tdd->getThsDoctorData();
     $stockInfo['ths'] = $ths;
     $ld = new LhbData($stockInfo["code"]);
     $lhb = $ld->getLhbData();
     $stockInfo['lhb'] = $lhb;
     $rd = new RateData($stockInfo["code"]);
     $rate = RateData::filterBuy($rd->getRateData());
     $stockInfo['rate'] = $rate;
     $stockInfo['day'] = array();
     $typeRight = array("normal", "before", "after");
     foreach ($typeRight as $aTypeRight) {
         $dd = new DayData($stockInfo["code"], $aTypeRight);
         if ($dd->prepareData()) {
             $stockInfo['day'][$aTypeRight] = $dd->getStockData();
         } else {
             $stockInfo['day'][$aTypeRight] = null;
         }
     }
     self::setTitle($stockInfo['name'] . '(' . $stockInfo['code'] . ') - Stock -- ForeShadow (Alpha)');
     self::$smarty->assign('historyUrl', Url::getBasePhp('History'));
     self::$smarty->assign('favoriteUrl', Url::getBasePhp('Favorite'));
     self::$smarty->assign('rawData', json_encode($stockInfo));
     self::$smarty->display('Chart.tpl');
 }
Example #4
0
 public static function calcV2P($start, $end)
 {
     $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_Vol2Price.Table.txt';
     $limiter = 200;
     $stockList = Refer::getStock();
     $stockData = array();
     foreach ($stockList as $stkL) {
         //if (--$limiter < 0 ) break;
         $stkT = array();
         $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>';
         $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>';
         $dd = new DayData($stkL['code'], 'before');
         if (!$dd->prepareData()) {
             continue;
         }
         $day = $dd->getDayPeriod($start, $end, 3);
         if (!$day) {
             continue;
         }
         //var_dump($day);
         $s_day = 0;
         $s_V2P = 0;
         for ($i = 2; $i < count($day); $i++) {
             //处理当日涨跌停
             $is_zt = ($day[$i]["high"] - $day[$i - 1]["close"]) / $day[$i - 1]["close"];
             $is_dt = ($day[$i - 1]["close"] - $day[$i]["low"]) / $day[$i - 1]["close"];
             $valid_vol = $day[$i]["volume"] / $day[$i - 1]["volume"];
             //涨跌停 并且 量小于0.3 不参与计算
             if (($is_zt > 1.09 || $is_dt < 0.9) && $valid_vol < 0.3) {
                 continue;
             }
             //处理前日涨跌停
             $is_zt = ($day[$i - 1]["high"] - $day[$i - 2]["close"]) / $day[$i - 2]["close"];
             $is_dt = ($day[$i - 2]["close"] - $day[$i - 1]["low"]) / $day[$i - 2]["close"];
             $valid_vol = $day[$i - 1]["volume"] / $day[$i - 2]["volume"];
             //涨跌停 并且 量小于0.3 不参与计算
             if (($is_zt > 1.09 || $is_dt < 0.9) && $valid_vol < 0.3) {
                 continue;
             }
             //处理量太小不值得计算
             $k1 = ($day[$i]["volume"] - $day[$i - 1]["volume"]) / $day[$i - 1]["volume"] * 100;
             $k2 = ($day[$i]["volume"] - $day[$i - 2]["volume"]) / $day[$i - 2]["volume"] * 100;
             if (abs($k1) < 20 && abs($k2) < 20) {
                 continue;
             }
             //计算V2P公式
             //计算量相关
             $q2 = ($day[$i]["volume"] - $day[$i - 1]["volume"]) / $day[$i - 1]["volume"] * 100;
             if ($q2 < -100) {
                 $q2 = -100;
             }
             if ($q2 > 100) {
                 $q2 = 100;
             }
             //计算价格相关
             $chg = $day[$i]["chg"] * 100;
             $q1 = $chg;
             if ($chg > 60) {
                 $q1 = 16;
             }
             if ($chg <= 60 && $chg > 30) {
                 $q1 = ($chg - 30) / 15 + 13;
             }
             if ($chg <= 30 && $chg > 10) {
                 $q1 = ($chg - 10) / 7 + 10;
             }
             if ($chg < -60) {
                 $q1 = -16;
             }
             if ($chg >= -60 && $chg < -30) {
                 $q1 = ($chg + 30) / 15 - 13;
             }
             if ($chg >= -30 && $chg < -10) {
                 $q1 = ($chg + 10) / 7 - 10;
             }
             $q1 = $q1 > 0 ? ceil($q1 + 100) : ceil($q1 - 100);
             $V2P = $q1 * $q2;
             if ($chg <= 10 && $chg >= -10) {
                 $V2P = abs(110 * $q2);
             }
             // 统计
             $s_day++;
             $s_V2P += $V2P;
         }
         $stkT['Vol2Price'] = $s_day ? ceil($s_V2P / $s_day) : 0;
         $stkT['ValidDayNum'] = $s_day;
         $stkT['TotalDayNum'] = count($day);
         $stockData[] = $stkT;
     }
     parent::putTable($resultFile, $stockData);
 }
Example #5
0
 public static function updateLhb()
 {
     //日志文件
     self::$log = new Log(LOG_PATH, __FILE__);
     //临时文件
     self::$tmp = new Tmp(TMP_PATH);
     self::$tmp->addTmp('lhb.duty.time', false);
     self::$log->debugLog("Begin Update Lhb");
     echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body>';
     //得到上次更新时间
     $lastTime = self::$tmp->getTmpContent('lhb.duty.time');
     //校验上次更新时间
     $pattern = "/[0-9]{4}-[0-9]{2}-[0-9]{2}/";
     preg_match($pattern, $lastTime, $k);
     $lastTime = $k[0];
     $thisTime = $lastTime;
     if ($lastTime) {
         //echo $lastTime . '<br />';
         $szzs = Refer::getSH();
         $dd = new DayData($szzs['code']);
         if ($dd->prepareData()) {
             $ks = $dd->getDayPeriod($lastTime, true);
             $list = array();
             foreach ($ks as $k) {
                 $cTime = $k['time'];
                 if ($cTime > $lastTime) {
                     //echo $cTime. '<br />';
                     $url = "http://data.eastmoney.com/stock/lhb/" . $cTime . ".html";
                     self::$log->debugLog('Get Url', $url);
                     $html = LhbKeeper::fetchSinglePage($url);
                     self::$log->debugLog("Fetch Url Page Success");
                     $updata = LhbKeeper::parseLhbHtml($html, $cTime);
                     if ($updata) {
                         $list = array_merge($list, $updata);
                     }
                     $thisTime = $cTime;
                 }
             }
             //var_dump($list);
             if ($list) {
                 foreach ($list as $new) {
                     $ld = new LhbData($new[0]);
                     $data = $ld->getLhbData();
                     if (!$data) {
                         LhbKeeper::addLhb($ld->getDataFile(), array($new[1]));
                         self::$log->noticeLog("Update", $new[0], $new[1]['time'], $new[1]['reason'], "Success");
                         continue;
                     }
                     $t = end($data)['time'];
                     //echo $new[1]['time']. '>'. $t. '<br />';
                     if ($new[1]['time'] > $t) {
                         LhbKeeper::addLhb($ld->getDataFile(), array($new[1]));
                         self::$log->noticeLog("Update", $new[0], $new[1]['time'], $new[1]['reason'], "Success");
                     }
                 }
             } else {
                 self::$log->errorLog("Parse Lhb Failed");
             }
             self::$tmp->newTmpFile('lhb.duty.time');
             self::$tmp->putTmpContent('lhb.duty.time', $thisTime);
             self::$log->debugLog("Finish Update Lhb");
         } else {
             self::$log->errorLog("Get Time List Failed");
         }
     } else {
         self::$log->errorLog("Get LastTime Failed");
     }
 }