Пример #1
0
        /// <summary>
        /// Copies the outline of a security position from the data model into the AppraisalSet.
        /// </summary>
        /// <param name="AccountId">AccountId of the position to search through.</param>
        /// <param name="SecurityId">SecurityId of the position to search through.</param>
        /// <param name="PositionTypeCode">Position Type Code of the position to search through.</param>
        /// <remarks>
        /// Table locks needed:
        ///		Read:	Security
        /// </remarks>
        protected void BuildSecurity(int AccountId, int SecurityId, int PositionTypeCode)
        {
            // See if the given security exists already in the table of security.  If this is the first time we've
            // encountered this security, we need to add it to the driver tables and then recursively search the hierarchy
            // and add every parent sector all the way up to the security classification scheme.  If we've run across it
            // already, we don't need to do anything related to the security.
            AppraisalSet.SecurityRow driverSecurity = this.Security.FindBySecurityId(SecurityId);
            if (driverSecurity == null)
            {
                // The AppraisalSet structure mirrors the structure of the MarketData.  We have a common 'object' table that
                // all object can use to navigate the tree structure.  When adding a new element to the data structure,
                // we need to add the object first to maintain integrity, then the security can be added.
                AppraisalSet.ObjectRow objectRow = this.Object.AddObjectRow(SecurityId);
                driverSecurity = this.Security.AddSecurityRow(objectRow);

                // Recursively search the hierarchy all the way up to the security classification scheme.  This will add
                // any elements of the hierarchy that are not already part of the outline.  Note that we first check to
                // see if the security belongs to the given security scheme before building the links.  This saves us from
                // having unused fragments of other security scheme in the outline.  This is useful when checking for
                // unclassified security.
                DataModel.SecurityRow securityRow = DataModel.Security.FindBySecurityId(SecurityId);
                if (IsObjectInScheme(securityRow.ObjectRow))
                {
                    BuildSector(securityRow.ObjectRow);
                    BuildScheme(securityRow.ObjectRow);
                }
            }

            // At this point, we know that the security and all the sector have been added to the outline.  Check to see
            // if the position -- that is, the combination of security and whether we own it or have borrowed it -- exist
            // in the outline.  Add the combination if it doesn't.
            AppraisalSet.PositionRow positionRow = this.Position.FindBySecurityIdPositionTypeCode(SecurityId, PositionTypeCode);
            if (positionRow == null)
            {
                positionRow = this.Position.AddPositionRow(driverSecurity, PositionTypeCode);
            }

            // Finally, at the bottom of the list, is the account level information.  This operation insures that only distinct account/position combinations
            // appear in the document.  This is very useful if the same account were to appear in different groups.
            AppraisalSet.AccountRow driverAccount = this.Account.FindByAccountIdSecurityIdPositionTypeCode(AccountId, SecurityId, PositionTypeCode);
            if (driverAccount == null)
            {
                driverAccount = this.Account.AddAccountRow(AccountId, SecurityId, PositionTypeCode);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates an Equity Element for an Appriasal Document.
        /// </summary>
        /// <param name="appraisalDocument">The parent Xml Document.</param>
        /// <param name="equityRow">An equity record from the data model.</param>
        /// <param name="PositionTypeCode">Whether a short or long position.</param>
        public EquityElement(AppraisalDocument appraisalDocument, ClientMarketData.EquityRow equityRow,
                             AppraisalSet.PositionRow positionRow) : base("Equity", appraisalDocument)
        {
            // These records are used to access information held in the ancestors.
            ClientMarketData.SecurityRow securityRow = equityRow.SecurityRowByFKSecurityEquityEquityId;
            ClientMarketData.ObjectRow   objectRow   = securityRow.ObjectRow;

            // Add the essential attributes for this element.
            AddAttribute("SecurityId", equityRow.EquityId.ToString());
            AddAttribute("PositionTypeCode", positionRow.PositionTypeCode.ToString());
            AddAttribute("Name", objectRow.Name.ToString());
            AddAttribute("PriceFactor", securityRow.PriceFactor.ToString());
            AddAttribute("QuantityFactor", securityRow.QuantityFactor.ToString());

            // Find the price based on the default currency found in the equity record.  If the security master doesn't
            // have a price for this security, provide dummy values to insure a market value can be calculated.  Zero is a
            // perfectly reasonable interpretation of a missing price.
            ClientMarketData.PriceRow securityPrice = ClientMarketData.Price.FindBySecurityIdCurrencyId(
                securityRow.SecurityId, equityRow.SettlementId);
            if (securityPrice == null)
            {
                AddAttribute("Price", "0.0");
            }
            else
            {
                if (ClientPreferences.Pricing == Pricing.Close)
                {
                    AddAttribute("Price", securityPrice.ClosePrice.ToString());
                }
                if (ClientPreferences.Pricing == Pricing.Last)
                {
                    AddAttribute("Price", securityPrice.LastPrice.ToString());
                }
            }

            // Find the crossing price.  This is used to convert any local price into the account's base currency. Provide
            // defaults if the crossing price can be found.  While this will lead to wrong values, they will be obvious on
            // the appraisal.
            ClientMarketData.PriceRow currencyPrice = ClientMarketData.Price.FindBySecurityIdCurrencyId(
                equityRow.SettlementId, appraisalDocument.AccountRow.CurrencyRow.CurrencyId);
            if (currencyPrice == null)
            {
                AddAttribute("CloseCrossPrice", "0.0");
                AddAttribute("LastCrossPrice", "0.0");
            }
            else
            {
                AddAttribute("CloseCrossPrice", currencyPrice.ClosePrice.ToString());
                AddAttribute("LastCrossPrice", currencyPrice.LastPrice.ToString());
            }

            // Add a target percentage if one is associated with this security.
            ClientMarketData.PositionTargetRow positionTargetRow =
                ClientMarketData.PositionTarget.FindByModelIdSecurityIdPositionTypeCode(
                    appraisalDocument.ModelRow.ModelId, equityRow.EquityId, positionRow.PositionTypeCode);
            if (positionTargetRow != null)
            {
                AddAttribute("ModelPercent", positionTargetRow.Percent.ToString());
            }

            // If there is a position record associated with this, er..  position, then add the externally supplied data
            // to the record.  Since the tax lots are always aggregated as we need them into a position, there's no static
            // table that keeps position data.  This information is generally from an outside system that is related to
            // the position, such as risk metrics or quantitative calculations.
            ClientMarketData.PositionRow position = ClientMarketData.Position.FindByAccountIdSecurityIdPositionTypeCode(
                appraisalDocument.AccountRow.AccountId, positionRow.SecurityId, positionRow.PositionTypeCode);
            if (position != null)
            {
                if (!position.IsUserData0Null())
                {
                    AddAttribute("UserData0", position.UserData0.ToString());
                }
                if (!position.IsUserData1Null())
                {
                    AddAttribute("UserData1", position.UserData1.ToString());
                }
                if (!position.IsUserData2Null())
                {
                    AddAttribute("UserData2", position.UserData2.ToString());
                }
                if (!position.IsUserData3Null())
                {
                    AddAttribute("UserData3", position.UserData3.ToString());
                }
                if (!position.IsUserData4Null())
                {
                    AddAttribute("UserData4", position.UserData4.ToString());
                }
                if (!position.IsUserData5Null())
                {
                    AddAttribute("UserData5", position.UserData5.ToString());
                }
                if (!position.IsUserData6Null())
                {
                    AddAttribute("UserData6", position.UserData6.ToString());
                }
                if (!position.IsUserData7Null())
                {
                    AddAttribute("UserData7", position.UserData7.ToString());
                }
            }

            // Add the account level aggregates for this security/position type pair.
            foreach (AppraisalSet.AccountRow accountRow in positionRow.GetAccountRows())
            {
                this.AppendChild(new AccountElement(appraisalDocument, accountRow));
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a Currency Element for an Appraisal Document.
        /// </summary>
        /// <param name="appraisalDocument">The parent Xml Document.</param>
        /// <param name="currencyRow">A currency record in the data model.</param>
        /// <param name="PositionTypeCode">Whether a short or long position.</param>
        public CurrencyElement(AppraisalDocument appraisalDocument, ClientMarketData.CurrencyRow currencyRow,
                               AppraisalSet.PositionRow positionRow) : base("Currency", appraisalDocument)
        {
            // These records are used to access information held in the ancestors.
            ClientMarketData.SecurityRow securityRow = currencyRow.SecurityRow;
            ClientMarketData.ObjectRow   objectRow   = securityRow.ObjectRow;

            // Add the essential attributes for this element.
            AddAttribute("SecurityId", currencyRow.CurrencyId.ToString());
            AddAttribute("PositionTypeCode", positionRow.PositionTypeCode.ToString());
            AddAttribute("Name", objectRow.Name.ToString());

            // Add the price info.
            ClientMarketData.PriceRow priceRow =
                ClientMarketData.Price.FindBySecurityIdCurrencyId(securityRow.SecurityId,
                                                                  appraisalDocument.AccountRow.CurrencyRow.CurrencyId);
            if (priceRow == null)
            {
                AddAttribute("Price", "0.0");
            }
            else
            {
                if (ClientPreferences.Pricing == Pricing.Close)
                {
                    AddAttribute("Price", priceRow.ClosePrice.ToString());
                }
                if (ClientPreferences.Pricing == Pricing.Last)
                {
                    AddAttribute("Price", priceRow.LastPrice.ToString());
                }
            }

            // Add a target percentage if one is associated with this security.
            ClientMarketData.PositionTargetRow positionTargetRow =
                ClientMarketData.PositionTarget.FindByModelIdSecurityIdPositionTypeCode(
                    appraisalDocument.ModelRow.ModelId, currencyRow.CurrencyId, positionRow.PositionTypeCode);
            if (positionTargetRow != null)
            {
                AddAttribute("ModelPercent", positionTargetRow.Percent.ToString());
            }

            // If there is a position record associated with this, er..  position, then add the externally supplied data
            // to the record.  Since the tax lots are always aggregated as we need them into a position, there's no static
            // table that keeps position data.  This information is generally from an outside system that is related to
            // the position, such as risk metrics or quantitative calculations.
            ClientMarketData.PositionRow position = ClientMarketData.Position.FindByAccountIdSecurityIdPositionTypeCode(
                appraisalDocument.AccountRow.AccountId, positionRow.SecurityId, positionRow.PositionTypeCode);
            if (position != null)
            {
                if (!position.IsUserData0Null())
                {
                    AddAttribute("UserData0", position.UserData0.ToString());
                }
                if (!position.IsUserData1Null())
                {
                    AddAttribute("UserData1", position.UserData1.ToString());
                }
                if (!position.IsUserData2Null())
                {
                    AddAttribute("UserData2", position.UserData2.ToString());
                }
                if (!position.IsUserData3Null())
                {
                    AddAttribute("UserData3", position.UserData3.ToString());
                }
                if (!position.IsUserData4Null())
                {
                    AddAttribute("UserData4", position.UserData4.ToString());
                }
                if (!position.IsUserData5Null())
                {
                    AddAttribute("UserData5", position.UserData5.ToString());
                }
                if (!position.IsUserData6Null())
                {
                    AddAttribute("UserData6", position.UserData6.ToString());
                }
                if (!position.IsUserData7Null())
                {
                    AddAttribute("UserData7", position.UserData7.ToString());
                }
            }

            // Append the account level aggregates to this security/position type element.
            foreach (AppraisalSet.AccountRow accountRow in positionRow.GetAccountRows())
            {
                this.AppendChild(new AccountElement(appraisalDocument, accountRow));
            }
        }