コード例 #1
0
function dayReferance($date, $format = "d-m-Y")
{
    if (formatDate($date) == formatDate(getCurrentDateTime())) {
        return "Today";
    } elseif (formatDate($date) == formatDate(getPreviousDate(getCurrentDateTime()))) {
        return "Yesterday";
    } else {
        return formatDate($date, $format);
    }
}
コード例 #2
0
ファイル: connorsRSI_strat_5.php プロジェクト: jimmyc815/algo
function getBuyList($today_date, $crsiThreshold, $enterRange, $portfolioID, $dailyBuyList, $pctLimitBelow, $orderBy)
{
    global $simplePriceHistory;
    if (!$portfolioID) {
        $portfolioID = 1;
    }
    if (!$dailyBuyList) {
        $dailyBuyList = "crsi_daily_buy_list";
    }
    $masterRankByResult = array();
    $rankResult = array();
    $previous_trade_date = getPreviousDate($today_date);
    $query = "select a.symbol, a.trade_date, a.open, a.high, a.low, a.close, a.pct_change, ";
    $query .= "a.ATR, a.55_DAY_HIGH, a.20_DAY_HIGH, a.50_MA, a.200_MA, a.vsSpyRank, a.crsi, c.buy_price, a.adj_close ";
    #$query .= "from price_history a, $dailyBuyList c ";
    $query .= "from quotes a, {$dailyBuyList} c ";
    $query .= " where a.trade_date = '" . $today_date . "'";
    $query .= " and c.portfolio_id = " . $portfolioID;
    $query .= " and a.symbol = c.symbol ";
    #		$query .= " and a.low  < c.buy_price";
    $query .= " and a.low * (a.adj_close / a.close)  < c.buy_price";
    $query .= " and a.symbol not in (select symbol from turtle_portfolio where portfolio_id = " . $portfolioID . ") ";
    $query .= " and a.ATR > 0 ";
    #$query .= " order by a.crsi asc";
    $query .= " order by {$orderBy}";
    #print " $query <br />\n\n";
    $query = stripslashes($query);
    $result = queryMysql($query);
    $tmpArray = array();
    $tmpRankArray = array();
    $i = 0;
    while ($row = mysql_fetch_assoc($result)) {
        foreach ($row as $key => $value) {
            $tmpArray[$i][$key] = $value;
            if ($key == "symbol") {
                $tmpRankArray[$value] = $i;
            }
        }
        if ($tmpArray[$i]['buy_price'] > $tmpArray[$i]['open']) {
            $tmpArray[$i]['purchase_price'] = ($tmpArray[$i]['open'] + $tmpArray[$i]['low']) / 2;
        } elseif ($tmpArray[$i]['buy_price'] > $tmpArray[$i]['close'] && $tmpArray[$i]['buy_price'] < $tmpArray[$i]['open']) {
            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['buy_price'];
        }
        if (!$tmpArray[$i]['purchase_price']) {
            $tmpArray[$i]['purchase_price'] = ($tmpArray[$i]['high'] + $tmpArray[$i]['low']) / 2;
        }
        $i++;
    }
    $rankResult[] = $tmpRankArray;
    $combineRank = array();
    foreach ($rankResult as $rankBy => $resultArray) {
        foreach ($resultArray as $symbol => $value) {
            $combineRank[$symbol] += $value * $rankAndWeightArray[$rankBy];
        }
    }
    asort($combineRank);
    $i = 0;
    $finalRet = "";
    foreach ($combineRank as $key => $value) {
        $keyPos = $tmpRankArray[$key];
        $finalRet[$i] = $tmpArray[$keyPos];
        $i++;
    }
    return $finalRet;
}
コード例 #3
0
function getBreakoutStock6($today_date, $movingAvg, $rankAndWeightArray, $portfolioID, $dailyBuyList)
{
    global $simplePriceHistory;
    #$time_first = microtime(true);
    if (!$portfolioID) {
        $portfolioID = 1;
    }
    if (!$dailyBuyList) {
        $dailyBuyList = "turtle_daily_buy_list";
    }
    $masterRankByResult = array();
    $rankResult = array();
    //$trade_date_id = getTradeDateID("AAPL", $today_date);
    #$time_start = microtime(true);
    $previous_trade_date = getPreviousDate($today_date);
    #$time_end = microtime(true);
    #$time = $time_end - $time_start;
    #print "\t\tget previous date breakout 6 took: $time micro seconds \n";
    //foreach ($rankAndWeightArray as $rankBy => $rankWeight)
    //{
    /* types of query
    			1: pct_change
    			2: relative_avg_vol
    			3: vsSpyEMA
    			
    			query stock where today's high is greater than yesterda's moving average
    			provided that yesterday's 50 MA is greater than yesterday's 200 MA
    			use table simple_price_history to compare against full price_history with trade_date_id - 1
    			*/
    /*$query  = "select a.symbol, a.trade_date, a.open, a.high, a.low, a.close, a.pct_change, ";
    		$query .= "a.ATR, a.55_DAY_HIGH, a.20_DAY_HIGH, a.50_MA, a.200_MA, a.vsSpyRank ";
    		$query .= "from price_history a, price_history b ";
    		$query .= " where a.trade_date = '".$today_date."'";
    		$query .= " and b.trade_date = '".$previous_trade_date."'";			
    		$query .= " and a.symbol = b.symbol ";
    		$query .= " and a.high > b.".$movingAvg;
    		$query .= " and a.symbol not in (select symbol from turtle_portfolio where portfolio_id = ".$portfolioID.") ";
    		$query .= " and b.vsSpyRank < 50 ";
    		$query .= " order by a.vsSpyRank desc";
    		$query = stripslashes($query);
    		*/
    $query = "select a.symbol, a.trade_date, a.open, a.high, a.low, a.close, a.pct_change, ";
    $query .= "a.ATR, a.55_DAY_HIGH, a.20_DAY_HIGH, a.50_MA, a.200_MA, a.vsSpyRank ";
    $query .= "from price_history a, {$simplePriceHistory} b ";
    $query .= " where a.trade_date = '" . $today_date . "'";
    $query .= " and b.trade_date = '" . $previous_trade_date . "'";
    $query .= " and a.symbol = b.symbol ";
    $query .= " and a.high > b." . $movingAvg;
    $query .= " and a.symbol not in (select symbol from turtle_portfolio where portfolio_id = " . $portfolioID . ") ";
    $query .= " and b.vsSpyRank < 75 ";
    $query .= " order by a.vsSpyRank desc";
    #print "$query ".date("h:i:sa")."\n";
    #$time_start = microtime(true);
    $query = stripslashes($query);
    $result = queryMysql($query);
    #$time_end = microtime(true);
    #$time = $time_end - $time_start;
    #print "\t\t\tget breakout 6 took: $time micro seconds \n";
    #print "after execution \n".date("h:i:sa")."\n";
    $tmpArray = array();
    $tmpRankArray = array();
    $i = 0;
    #$time_start = microtime(true);
    while ($row = mysql_fetch_assoc($result)) {
        foreach ($row as $key => $value) {
            $tmpArray[$i][$key] = $value;
            if ($key == "symbol") {
                $tmpRankArray[$value] = $i;
            }
        }
        /*	            if ($tmpArray[$i]['buy_price'] > $tmpArray[$i]['low']) {
        		            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        	            } elseif ($tmpArray[$i]['buy_price'] < $tmpArray[$i]['open']) {
        		            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        	            } elseif ($tmpArray[$i]['buy_price'] < $tmpArray[$i]['low']) {
        		            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        	            }
        */
        /*		            if ($tmpArray[$i]['$movingAvg'] > $tmpArray[$i]['low']) {
        			            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        		            } elseif ($tmpArray[$i]['$movingAvg'] < $tmpArray[$i]['open']) {
        			            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        		            } elseif ($tmpArray[$i]['$movingAvg'] < $tmpArray[$i]['low']) {
        			            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        		            }
        */
        if ($tmpArray[$i][$movingAvg] > $tmpArray[$i]['low']) {
            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        } elseif ($tmpArray[$i][$movingAvg] < $tmpArray[$i]['open']) {
            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        } elseif ($tmpArray[$i][$movingAvg] < $tmpArray[$i]['low']) {
            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        }
        if (!$tmpArray[$i]['purchase_price']) {
            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        }
        $i++;
    }
    #$time_end = microtime(true);
    #$time = $time_end - $time_start;
    #print "\t\t\twhile loop inside breakout 6 took: $time micro seconds \n";
    //print "rank by: $rankBy \n";
    //	        $masterRankByResult[$rankBy] = $tmpArray;
    $rankResult[] = $tmpRankArray;
    //}
    $combineRank = array();
    #$time_start = microtime(true);
    foreach ($rankResult as $rankBy => $resultArray) {
        foreach ($resultArray as $symbol => $value) {
            $combineRank[$symbol] += $value * $rankAndWeightArray[$rankBy];
        }
    }
    asort($combineRank);
    $i = 0;
    $finalRet = "";
    foreach ($combineRank as $key => $value) {
        $keyPos = $tmpRankArray[$key];
        $finalRet[$i] = $tmpArray[$keyPos];
        $i++;
    }
    #$time_end = microtime(true);
    #$time = $time_end - $time_start;
    #print "\t\t\for each nside breakout 6 took: $time micro seconds \n";
    //populate daily buy list
    //populateDailyBuyList ($today_date, $movingAvg, $rankAndWeightArray);
    #$time_duration = $time_end - $time_first;
    #print"\t\t\toverall inside braekout6 : $time_duration \n";
    return $finalRet;
}
コード例 #4
0
function live_get_portfolio_risk($trade_date, $portfolioID)
{
    global $quote_table;
    global $liveportfolio;
    $previous_date = getPreviousDate($trade_date);
    $p_value = live_get_portfolio_value($trade_date, $portfolioID);
    $tmp_sql = "SELECT sum(b.ATR * a.shares) from {$liveportfolio} a, {$quote_table} b \n\t\t\t\tWHERE a.portfolio_id = {$portfolioID} \n\t\t\t\tAND a.symbol=b.symbol\n\t\t\t\tAND b.trade_date = '{$previous_date}'\n\t\t\t\tAND a.symbol != 'CASH'";
    $tmp_result = queryMysql($tmp_sql);
    while ($tmp_data = mysql_fetch_row($tmp_result)) {
        $r_value = $tmp_data[0];
    }
    $current_risk = $r_value / $p_value * 100;
    return $current_risk;
}