Example #1
0
 /**
  * Calculate current capital, current outstanding capital, current profit/loss.
  **/
 function runCapitalReport()
 {
     $query = mysql_query("SELECT * FROM trades WHERE portfolio_id = '" . $this->id . "'");
     $trade_profit = 0;
     $cash_out = 0;
     $open_trade_profit = 0;
     while ($array = mysql_fetch_array($query)) {
         $trade = new Trade($array);
         //Closed Trade
         if ($trade->sold_price > 0.0) {
             $trade_profit += ($trade->sold_price - $trade->bought_price) * $trade->number_of_stocks;
         } else {
             $ticker = $trade->stock->getTicker();
             update_stock_info($ticker);
             $trade->stock = new Stock($ticker);
             //Open Trade
             $open_trade_profit += $trade->number_of_stocks * ($trade->stock->getLastTrade() - $trade->bought_price);
             $cash_out += $trade->bought_price * $trade->number_of_stocks;
         }
     }
     $this->current_cash = $this->opening_capital + $trade_profit - $cash_out;
     $this->account_value = $this->opening_capital + $trade_profit + $open_trade_profit;
 }
Example #2
0
/**
 * @param Mixed $stock Can be either a stock ID or an instance of stock class.
 * @return HTML formatted list of trades attached to this stock.
 **/
