当前位置: 首页>>代码示例>>PHP>>正文


PHP populateDailyBuyList函数代码示例

本文整理汇总了PHP中populateDailyBuyList函数的典型用法代码示例。如果您正苦于以下问题:PHP populateDailyBuyList函数的具体用法?PHP populateDailyBuyList怎么用?PHP populateDailyBuyList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了populateDailyBuyList函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: turtle_portfolio_buy


//.........这里部分代码省略.........
    //		echo json_decode($breakOutStockArray);
    // set how many breakout stocks to buy
    //$len_array = count($breakOutStockArray);
    $len_array = count($breakOutStockArray);
    $risk_factor = 1 / $max_num_holdings;
    $portfolio_value = 0;
    $current_pos = 0;
    $next_buy_point = 100000;
    $stop_loss = 0;
    $num_shares = 0;
    $current_N = 0;
    $risk_value = 0;
    $purchase_value = 0;
    $sim_start_day = 55;
    $pyramid_mode = 0;
    $stop_loss = 0;
    //		$ADX_filter = "Off";
    $current_trade_date_id = 0;
    $workingArray = $breakOutStockArray;
    $adxArray = "";
    $adxCount = 1;
    // check if ADX check if turned on
    if ($ADX_filter == "On") {
        for ($x = 1; $x < $len_array; $x++) {
            $current_trade_date_id = getTradeDateID($workingArray[$x]['symbol'], $date);
            $returnADX = calculate_ADX($workingArray[$x]['symbol'], $current_trade_date_id, 14);
            if ($returnADX["plusDI14"] > $returnADX["negDI14"] && $returnADX["ADX"] < 30) {
                //if ($returnADX["plusDI14"] < $returnADX["negDI14"])  {
                //array_delete ($breakOutStockArray[$x]);
                //unset ($breakOutStockArray[$x]);
                if ($returnADX["changeADX"] > 5) {
                    $adxArray[$adxCount] = $workingArray[$x];
                    $adxCount++;
                }
            }
        }
        $breakOutStockArray = $adxArray;
    }
    $len_array = count($breakOutStockArray);
    for ($x = 1; $x < $len_array; $x++) {
        ### get portfolio value
        $portfolio_value = get_historical_turtle_portfolio_value($date);
        ### get current available cash
        $query = "select shares from turtle_portfolio where portfolio_id = 1 and symbol = 'CASH'";
        $result = queryMysql($query);
        while ($data = mysql_fetch_row($result)) {
            $cash = $data[0];
        }
        $risk_value = $portfolio_value * $risk_factor / 100;
        $current_N = $breakOutStockArray[$x]['ATR'];
        if ($current_N > 0) {
            $num_shares = floor($risk_value / (2 * $current_N));
        }
        /*				$purchase_value = $num_shares * $breakOutStockArray[$x][$breakOutSignal];
        				$stop_loss = $breakOutStockArray[$x][$breakOutSignal] - (2*$current_N);
        				$stop_buy = $breakOutStockArray[$x][$breakOutSignal] + $current_N;
        */
        $purchase_value = $num_shares * $breakOutStockArray[$x]['purchase_price'];
        $stop_loss = $breakOutStockArray[$x]['purchase_price'] - 2 * $current_N;
        $stop_buy = $breakOutStockArray[$x]['purchase_price'] + $current_N;
        $current_risk = get_current_risk();
        if ($cash > $purchase_value && $current_risk < $max_risk) {
            $cash = $cash - $purchase_value;
            $risk_dollar = $num_shares * (2 * $current_N);
            $risk_pct = $risk_dollar / $portfolio_value * 100;
            // insert into turtle_portfolio
            $my_sql = "insert into turtle_portfolio (portfolio_id, symbol, last_price, shares, cost_basis, stop_loss, stop_buy, risk, risk_pct) ";
            $my_sql .= "values (1, '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= $breakOutStockArray[$x]['close'] . ", ";
            $my_sql .= $num_shares . ", ";
            //					$my_sql .= $breakOutStockArray[$x][$breakOutSignal].", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $stop_loss . ", ";
            $my_sql .= $stop_buy . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . " )";
            //print $my_sql;
            //print "\n";
            $result = queryMysql($my_sql);
            // insert into transaction history table
            $my_sql = "insert into turtle_portfolio_transaction (portfolio_id, symbol, trade_type, trade_date, shares, price, risk, risk_pct) ";
            $my_sql .= "values (1, '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= "'BUY', ";
            $my_sql .= "'" . $date . "', ";
            $my_sql .= $num_shares . ", ";
            //					$my_sql .= $breakOutStockArray[$x][$breakOutSignal].", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . " )";
            //print "tranx: $my_sql";
            $result = queryMysql($my_sql);
            // update cash position
            $my_sql = "update turtle_portfolio set shares = " . $cash . " where symbol = 'CASH'";
            $result = queryMysql($my_sql);
            //print "update: $my_sql";
        }
        $pyramid_mode++;
    }
    populateDailyBuyList($date, $breakOutSignal, $rankAndWeightArray);
}
开发者ID:jimmyc815,项目名称:algo,代码行数:101,代码来源:portfolio_selection.php

