예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:B4F.TotalGiro.PortfolioComparer.PortfolioCompareSetting">PortfolioCompareSetting</see> class.
        /// </summary>
        /// <param name="compareAction">
        /// When this argument equals 'CloseOrders' it is checked whether positions exist that do not exist in the modelportfolio. 
        /// When this is the case this will result in only sell close size based orders.
        /// When the argument equals 'Rebalance' a normal rebalance is done.
        /// However the method will generate an error when positions do exist that do not exist in the modelportfolio.
        /// When the argument equals 'CashFundOrders' the remaining cash will be transferred to cash fund.
        /// </param>
        /// <param name="instruction">The instruction that generated the orders</param>
        /// <param name="engineParams">The parameters used in porfolio compare action</param>
        public PortfolioCompareSetting(PortfolioCompareAction compareAction, IInstruction instruction, InstructionEngineParameters engineParams)
        {
            if (instruction == null)
                throw new ApplicationException("The instruction is mandatory");

            this.CompareAction = compareAction;
            this.Instruction = instruction;
            this.EngineParams = engineParams;
        }
예제 #2
0
        internal void Add(IOrder order, PortfolioCompareAction compareAction)
        {
            if (!(order.IsMonetary && ((IMonetaryOrder)order).MoneyParent != null))
            {
                if (!order.IsClosed && order.OpenValue.IsNotZero)
                {
                    decimal ratio = 1M;
                    // remove already approved transactions from the ratio
                    if (order.Transactions != null && order.Transactions.Count > 0)
                        ratio -= order.Transactions.TotalApprovedFillRatio();

                    // Find traded instrument
                    PositionComparer pc = getPos(order.RequestedInstrument);
                    if (pc != null)
                    {
                        if (order.IsAmountBased)
                            pc.ExistingOrderAmount += order.GrossAmount * ratio;
                        else if (order.IsSizeBased)
                            pc.ExistingOrderSize += order.OpenValue;
                        pc.OrderIds += (pc.OrderIds != string.Empty ? ", " : "") + order.OrderID.ToString();
                    }

                    if (compareAction != PortfolioCompareAction.CloseOrders)
                    {
                        if (!(order.OpenValue.Underlying.IsCash && order.OpenValue.Underlying.ToCurrency.IsBase))
                            throw new ApplicationException("Order not in base currency");

                        // Find cash record
                        pc = getPos(order.OpenValue.Underlying);
                        if (pc != null)
                            pc.OpenOrderAmount += (order.GrossAmount * ratio * - 1M);
                    }
                }
            }
        }