function get_trade_list_from_portfolio($portfolio, $close_trade_id = -1)
{
    if (is_numeric($portfolio)) {
        $portfolio = new Portfolio($portfolio);
    }
    $tradeTable = '
    
    <h2>Open Trades</h2>
    <table class="table" width="720" cellspacing="0">
        <tr>
            <td width="75" class="table_header"><b>Date</b></td>
            <td width="60" class="table_header"><b># of Stocks</b></td>
            <td width="60" class="table_header"><b>Bought Price</b></td>
            <td width="60" class="table_header"><b>Current Price</b></td>
            <td width="60" class="table_header"><b>Gain/Loss</b></td>
            <td width="60" class="table_header"><b>Portfolio</b></td>
            <td width="60" class="table_header"><b>Action</b></td>
        </tr>
    ';
    $query = mysql_query("SELECT * FROM trades WHERE portfolio_id = '" . $portfolio->id . "' AND sold_price < 0.01 ORDER BY bought_date DESC");
    if (mysql_num_rows($query) < 1) {
        $tradeTable .= '<tr><td width="100%" class="table_row" colspan="7">No Open Trades</td></tr>';
    }
    while ($array = mysql_fetch_array($query)) {
        $trade = new Trade($array);
        $ticker = $trade->stock->getTicker();
        update_stock_info($ticker);
        $trade->stock = new Stock($ticker);
        if ($close_trade_id == $trade->id) {
            $tradeTable .= '
            <tr>
                <td width="75" class="table_row_bottomless">' . $trade->bought_date_string . '</td>
                <td width="60" class="table_row_bottomless">' . $trade->number_of_stocks . '</td>
                <td width="60" class="table_row_bottomless">' . $trade->bought_price . '</td>
                <td width="60" class="table_row_bottomless">' . $trade->stock->getLastTrade() . '</td>
                <td width="60" class="table_row_bottomless">' . round(($trade->stock->getLastTrade() - $trade->bought_price) * $trade->number_of_stocks, 2) . '</td>
                <td width="60" class="table_row_bottomless">' . $portfolio->name . '</td>
                <td width="60" class="table_row_bottomless"><input type="submit" value="Cancel" onClick="trade_tradePortfolioList(' . $portfolio->id . ',-1);return false;"</td>
            </tr>';
            $tradeTable .= '
            <tr>
                <td width="100%" colspan="7" class="table_row">
                    <form action="portfolio.php?do=closeTrade&portfolio_id=' . $portfolio->id . '" method="POST">
                        <p>
                            <input type="hidden" value="' . $trade->id . '" name="trade_id" id="trade_id"/>
                            <label>Close Date</label>
                            <input type="text" id="sold_date_string" name="sold_date_string" />
                            <label>Close Price</label>
                            <input type="text" id="sold_price" name="sold_price" />
                            <label>Save</label>
                            <input type="submit" value="Close Trades" />
                        </p>
                    </form>
                </td>
            </tr>
            ';
        } else {
            $tradeTable .= '
            <tr>
                <td width="75" class="table_row">' . $trade->bought_date_string . '</td>
                <td width="60" class="table_row">' . $trade->number_of_stocks . '</td>
                <td width="60" class="table_row">' . $trade->bought_price . '</td>
                <td width="60" class="table_row">' . $trade->stock->getLastTrade() . '</td>
                <td width="60" class="table_row">' . round(($trade->stock->getLastTrade() - $trade->bought_price) * $trade->number_of_stocks, 2) . '</td>
                <td width="60" class="table_row">' . $portfolio->name . '</td>
                <td width="60" class="table_row"><input type="submit" value="Close" onClick="trade_tradePortfolioList(' . $portfolio->id . ',' . $trade->id . ');return false;"</td>
            </tr>';
        }
    }
    $tradeTable .= '</table>';
    $tradeTable .= '
    <h2>Closed Trades</h2>
    <table class="table" width="720" cellspacing="0">
        <tr>
            <td width="75" class="table_header"><b>Date Bought</b></td>
            <td width="60" class="table_header"><b># of Stocks</b></td>
            <td width="60" class="table_header"><b>Bought Price</b></td>
            <td width="60" class="table_header"><b>Sold Price</b></td>
            <td width="60" class="table_header"><b>Sold Date</b></td>
            <td width="60" class="table_header"><b>Gain/Loss</b></td>
            <td width="60" class="table_header"><b>Portfolio</b></td>
        </tr>
    ';
    $query = mysql_query("SELECT * FROM trades WHERE portfolio_id = '" . $portfolio->id . "' AND sold_price > 0.00 ORDER BY bought_date DESC");
    if (mysql_num_rows($query) < 1) {
        $tradeTable .= '<tr><td width="100%" class="table_row" colspan="8">No Closed Trades</td></tr>';
    }
    while ($array = mysql_fetch_array($query)) {
        $trade = new Trade($array);
        $tradeTable .= '
        <tr>
            <td width="75" class="table_row">' . $trade->bought_date_string . '</td>
            <td width="60" class="table_row">' . $trade->number_of_stocks . '</td>
            <td width="60" class="table_row">' . $trade->bought_price . '</td>
            <td width="60" class="table_row">' . $trade->sold_price . '</td>
            <td width="60" class="table_row">' . $trade->sold_date_string . '</td>
            <td width="60" class="table_row">' . round(($trade->sold_price - $trade->bought_price) * $trade->number_of_stocks, 2) . '</td>
            <td width="60" class="table_row">' . $portfolio->name . '</td>
        </tr>';
    }
    $tradeTable .= '</table><br /><br />';
    return $tradeTable;
}
Example #3
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php 
error_reporting(E_ALL ^ E_NOTICE);
require_once 'model.php';
require_once 'php-ofc-library/open-flash-chart-object.php';
require_once 'php-ofc-library/open-flash-chart.php';
require_once 'php-ofc-library/ofc_candle.php';
$ticker = $_REQUEST['s'];
//update_stock_info($ticker);
update_stock_daily($ticker);
update_stock_info($ticker);
$stock = get_stock($ticker);
$t = $_REQUEST['t'];
if ($t == "") {
    $t = 20;
}
$tid = $_REQUEST['tid'];
$sa = $_REQUEST['sa'];
$sb = $_REQUEST['sb'];
$sc = $_REQUEST['sc'];
$sd = $_REQUEST['sd'];
$se = $_REQUEST['se'];
$chart_url = urlencode('chart.php?t=' . $t . '&tid=' . $stock->getId() . '&sa=' . $sa . '&sb=' . $sb . '&sc=' . $sc . '&sd=' . $sd . '&se=' . $se);
if ($_REQUEST['do'] == 'processTrade') {
    $trade = new Trade();
    $message = $trade->buildFromPost();
    if ($message == "") {
        $trade->persist();
        $message = "Successfully added trade.";
        include 'html/green_messagebox.php';
    } else {
Example #4
0
    }
    $stockTable = get_stock_list($letter, $cap, $price, $eps, $ppe);
    include 'html/stock_list.php';
} else {
    if ($_REQUEST['do'] == 'updateStockDetails') {
        $start = $_REQUEST['s'];
        if ($start == "") {
            $start = 0;
        }
        $query = mysql_query("SELECT ticker FROM stocks WHERE status = '" . STATUS_ACTIVE . "' LIMIT {$start},1");
        if (mysql_num_rows($query) < 1) {
            echo -1;
            return;
        }
        while ($array = mysql_fetch_array($query)) {
            update_stock_info($array['ticker']);
        }
        $start = $start + 1;
        echo $start;
    } else {
        if ($_REQUEST['do'] == 'updateStockDailyData') {
            $start = $_REQUEST['s'];
            if ($start == "") {
                $start = 0;
            }
            $query = mysql_query("SELECT ticker FROM stocks WHERE status = '" . STATUS_ACTIVE . "' LIMIT {$start},1") or die(mysql_error() . "DD:" . $start);
            if (mysql_num_rows($query) < 1) {
                echo -1;
                return;
            }
            while ($array = mysql_fetch_array($query)) {