示例2: crsi_buy


//.........这里部分代码省略.........
            $p = $breakOutStockArray[$x]['purchase_price'];
            $b = $breakOutStockArray[$x]['buy_price'];
            $h = $breakOutStockArray[$x]['high'];
            $l = $breakOutStockArray[$x]['low'];
            $o = $breakOutStockArray[$x]['open'];
            $c = $breakOutStockArray[$x]['close'];
            #print "regular price: $o high $h low $l  close $c : $s buy price = $b purchase price = $p <br />";
        }
        ## set purchase price to next day open price
        ##$breakOutStockArray[$x]['purchase_price'] = getStockPrice($next_date, $breakOutStockArray[$x]['symbol'], 'open');
        $h = $breakOutStockArray[$x]['high'];
        $l = $breakOutStockArray[$x]['low'];
        $o = $breakOutStockArray[$x]['open'];
        $c = $breakOutStockArray[$x]['close'];
        $p = $breakOutStockArray[$x]['purchase_price'];
        #print "trade date: $date symbol $s close: $c open: $o purchase price = $p <br /> \n";
        #$breakOutStockArray[$x]['purchase_price'] = $breakOutStockArray[$x]['buy_price'];
        $purchase_value = $num_shares * $breakOutStockArray[$x]['purchase_price'];
        $stop_loss = $breakOutStockArray[$x]['purchase_price'] - $stop_loss_muptiplier * $current_N;
        $stop_buy = $breakOutStockArray[$x]['purchase_price'] + $current_N;
        #$current_risk = get_current_risk($portfolioID);
        $current_risk = get_portfolio_risk($date, $portfolioID);
        #print "date: $date symbol: ".$breakOutStockArray[$x]['symbol']." current risk :$current_risk \n";
        if ($cash > $purchase_value && $current_risk < $max_risk) {
            $cash = $cash - $purchase_value;
            $risk_dollar = $num_shares * ($stop_loss_muptiplier * $current_N);
            $risk_pct = $risk_dollar / $portfolio_value * 100;
            // insert into turtle_portfolio
            $my_sql = "insert into turtle_portfolio (portfolio_id, symbol, last_price, shares, cost_basis, stop_loss, stop_buy, risk, risk_pct) ";
            $my_sql .= "values (" . $portfolioID . ", '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= $breakOutStockArray[$x]['adj_close'] . ", ";
            $my_sql .= $num_shares . ", ";
            //					$my_sql .= $breakOutStockArray[$x][$breakOutSignal].", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $stop_loss . ", ";
            $my_sql .= $stop_buy . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . " )";
            #$showOutput = true;
            if ($showOutput) {
                print "num: {$x} sql: {$my_sql} <br />";
                $p = $breakOutStockArray[$x]['purchase_price'];
                print "cash: {$cash} purchase price: {$purchase_value} num shares: {$num_shares} purchase value: {$p} current n: {$current_N}<br />";
            }
            $result = queryMysql($my_sql);
            // trigger on transaction table
            /*
            DELIMITER $$
            CREATE TRIGGER ins_buy AFTER INSERT ON turtle_portfolio_transaction 
            	FOR EACH ROW 
            		BEGIN
            			DECLARE xid int;
            			IF (NEW.trade_type = 'BUY')
            			THEN
            				insert IGNORE into open_buy_transaction (portfolio_id, symbol, trade_type, trade_date, shares, price) values (NEW.portfolio_id, NEW.symbol, NEW.trade_type, NEW.trade_date, NEW.shares, NEW.price);
            			ELSE
            				insert IGNORE into transactions (portfolio_id, symbol, sell_date, sell_shares, sell_price) values (NEW.portfolio_id, NEW.symbol, NEW.trade_date, NEW.shares, NEW.price);
            				SET xid = select 1 from transactions;
            				update transactions, open_buy_transaction set transactions.buy_date =  open_buy_transaction.trade_date, transactions.buy_shares = open_buy_transaction.shares, transactions.buy_price=open_buy_transaction.price where transactions.symbol = open_buy_transaction and transactions.xid = xid  ;
            				
            				delete from open_buy_transaction where symbol = NEW.symbol
            			END IF;
            		END;
            $$
            DELIMITER ;
            */
            // insert into transaction history table
            $my_sql = "insert into {$tranHistory} (portfolio_id, symbol, trade_type, trade_date, shares, price, risk, risk_pct, vsSpyRank) ";
            $my_sql .= "values (" . $portfolioID . ", '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= "'BUY', ";
            $my_sql .= "'" . $date . "', ";
            $my_sql .= $num_shares . ", ";
            //					$my_sql .= $breakOutStockArray[$x][$breakOutSignal].", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . ", ";
            $my_sql .= $breakOutStockArray[$x]['vsSpyRank'] . " )";
            if ($showOutput) {
                print "{$my_sql} <br />";
            }
            try {
                $result = queryMysql($my_sql);
            } catch (Exception $e) {
                echo "query: {$my_sql} \n";
                echo 'Caught exception: ', $e->getMessage(), "\n";
            }
            // update cash position
            $my_sql = "update turtle_portfolio set shares = " . $cash . " where symbol = 'CASH' and portfolio_id = " . $portfolioID;
            if ($showOutput) {
                print "{$my_sql} <br />";
            }
            $result = queryMysql($my_sql);
        } else {
            #print "trade date: $date ran out of money </ br> \n";
            break;
        }
        $pyramid_mode++;
    }
    populateDailyBuyList($date, $enterCRSI, $enterRange, $portfolioID, $dailyBuyList, $enterLimit);
}
开发者ID:jimmyc815,项目名称:algo,代码行数:101,代码来源:connorsRSI_strat_5.php

