Exemple #1
0
        /// <summary>
        /// Creates a sector element.
        /// </summary>
        /// <param name="appraisalDocument">The parent document.</param>
        /// <param name="sectorRow">The sector record used to create the Xml element.</param>
        public SectorElement(AppraisalDocument appraisalDocument, ClientMarketData.SectorRow sectorRow) :
            base("Sector", appraisalDocument)
        {
            // The sector id and name are taken directly from the SectorRow record.
            AddAttribute("SectorId", sectorRow.SectorId.ToString());
            AddAttribute("SortOrder", sectorRow.SortOrder.ToString());
            AddAttribute("Name", sectorRow.ObjectRow.Name.ToString());

            // If there is a target percentage associated with this sector, add it to the attribute list.
            ClientMarketData.SectorTargetRow sectorTargetRow =
                ClientMarketData.SectorTarget.FindByModelIdSectorId(appraisalDocument.ModelRow.ModelId,
                                                                    sectorRow.SectorId);
            if (sectorTargetRow != null)
            {
                AddAttribute("ModelPercent", sectorTargetRow.Percent.ToString());
            }

            // If there is a position record associated with this sector, 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, sectorRow.SectorId, Shadows.Quasar.Common.PositionType.Long);
            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());
                }
            }
        }
Exemple #2
0
        internal static Position Make(Account account, Security security, PositionType positionType)
        {
            Position position = new Position();

            // We can always create a position.  There may be no information associated with it, but it can be created just the
            // same.
            position.account      = account;
            position.security     = security;
            position.positionType = positionType;

            // Look up the position record.
            ClientMarketData.PositionRow positionRow =
                ClientMarketData.Position.FindByAccountIdSecurityIdPositionTypeCode(account.AccountId, security.SecurityId, (int)positionType);

            // If we have a record for the price/currency combination, then update it with the new price.
            if (positionRow != null)
            {
                if (!positionRow.IsUserData0Null())
                {
                    position.userData0 = positionRow.UserData0;
                }
                if (!positionRow.IsUserData1Null())
                {
                    position.userData1 = positionRow.UserData1;
                }
                if (!positionRow.IsUserData2Null())
                {
                    position.userData2 = positionRow.UserData2;
                }
                if (!positionRow.IsUserData3Null())
                {
                    position.userData3 = positionRow.UserData3;
                }
                if (!positionRow.IsUserData4Null())
                {
                    position.userData4 = positionRow.UserData4;
                }
                if (!positionRow.IsUserData5Null())
                {
                    position.userData5 = positionRow.UserData5;
                }
                if (!positionRow.IsUserData6Null())
                {
                    position.userData6 = positionRow.UserData6;
                }
                if (!positionRow.IsUserData7Null())
                {
                    position.userData7 = positionRow.UserData7;
                }
            }

            return(position);
        }
Exemple #3
0
        internal static Position Make(int accountId, int securityId, int positionTypeCode)
        {
            Position position = new Position();

            ClientMarketData.AccountRow accountRow =
                ClientMarketData.Account.FindByAccountId(accountId);
            if (accountRow == null)
            {
                throw new Exception(string.Format("Account {0} doesn't exist", accountId));
            }

            ClientMarketData.SecurityRow securityRow =
                ClientMarketData.Security.FindBySecurityId(securityId);
            if (securityRow == null)
            {
                throw new Exception(string.Format("Security {0} doesn't exist", securityId));
            }

            // Look up the position record.
            ClientMarketData.PositionRow positionRow =
                ClientMarketData.Position.FindByAccountIdSecurityIdPositionTypeCode(accountId, securityId, positionTypeCode);

            // We can always create a position.  There may be no information associated with it, but it can be created just the
            // same.
            position.account      = Account.Make(accountId);
            position.security     = Security.Make(securityId);
            position.positionType = (PositionType)positionTypeCode;

            // If we have a record for the price/currency combination, then update it with the new price.
            if (positionRow != null)
            {
                if (!positionRow.IsUserData0Null())
                {
                    position.userData0 = positionRow.UserData0;
                }
                if (!positionRow.IsUserData1Null())
                {
                    position.userData1 = positionRow.UserData1;
                }
                if (!positionRow.IsUserData2Null())
                {
                    position.userData2 = positionRow.UserData2;
                }
                if (!positionRow.IsUserData3Null())
                {
                    position.userData3 = positionRow.UserData3;
                }
                if (!positionRow.IsUserData4Null())
                {
                    position.userData4 = positionRow.UserData4;
                }
                if (!positionRow.IsUserData5Null())
                {
                    position.userData5 = positionRow.UserData5;
                }
                if (!positionRow.IsUserData6Null())
                {
                    position.userData6 = positionRow.UserData6;
                }
                if (!positionRow.IsUserData7Null())
                {
                    position.userData7 = positionRow.UserData7;
                }
            }

            return(position);
        }
Exemple #4
0
        /// <summary>
        /// Finds a position.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <param name="security">The security.</param>
        /// <param name="positionType">A Long or Short Position Type.</param>
        /// <returns>A Position.</returns>
        public Position(Account account, Security security, PositionType positionType)
        {
            // We can always create a position.  There may be no information associated with it, but it can be created just the
            // same.
            this.account      = account;
            this.security     = security;
            this.positionType = positionType;

            try
            {
                // Lock the tables.
                Debug.Assert(!ClientMarketData.AreLocksHeld);
                ClientMarketData.AccountLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PositionLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Look up the position record.
                ClientMarketData.PositionRow positionRow =
                    ClientMarketData.Position.FindByAccountIdSecurityIdPositionTypeCode(account.AccountId, security.SecurityId, (int)positionType);

                // If we have a record for the price/currency combination, then update it with the new price.
                if (positionRow != null)
                {
                    if (!positionRow.IsUserData0Null())
                    {
                        this.userData0 = positionRow.UserData0;
                    }
                    if (!positionRow.IsUserData1Null())
                    {
                        this.userData1 = positionRow.UserData1;
                    }
                    if (!positionRow.IsUserData2Null())
                    {
                        this.userData2 = positionRow.UserData2;
                    }
                    if (!positionRow.IsUserData3Null())
                    {
                        this.userData3 = positionRow.UserData3;
                    }
                    if (!positionRow.IsUserData4Null())
                    {
                        this.userData4 = positionRow.UserData4;
                    }
                    if (!positionRow.IsUserData5Null())
                    {
                        this.userData5 = positionRow.UserData5;
                    }
                    if (!positionRow.IsUserData6Null())
                    {
                        this.userData6 = positionRow.UserData6;
                    }
                    if (!positionRow.IsUserData7Null())
                    {
                        this.userData7 = positionRow.UserData7;
                    }
                }
            }
            finally
            {
                // Locks are no longer needed on the price table.
                if (ClientMarketData.AccountLock.IsReaderLockHeld)
                {
                    ClientMarketData.AccountLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PositionLock.IsReaderLockHeld)
                {
                    ClientMarketData.PositionLock.ReleaseReaderLock();
                }
                Debug.Assert(!ClientMarketData.AreLocksHeld);
            }
        }
Exemple #5
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));
            }
        }
Exemple #6
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));
            }
        }