$orderBy = $_GET['orderBy']; $commission = $_GET['commission']; ## risk factor if ($_GET['maxRisk']) { $max_risk = $_GET['maxRisk']; } if ($_GET['riskFactor']) { $risk_factor = $_GET['riskFactor']; } if ($_GET['riskSD']) { $stop_loss_multiplier = $_GET['riskSD']; } if (!$orderBy) { $orderBy = "crsi desc"; } $simResult = simulate_range_trade($portfolioID, $start_date, $end_date, $enterCRSI, $enterRange, $enterLimit, $exitCRSI, $commission, $max_risk, $risk_factor, $stop_loss_multiplier, $orderBy); echo $simResult; } elseif ($_GET['action'] == 'reset_portfolio') { $cash = 1000000; $cash = $_GET['cash']; $pid = $_GET['portfolio_id']; print "cash: {$cash} \n"; reset_portfolio($pid); } elseif ($_GET['action'] == 'get_num_of_trade_days') { $start_date = $_GET['start_date']; $end_date = $_GET['end_date']; // if end date is not supplied, default to today if (!$end_date) { $end_date = date("Y-m-d"); } $query = "select count(*) from quotes_memory where symbol = 'AAPL' and trade_date >= '" . $start_date . "' and trade_date <= '" . $end_date . "'";
function initiate_live_portfolio_2($portfolioID) { global $original_investment; global $breakOutSignal; global $ADX_filter; global $breakOutSignal; global $breakOutOrderBy; global $simplePriceHistory; global $showOutput; global $risk_factor; global $max_risk; global $stop_loss_multiplier; global $tranHistArray; global $portfolio_table; global $liveportfolio; global $liveportfolio_account; global $liveportfolio_trade; global $liveportfolio_complete_trade; global $commission; $account = live_get_account_setting($portfolioID); $original_investment = $account['starting_capital']; reset_live_portfolio($portfolioID); $end_date = date("Y-m-d"); $simResult = simulate_range_trade($portfolioID, $account['start_date'], $end_date, $account['enter_crsi'], $account['enter_range'], $account['pct_limit_below'], $account['exit_crsi'], $commission, $account['max_risk'], $account['risk_factor'], $account['risk_sd'], $account['order_by']); copy_sim_to_live_portfolio($portfolioID); print $simResult; }
function initiate_live_portfolio($portfolioID, $start_date, $end_date, $enterCRSI, $enterRange, $enterLimit, $exitCRSI, $commission, $max_risk, $risk_factor, $stop_loss_multiplier, $orderBy) { global $original_investment; global $breakOutSignal; global $ADX_filter; global $breakOutSignal; global $breakOutOrderBy; global $simplePriceHistory; global $showOutput; global $risk_factor; global $max_risk; global $stop_loss_multiplier; global $tranHistArray; global $portfolio_table; global $liveportfolio; global $liveportfolio_account; global $liveportfolio_trade; global $liveportfolio_complete_trade; reset_live_portfolio($portfolioID); $simResult = simulate_range_trade($portfolioID, $start_date, $end_date, $enterCRSI, $enterRange, $enterLimit, $exitCRSI, $commission, $max_risk, $risk_factor, $stop_loss_multiplier, $orderBy); copy_sim_to_live_portfolio($portfolioID); print $simResult; }
function execute_test_runs($pid) { global $dbname; $simTestCases = "simTestCases"; $simRuns = "simRuns"; $simRestart = "simRestart"; $maxParallelRun = 13; $commission = 7; $query = "use {$dbname}"; $result = queryMysql($query); # count number of simulation runs left $query = "select count(*) from {$simRuns} "; $result = queryMysql($query); while ($data = mysql_fetch_row($result)) { $runCount = $data[0]; } # count number of current process running simulation $query = "select count(*) from {$simRestart} "; $result = queryMysql($query); while ($data = mysql_fetch_row($result)) { $restartCount = $data[0]; } $restartRunID = ""; $restartCaseID = ""; # check if restart table has unfinished run id for this pid $query = "select runID, caseID from {$simRestart} where PID = {$pid}"; $result = queryMysql($query); while ($data = mysql_fetch_row($result)) { $restartRunID = $data[0]; $restartCaseID = $data[1]; } #if ($restartCount < $maxParallelRun) { #while ($runCount > 0) { ## copy portfolio holding # if there's unfinished run id for this pid in restart table, rerun simulation for this run id if ($restartCaseID) { $query = "select a.runID, a.caseID, start_date, end_date, enter_crsi, enter_range, pct_limit_below, exit_crsi, order_by, max_risk, risk_factor, risk_sd, skip_factor \n\t\t\t\t\t\t from {$simRestart} a, {$simTestCases} b\n\t\t\t\t\t\t where a.caseID = b.caseID \n\t\t\t\t\t\t and a.runID = {$restartRunID} \n\t\t\t\t\t\t "; } else { $query = "select runID, a.caseID, start_date, end_date, enter_crsi, enter_range, pct_limit_below, exit_crsi, order_by, max_risk, risk_factor, risk_sd, skip_factor \n\t\t\t\t\t\t from {$simRuns} a, {$simTestCases} b \n\t\t\t\t\t\t where a.caseID = b.caseID \n\t\t\t\t\t\t order by runID desc limit 1"; } #and enter_crsi not in (select enter_crsi from $simTestCases c, $simRestart d where c.caseID = d.caseID ) #echo "query : $query ", PHP_EOL; $result = queryMysql($query); while ($data = mysql_fetch_row($result)) { $runID = $data[0]; $caseID = $data[1]; $startDate = $data[2]; $endDate = $data[3]; $enterCRSI = $data[4]; $enterRange = $data[5]; $limitBelow = $data[6]; $exitCRSI = $data[7]; $orderBy = $data[8]; $maxRisk = $data[9]; $riskFactor = $data[10]; $riskSD = $data[11]; $skipFactor = $data[12]; } #echo "resart case id $restartCaseID", PHP_EOL; if (empty($restartCaseID)) { # move current RunID to restart table #echo "inside ", PHP_EOL; $query = "insert into {$simRestart} select runID, caseID, start_date, end_date, {$pid} from {$simRuns} where runID = {$runID}"; $result = queryMysql($query); # delete runID from run table $query = "delete from {$simRuns} where runID = {$runID} "; $result = queryMysql($query); } #echo "query: $query ", PHP_EOL; #$portfolioID = $enterCRSI; echo "portfolio id: {$pid} start date: {$startDate} end date: {$endDate} enter crsi: {$enterCRSI} enter range: {$enterRange} limit below: {$limitBelow} exit crsi: {$exitCRSI} commission {$commission} max risk: {$maxRisk} risk factor: {$riskFactor} risk sd: {$riskSD} order by {$orderBy} skip factor: {$skipFactor} ", PHP_EOL; ## start simultation $simResult = simulate_range_trade($pid, $startDate, $endDate, $enterCRSI, $enterRange, $limitBelow, $exitCRSI, $commission, $maxRisk, $riskFactor, $riskSD, $orderBy, $skipFactor); #echo "sim Result: $simResult ", PHP_EOL; $pythonOut = system("python /python_script/PortfolioAnalyzer3.py --run_id {$runID} --portfolio {$pid}"); echo "python out: {$pythonOut} ", PHP_EOL; ## remove runID from restart table $query = "delete from {$simRestart} where runID = {$runID} "; $result = queryMysql($query); # count number of simulation runs left $query = "select count(*) from {$simRuns} "; $result = queryMysql($query); while ($data = mysql_fetch_row($result)) { $runCount = $data[0]; } echo "run count: {$runCount}", PHP_EOL; #} #} }