示例3: getBreakoutStock5


//.........这里部分代码省略.........
    }
    if (!$dailyBuyList) {
        $dailyBuyList = "turtle_daily_buy_list";
    }
    $masterRankByResult = array();
    $rankResult = array();
    //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 d.rank, 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, d.buy_price, a.vsSpyRank ";
    $query .= "from price_history a, turtle_daily_buy_list d ";
    $query .= " where a.trade_date = '" . $today_date . "'";
    $query .= " and a.symbol = d.symbol ";
    $query .= " and a.high > d.buy_price ";
    $query .= " and d.symbol not in (select symbol from turtle_portfolio where portfolio_id = " . $portfolioID . ") ";
    //$query .= " and a.trade_date = d.trade_date ";
    //$query .= " and d.rank < 5 ";
    $query .= " order by d.rank asc";
    $query = stripslashes($query);
    //print $query;
    //print "\n";
    $result = queryMysql($query);
    /*if ($today_date == "2012-12-05")
    {
    	print "breakout stock: ";
    	print $query;
    	print "<br>";
    	
    	//exit;
    }
    */
    $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;
            }
        }
        // set would-be purchase price of the stock
        // if high > stop buy price
        // 		AND stop buy price > low, then purchase price = stop buy price
        //		AND stop buy price < open, the purchase price = opening price
        /*	            if ($tmpArray[$i]['buy_price'] > $tmpArray[$i]['low']) {
        		            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['buy_price'];
        	            } elseif ($tmpArray[$i]['buy_price'] < $tmpArray[$i]['open']) {
        		            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['open'];
        	            } elseif ($tmpArray[$i]['buy_price'] < $tmpArray[$i]['low']) {
        		            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['low'];
        	            }
        	            
        	            if (!$tmpArray[$i]['purchase_price']){
        		            $tmpArray[$i]['purchase_price'] = $tmpArray[$i][$movingAvg];
        		            
        	            }
        
        */
        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]['purchase_price']) {
            $tmpArray[$i]['purchase_price'] = $tmpArray[$i]['close'];
        }
        $i++;
    }
    $masterRankByResult[$rankBy] = $tmpArray;
    $rankResult[$rankBy] = $tmpRankArray;
    //}
    $combineRank = array();
    foreach ($rankResult as $rankBy => $resultArray) {
        foreach ($resultArray as $symbol => $value) {
            $combineRank[$symbol] += $value * $rankAndWeightArray[$rankBy];
        }
    }
    asort($combineRank);
    $i = 0;
    foreach ($combineRank as $key => $value) {
        $keyPos = $tmpRankArray[$key];
        $finalRet[$i] = $tmpArray[$keyPos];
        $i++;
    }
    //populate daily buy list
    populateDailyBuyList($today_date, $movingAvg, $rankAndWeightArray);
    return $finalRet;
}
开发者ID:jimmyc815,项目名称:algo,代码行数:101,代码来源:portfolio_selection.php

