Example #1
0
 /// <summary>
 /// Determines if the record is a child proposedOrder of another order.
 /// </summary>
 /// <param name="proposedOrderRow"></param>
 /// <returns>True if the order is a child of another propsosed order.</returns>
 public static bool IsChildProposedOrder(DataModel.ProposedOrderRow proposedOrderRow)
 {
     // This assumes only one level of hierarchy to the order, but returns true of the order is a child of another
     // proposedOrder.
     return((proposedOrderRow.GetProposedOrderTreeRowsByFKProposedOrderProposedOrderTreeChildId().Length > 0) ?
            true : false);
 }
Example #2
0
 /// <summary>
 /// Calculates the market value of the given Proposed Order in the base currency.
 /// </summary>
 /// <param name="baseCurrency">The base currency for the market value calculation.</param>
 /// <param name="proposedOrderRow">The subject of the calculation.</param>
 /// <returns>The market value of the Proposed Order in the base currency.</returns>
 private static decimal Calculate(DataModel.CurrencyRow baseCurrency,
                                  DataModel.ProposedOrderRow proposedOrderRow)
 {
     return(proposedOrderRow.Quantity *
            proposedOrderRow.SecurityRowByFKSecurityProposedOrderSecurityId.QuantityFactor *
            Price.Security(baseCurrency, proposedOrderRow.SecurityRowByFKSecurityProposedOrderSecurityId) *
            proposedOrderRow.SecurityRowByFKSecurityProposedOrderSecurityId.PriceFactor *
            proposedOrderRow.TransactionTypeRow.QuantitySign);
 }
Example #3
0
        /// <summary>
        /// Calculates the number of shares in a given position.
        /// </summary>
        /// <param name="baseCurrency">The base currency for the market value calculation.</param>
        /// <param name="AccountId">The identifier of the account.</param>
        /// <param name="SecurityId">The identifier of the security.</param>
        /// <param name="positionTypeCode">The PositionTypeCode (long or short).</param>
        /// <param name="quantityFlags">These flags direct what elements are included and whether to include
        /// children.</param>
        /// <returns></returns>
        public static decimal Calculate(DataModel.AccountRow accountRow, DataModel.SecurityRow securityRow,
                                        int positionTypeCode, MarketValueFlags quantityFlags)
        {
            // This is the accumulator for market value.
            decimal quantity = 0.0M;

            // This key is used to find records that match the given position.
            object[] key = new object[] { accountRow.AccountId, securityRow.SecurityId, positionTypeCode };

            // Aggregate Tax Lots
            if ((quantityFlags & MarketValueFlags.IncludeTaxLot) != 0)
            {
                foreach (DataRowView dataRowView in DataModel.TaxLot.UKTaxLotAccountIdSecurityIdPositionTypeCode.FindRows(key))
                {
                    quantity += ((DataModel.TaxLotRow)dataRowView.Row).Quantity;
                }
            }

            // Aggregate Proposed Order
            if ((quantityFlags & MarketValueFlags.IncludeProposedOrder) != 0)
            {
                foreach (DataRowView dataRowView in DataModel.ProposedOrder.UKProposedOrderAccountIdSecurityIdPositionTypeCode.FindRows(key))
                {
                    DataModel.ProposedOrderRow proposedProposedOrderRow = (DataModel.ProposedOrderRow)dataRowView.Row;
                    quantity += proposedProposedOrderRow.Quantity * proposedProposedOrderRow.TransactionTypeRow.QuantitySign;
                }
            }

            // Aggregate Order
            if ((quantityFlags & MarketValueFlags.IncludeOrder) != 0)
            {
                foreach (DataRowView dataRowView in DataModel.Order.UKOrderAccountIdSecurityIdPositionTypeCode.FindRows(key))
                {
                    DataModel.OrderRow orderRow = (DataModel.OrderRow)dataRowView.Row;
                    quantity += orderRow.Quantity * orderRow.TransactionTypeRow.QuantitySign;
                }
            }

            // Aggregate Allocation
            if ((quantityFlags & MarketValueFlags.IncludeAllocation) != 0)
            {
                foreach (DataRowView dataRowView in DataModel.Allocation.UKAllocationAccountIdSecurityIdPositionTypeCode.FindRows(key))
                {
                    DataModel.AllocationRow allocationRow = (DataModel.AllocationRow)dataRowView.Row;
                    quantity += allocationRow.Quantity * allocationRow.TransactionTypeRow.QuantitySign;
                }
            }

            // If sub-account are to be included, recurse into the account structures.
            if ((quantityFlags & MarketValueFlags.IncludeChildAccounts) != 0)
            {
                foreach (DataModel.ObjectTreeRow objectTreeRow in
                         accountRow.ObjectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId())
                {
                    foreach (DataModel.AccountRow childAccount in
                             objectTreeRow.ObjectRowByFKObjectObjectTreeChildId.GetAccountRows())
                    {
                        quantity += Calculate(childAccount, securityRow, positionTypeCode, quantityFlags);
                    }
                }
            }

            // This is the market value of the given account/security/position combination.
            return(quantity);
        }