The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Finance::GeniusTrader::Portfolio::Position - An open position within a portfolio

DESCRIPTION

Internal structure

  {
    "long" => 1,            # 1:Long 0:Short
    "code" => "13000",
    "quantity" => 100,
    "initial_quantity" => 100, # Quantity when position was opened
    "open_price" => 12.4,      # Price when position has been taken
    "close_price" => 13.2,     # Prices when position has been closed
    "source" => "Trend",       # Which trading system opened the position
    "open_date" => "2001-07-01",
    "close_date" => "2001-07-04",
    "stop" => 12               # Stop is at 12
  }

Functions

$p = Finance::GeniusTrader::Portfolio::Position->new($code, $source, $date)
$p->set_long()
$p->set_short()
$p->is_long()
$p->is_short()
$p->set_code($code)
$p->code()
$p->set_quantity($quantity)
$p->quantity()
$p->set_initial_quantity($quantity)
$p->initial_quantity()
$p->set_open_price($price)
$p->open_price()
$p->set_close_price($price)
$p->close_price()
$p->set_source($source)
$p->source()
$p->set_open_date($date)
$p->open_date()
$p->set_close_date($date)
$p->close_date()
$p->set_id($id)
$p->id()
$p->set_stop($price)
$p->update_stop($price)
$p->force_stop($price)
$p->stop()

set_stop and update_stop modifies the stop level but it won't let you further the stop, you can only bring it nearer. If you want to further the stop level use force_stop.

$p->set_attribute($key, [ $value ]);
$p->has_attribute($key);
$p->attribute($key);
$p->delete_attribute($key);

A position can have "attributes" associated to keep track of its status in various strategies. has_attribute returns only true if the attribute exists (whatever its value is). attribute returns the attribute value if it exists or undef otherwise.

$p->set_timeframe($timeframe)
$p->timeframe()

Set and return the timeframe associated to this position.

$p->set_marged()
$p->set_not_marged()
$p->is_marged()

A marged position is constitued of shares that have been "rented" (or bought with rented cash).

$p->apply_order($order, $price, $date)

Update the position with the corresponding order. The order has been executed at the given date and at the given price.

$p->apply_pending_orders($calc, $i)
$p->add_order($order)

Add a new pending order to the position.

$p->delete_order($order)
$p->discard_order($order)
$p->list_pending_orders()

Returns the list of pending orders on the position. Those orders have not yet been executed.

$p->list_detailed_orders()

Returns the list of detailed orders on the position. Those orders have already been executed.

$p->is_open()

Returns true if the position is still open (ie if quantity != 0)

$p->set_intent_to_close()

Mark the position as being in the process of being closed. This will let the system detect new opportunities as soon as possible.

$p->set_no_intent_to_close()

DeMark the position as being in the process of being closed. This will let the system manage the position without knowing that some orders have been placed to close the position (ie those orders may or may not be executed).

$p->being_closed()

Returns true if the position is in the process of beeing closed.

$p->stats($portfolio, [ $quantity_factor ])

Calculate some statistics about the position.