示例4: crsi_buy


//.........这里部分代码省略.........
        $h = $breakOutStockArray[$x]['high'];
        $l = $breakOutStockArray[$x]['low'];
        $o = $breakOutStockArray[$x]['open'];
        $c = $breakOutStockArray[$x]['close'];
        $p = $breakOutStockArray[$x]['purchase_price'];
        #print "trade date: $date symbol $s close: $c open: $o purchase price = $p <br /> \n";
        #$breakOutStockArray[$x]['purchase_price'] = $breakOutStockArray[$x]['buy_price'];
        $purchase_value = $num_shares * $breakOutStockArray[$x]['purchase_price'] + $commission;
        $stop_loss = $breakOutStockArray[$x]['purchase_price'] - $stop_loss_multiplier * $current_N;
        $stop_buy = $breakOutStockArray[$x]['purchase_price'] + $current_N;
        #$current_risk = get_current_risk($portfolioID);
        #$current_risk = get_portfolio_risk($date, $portfolioID);
        #print "date: $date symbol: ".$breakOutStockArray[$x]['symbol']." current risk :$current_risk \n";
        #echo "date: $date symbol: ", $breakOutStockArray[$x]['symbol'], "cash: $cash purchase value: $purchase_value current risk: $current_risk max risk: $max_risk ", PHP_EOL;
        if ($cash > $purchase_value && $current_risk < $max_risk) {
            $cash = $cash - $purchase_value;
            $risk_dollar = $num_shares * ($stop_loss_multiplier * $current_N);
            $risk_pct = $risk_dollar / $portfolio_value * 100;
            // insert into turtle_portfolio
            $my_sql = "insert into {$portfolio_table} (portfolio_id, symbol, last_price, shares, cost_basis, stop_loss, stop_buy, risk, risk_pct) ";
            $my_sql .= "values (" . $portfolioID . ", '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= $breakOutStockArray[$x]['adj_close'] . ", ";
            $my_sql .= $num_shares . ", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $stop_loss . ", ";
            $my_sql .= $stop_buy . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . " )";
            array_push($buy_array, $my_sql);
            $current_risk += $risk_pct;
            #print "current risk after adding risk dollar: current risk: $current_risk	risk pct added: $risk_pct max risk: $max_risk \n";
            #$showOutput = true;
            if ($showOutput) {
                print "num: {$x} sql: {$my_sql} <br />";
                $p = $breakOutStockArray[$x]['purchase_price'];
                print "cash: {$cash} purchase price: {$purchase_value} num shares: {$num_shares} purchase value: {$p} current n: {$current_N}<br />";
            }
            #$result = queryMysql($my_sql);
            // trigger on transaction table
            /*
            DELIMITER $$
            CREATE TRIGGER ins_buy AFTER INSERT ON turtle_portfolio_transaction 
            	FOR EACH ROW 
            		BEGIN
            			DECLARE xid int;
            			IF (NEW.trade_type = 'BUY')
            			THEN
            				insert IGNORE into open_buy_transaction (portfolio_id, symbol, trade_type, trade_date, shares, price) values (NEW.portfolio_id, NEW.symbol, NEW.trade_type, NEW.trade_date, NEW.shares, NEW.price);
            			ELSE
            				insert IGNORE into transactions (portfolio_id, symbol, sell_date, sell_shares, sell_price) values (NEW.portfolio_id, NEW.symbol, NEW.trade_date, NEW.shares, NEW.price);
            				SET xid = select 1 from transactions;
            				update transactions, open_buy_transaction set transactions.buy_date =  open_buy_transaction.trade_date, transactions.buy_shares = open_buy_transaction.shares, transactions.buy_price=open_buy_transaction.price where transactions.symbol = open_buy_transaction and transactions.xid = xid  ;
            				
            				delete from open_buy_transaction where symbol = NEW.symbol
            			END IF;
            		END;
            $$
            DELIMITER ;
            */
            // insert into transaction history table
            $my_sql = "insert into {$tranHistory} (portfolio_id, symbol, trade_type, trade_date, shares, price, risk, risk_pct, vsSpyRank) ";
            $my_sql .= "values (" . $portfolioID . ", '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= "'BUY', ";
            $my_sql .= "'" . $date . "', ";
            $my_sql .= $num_shares . ", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . ", ";
            $my_sql .= $breakOutStockArray[$x]['vsSpyRank'] . " )";
            array_push($tranHistArray, $my_sql);
            if ($showOutput) {
                print "{$my_sql} <br />";
            }
            #try {
            #	$result = queryMysql($my_sql);
            #} catch (Exception $e) {
            #   echo "query: $my_sql \n";
            #   echo 'Caught exception: ',  $e->getMessage(), "\n";
            #}
            // update cash position
            #$my_sql  = "update turtle_portfolio set shares = ".$cash." where symbol = 'CASH' and portfolio_id = ".$portfolioID;
            #$result = queryMysql($my_sql);
        } else {
            #print "trade date: $date ran out of money </ br> \n";
            break;
        }
        $pyramid_mode++;
    }
    $my_sql = "update {$portfolio_table} set shares = " . $cash . " where symbol = 'CASH' and portfolio_id = " . $portfolioID;
    $result = queryMysql($my_sql);
    foreach ($buy_array as $buy) {
        try {
            queryMysql($buy);
        } catch (Exception $e) {
            echo "Query: {$buy} \n";
            echo 'Caught exception: ', $e->getMessage(), "\n";
        }
    }
    populateDailyBuyList($date, $enterCRSI, $enterRange, $portfolioID, $dailyBuyList, $enterLimit);
}
开发者ID:jimmyc815,项目名称:algo,代码行数:101,代码来源:connorsRSI_strat_17.php

