Esempio n. 1
0
int CPos::short_pos(day_price_t &dp, int percent)
{
    int date = dp.date;
    int price = dp.open;

    assert(m_status == ST_OPEN);
    assert(date >= m_begin_date && m_end_date == 0);

    int count = m_init_count / percent;
    if (count > m_curr_count)
        count = m_curr_count;

    m_curr_count -= count;
    if (m_curr_count == 0){
        m_status = ST_CLOSE;
        m_end_date = date;
    }

    m_curr_cost = price;
    COperation *op = new COperation(this, date, DI_SELL, count, price);
    m_ops[date] = op;

    //we get fix_profit now
    profit_t *p = &m_fix_profit;
    p->fee += op->get_fee();
    p->cash_profit += count * (price - m_init_cost);
    p->float_profit = m_curr_count * (price - m_init_cost) + p->cash_profit;
    p->total_profit = p->cash_profit - p->fee;

    return p->total_profit;
}
Esempio n. 2
0
CPos:: CPos(CStock *owner, int begin_date, int count, int cost)
{
    m_db = owner->get_db();
    m_owner = owner;
    m_begin_date = begin_date;
    m_end_date = 0;
    m_init_count = m_curr_count = count;
    m_init_cost = m_curr_cost = cost;
    m_status = ST_OPEN;

    COperation *op = new COperation(this, begin_date, DI_BUY, count, cost);
    m_ops[begin_date] = op;
    m_fix_profit.fee = op->get_fee();
}