Exemple #1
0
        /// <summary>
        /// Profit if we closed the holdings right now including the approximate fees.
        /// </summary>
        /// <remarks>Does not use the transaction model for market fills but should.</remarks>
        public virtual decimal TotalCloseProfit() 
        {
            decimal gross = 0, net = 0;
            decimal orderFee = 0;

            if (AbsoluteQuantity > 0) 
            {
                orderFee = _model.GetOrderFee(AbsoluteQuantity, _price);
            }

            if (IsLong) 
            {
                //if we're long on a position, profit from selling off $10,000 stock:
                gross = (_price - AveragePrice) * AbsoluteQuantity;
            } 
            else if (IsShort) 
            {
                //if we're short on a position, profit from buying $10,000 stock:
                gross = (AveragePrice - _price) * AbsoluteQuantity;
            } 
            else 
            {
                //no holdings, 0 profit.
                return 0;
            }

            net = gross - orderFee;

            return net;
        }
        /// <summary>
        /// Profit if we closed the holdings right now including the approximate fees.
        /// </summary>
        /// <remarks>Does not use the transaction model for market fills but should.</remarks>
        public virtual decimal TotalCloseProfit() 
        {
            if (AbsoluteQuantity == 0)
            {
                return 0;
            }

            // this is in the account currency
            var marketOrder = new MarketOrder(_security.Symbol, -Quantity, _security.Time, type: _security.Type) {Price = Price};
            var orderFee = TransactionModel.GetOrderFee(_security, marketOrder);

            return (Price - AveragePrice) * Quantity - orderFee;
        }