示例5: crsi_buy_and_sell


//.........这里部分代码省略.........
        ### get portfolio value
        #$portfolio_value = get_historical_turtle_portfolio_value($date, $portfolioID);
        ### get current available cash
        #$query = "select shares from turtle_portfolio where symbol = 'CASH' and portfolio_id = ".$portfolioID;
        #$result = queryMysql($query);
        #while ($data = mysql_fetch_row($result)) {
        #	$cash = $data[0];
        #}
        $risk_value = $portfolio_value * $risk_factor / 100;
        $current_N = $breakOutStockArray[$x]['ATR'];
        if ($current_N > 0) {
            $num_shares = floor($risk_value / ($stop_loss_multiplier * $current_N));
        }
        ## set purchase price to next day open price
        $breakOutStockArray[$x]['purchase_price'] = getStockPrice($next_date, $breakOutStockArray[$x]['symbol'], 'open');
        if (!$breakOutStockArray[$x]['purchase_price']) {
            break;
        }
        $purchase_value = $num_shares * $breakOutStockArray[$x]['purchase_price'] + $commission;
        $stop_loss = $breakOutStockArray[$x]['purchase_price'] - $stop_loss_multiplier * $current_N;
        $stop_buy = $breakOutStockArray[$x]['purchase_price'] + $current_N;
        #echo "symbol: ", $breakOutStockArray[$x]['symbol'], " cash: $cash purchase: $purchase_value current risk: $current_risk max risk: $max_risk ", PHP_EOL;
        if ($cash > $purchase_value && $current_risk < $max_risk) {
            $cash = $cash - $purchase_value;
            $risk_dollar = $num_shares * ($stop_loss_multiplier * $current_N);
            $risk_pct = $risk_dollar / $portfolio_value * 100;
            // insert into turtle_portfolio
            $my_sql = "insert into {$portfolio_table} (portfolio_id, symbol, last_price, shares, cost_basis, stop_loss, stop_buy, risk, risk_pct) ";
            $my_sql .= "values (" . $portfolioID . ", '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $num_shares . ", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $stop_loss . ", ";
            $my_sql .= $stop_buy . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . " )";
            array_push($buy_array, $my_sql);
            $current_risk += $risk_pct;
            #print "current risk after adding risk dollar: current risk: $current_risk	risk pct added: $risk_pct max risk: $max_risk \n";
            #$showOutput = true;
            if ($showOutput) {
                print "num: {$x} sql: {$my_sql} <br />";
                $p = $breakOutStockArray[$x]['purchase_price'];
                print "cash: {$cash} purchase price: {$purchase_value} num shares: {$num_shares} purchase value: {$p} current n: {$current_N}<br />";
            }
            // insert into transaction history table
            $my_sql = "insert into {$tranHistory} (portfolio_id, symbol, trade_type, trade_date, shares, price, risk, risk_pct, vsSpyRank) ";
            $my_sql .= "values (" . $portfolioID . ", '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= "'BUY', ";
            $my_sql .= "'" . $date . "', ";
            $my_sql .= $num_shares . ", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . ", ";
            $my_sql .= "0 )";
            array_push($tranHistArray, $my_sql);
            $tmpTransaction = array();
            $tmpTransaction['portfolioID'] = $portfolioID;
            $tmpTransaction['symbol'] = $breakOutStockArray[$x]['symbol'];
            $tmpTransaction['buy_sell'] = "BUY";
            $tmpTransaction['trade_date'] = $date;
            $tmpTransaction['shares'] = $num_shares;
            $tmpTransaction['price'] = $breakOutStockArray[$x]['purchase_price'];
            $tmpTransaction['risk'] = $risk_dollar;
            $tmpTransaction['risk_pct'] = $risk_pct;
            $tmpTransaction['trade_time'] = "null";
            $tmpTransaction['gain_loss'] = 0;
            $tmpTransaction['holding_period'] = 0;
            $tmpTransaction['vsSpyRank'] = 0;
            array_push($transactionHistory, $tmpTransaction);
            if ($showOutput) {
                print "{$my_sql} <br />";
            }
            #try {
            #	$result = queryMysql($my_sql);
            #} catch (Exception $e) {
            #   echo "query: $my_sql \n";
            #   echo 'Caught exception: ',  $e->getMessage(), "\n";
            #}
            // update cash position
            #$my_sql  = "update turtle_portfolio set shares = ".$cash." where symbol = 'CASH' and portfolio_id = ".$portfolioID;
            #$result = queryMysql($my_sql);
        } else {
            #print "trade date: $date ran out of money </ br> \n";
            break;
        }
        $pyramid_mode++;
    }
    $my_sql = "update {$portfolio_table} set shares = " . $cash . " where symbol = 'CASH' and portfolio_id = " . $portfolioID;
    $result = queryMysql($my_sql);
    foreach ($buy_array as $buy) {
        try {
            queryMysql($buy);
        } catch (Exception $e) {
            echo "Query: {$buy} \n";
            echo 'Caught exception: ', $e->getMessage(), "\n";
        }
    }
    populateDailyBuyList($date, $enterCRSI, $enterRange, $portfolioID, $dailyBuyList, $enterLimit);
}
开发者ID:jimmyc815,项目名称:algo,代码行数:101,代码来源:connorsRSI_strat_19.php

示例6: array

     
     			array_push($retArray, array($newDateStr, $preturn));
     */
     $count++;
     //		}
     echo json_encode($retArray);
 } else {
     if ($_GET['action'] == 'end_of_day_processing') {
         global $portfolioID;
         $portfolioID = $_GET['portfolio_id'];
         $today_date = date("Y-m-d");
         $today_date = "2013-02-15";
         $breakOutSignal = "55_DAY_HIGH";
         $dailyBuyList = "turtle_daily_buy_list_live";
         $rankAndWeightArray = "";
         populateDailyBuyList($today_date, $breakOutSignal, $rankAndWeightArray, $portfolioID, $dailyBuyList);
         live_turtle_portfolio_update_stop_loss($portfolioID);
         update_daily_portfolio_performance($portfolioID);
         send_end_of_day_email($portfolioID);
     } else {
         if ($_GET['action'] == 'reset_live_portfolio') {
             global $portfolioID;
             $portfolioID = $_GET['portfolio_id'];
             reset_portfolio($portfolioID);
         } elseif ($_GET['action'] == 'testCalculateEndBalance') {
             $transactionList = array();
             $beginBalance = 1000000;
             // get unique symbol from transaction table that has sell
             $query = "select symbol, trade_type, trade_date, shares, price from turtle_portfolio_transaction where portfolio_id = 1 order by trade_date asc ";
             $result = queryMysql($query);
             while ($data = mysql_fetch_row($result)) {
开发者ID:jimmyc815,项目名称:algo,代码行数:30,代码来源:turtle_live_monitor.php

示例7: crsi_buy_and_sell


//.........这里部分代码省略.........
    #$breakOutStockArray = getBuyList ($date, $enterCRSI, $enterRange, $portfolioID, $dailyBuyList, $enterLimit, $orderBy);
    $breakOutStockArray = $buy_list;
    $sizeBuyList = sizeof($breakOutStockArray);
    if (!$skipFactor) {
        $skipFactor = 0.05;
    }
    $len_array = count($breakOutStockArray);
    $portfolio_value = 0;
    $current_pos = 0;
    $next_buy_point = 100000;
    $stop_loss = 0;
    $num_shares = 0;
    $current_N = 0;
    $risk_value = 0;
    $purchase_value = 0;
    $sim_start_day = 55;
    $pyramid_mode = 0;
    $stop_loss = 0;
    $current_trade_date_id = 0;
    $workingArray = $breakOutStockArray;
    $adxArray = "";
    $adxCount = 1;
    $len_array = count($breakOutStockArray);
    $portfolio_value = 0;
    #calculate portfolio value
    foreach (array_keys($portfolioArray) as $key) {
        $portfolio_value += $portfolioArray[$key]['shares'] * $portfolioArray[$key]['adj_close'];
    }
    $portfolio_value += $cash_balance;
    #echo "date: $date portfolio value: $portfolio_value cash balance: $cash_balance ", PHP_EOL;
    $crisk = 0;
    #calculate portfolio value
    foreach (array_keys($portfolioArray) as $key) {
        $crisk += $portfolioArray[$key]['risk_pct'];
    }
    $current_risk = $crisk;
    $buy_array = array();
    $skipNum = ceil($skipFactor * $sizeBuyList);
    #for ($x=1; $x < $len_array; $x++) {
    for ($x = $skipNum; $x < $sizeBuyList; $x++) {
        $risk_value = $portfolio_value * $risk_factor / 100;
        $current_N = $breakOutStockArray[$x]['ATR'];
        if ($current_N > 0) {
            $num_shares = floor($risk_value / ($stop_loss_multiplier * $current_N));
        }
        ## set purchase price to next day open price
        #$breakOutStockArray[$x]['purchase_price'] = getStockPrice($next_date, $breakOutStockArray[$x]['symbol'], 'open');
        $breakOutStockArray[$x]['purchase_price'] = $breakOutStockArray[$x]['next_open'];
        if (!$breakOutStockArray[$x]['purchase_price']) {
            break;
        }
        $purchase_value = $num_shares * $breakOutStockArray[$x]['purchase_price'] + $commission;
        $stop_loss = $breakOutStockArray[$x]['purchase_price'] - $stop_loss_multiplier * $current_N;
        $stop_buy = $breakOutStockArray[$x]['purchase_price'] + $current_N;
        #echo "cash balance: ", $cash_balance, PHP_EOL;
        #echo "symbol: ", $breakOutStockArray[$x]['symbol'], " cash : $cash cash balance: $cash_balance current risk: $current_risk max risk: $max_risk ", PHP_EOL;
        if ($cash_balance > $purchase_value && $current_risk < $max_risk) {
            $risk_dollar = $num_shares * ($stop_loss_multiplier * $current_N);
            $risk_pct = $risk_dollar / $portfolio_value * 100;
            $current_risk += $risk_pct;
            $cash_balance = $cash_balance - $purchase_value;
            $tmpBuy = array();
            $tmpBuy['shares'] = $num_shares;
            $tmpBuy['risk'] = $risk_dollar;
            $tmpBuy['risk_pct'] = $risk_pct;
            $tmpBuy['adj_close'] = $breakOutStockArray[$x]['adj_close'];
            $tmpBuy['cost_basis'] = $breakOutStockArray[$x]['purchase_price'];
            $portfolioArray[$breakOutStockArray[$x]['symbol']] = $tmpBuy;
            // insert into transaction history table
            $my_sql = "insert into {$tranHistory} (portfolio_id, symbol, trade_type, trade_date, shares, price, risk, risk_pct, vsSpyRank) ";
            $my_sql .= "values (" . $portfolioID . ", '" . $breakOutStockArray[$x]['symbol'] . "', ";
            $my_sql .= "'BUY', ";
            $my_sql .= "'" . $date . "', ";
            $my_sql .= $num_shares . ", ";
            $my_sql .= $breakOutStockArray[$x]['purchase_price'] . ", ";
            $my_sql .= $risk_dollar . ", ";
            $my_sql .= $risk_pct . ", ";
            $my_sql .= "0 )";
            array_push($tranHistArray, $my_sql);
            $tmpTransaction = array();
            $tmpTransaction['portfolioID'] = $portfolioID;
            $tmpTransaction['symbol'] = $breakOutStockArray[$x]['symbol'];
            $tmpTransaction['buy_sell'] = "BUY";
            $tmpTransaction['trade_date'] = $date;
            $tmpTransaction['shares'] = $num_shares;
            $tmpTransaction['price'] = $breakOutStockArray[$x]['purchase_price'];
            $tmpTransaction['risk'] = $risk_dollar;
            $tmpTransaction['risk_pct'] = $risk_pct;
            $tmpTransaction['trade_time'] = "null";
            $tmpTransaction['gain_loss'] = 0;
            $tmpTransaction['holding_period'] = 0;
            $tmpTransaction['vsSpyRank'] = 0;
            #array_push($transactionHistory, $tmpTransaction);
        } else {
            break;
        }
        $pyramid_mode++;
    }
    populateDailyBuyList($date, $enterCRSI, $enterRange, $portfolioID, $dailyBuyList, $enterLimit);
}
开发者ID:jimmyc815,项目名称:algo,代码行数:101,代码来源:connorsRSI_strat_21.php


注:本文中的populateDailyBuyList函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。