/// <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); } }
/// <summary> /// Creates an element in the Appraisal Document that represents a fund's or account's position. /// </summary> /// <param name="appraisalDocument">The parent document.</param> /// <param name="driverAccount">Identifies the individual position at the account/security/position level.</param> public AccountElement(AppraisalDocument appraisalDocument, AppraisalSet.AccountRow driverAccount) : base("Account", appraisalDocument) { // Get the account record from the account id. This record drives most of the data that appears in this element. ClientMarketData.AccountRow accountRow = ClientMarketData.Account.FindByAccountId(driverAccount.AccountId); // Count up the compliance violations int violationCount = 0; foreach (DataRowView dataRowView in ClientMarketData.Violation.UKViolationAccountIdSecurityIdPositionTypeCode.FindRows( new object[] { driverAccount.AccountId, driverAccount.SecurityId, driverAccount.PositionTypeCode })) { ClientMarketData.ViolationRow violationRow = (ClientMarketData.ViolationRow)dataRowView.Row; if (violationRow.RestrictionRow.Severity > 0) { violationCount++; } } AddAttribute("Violation", violationCount); // Add the essential attributes to the element. AddAttribute("AccountId", accountRow.AccountId.ToString()); // Aggregate the tax lot positions and cost. decimal taxLotQuantity = 0.0M; decimal taxLotCost = 0.0M; foreach (ClientMarketData.TaxLotRow taxLotRow in accountRow.GetTaxLotRows()) { if (taxLotRow.SecurityId == driverAccount.SecurityId && taxLotRow.PositionTypeCode == driverAccount.PositionTypeCode) { taxLotQuantity += taxLotRow.Quantity; taxLotCost += taxLotRow.Cost * taxLotRow.Quantity; } } AddAttribute("TaxLotQuantity", taxLotQuantity.ToString()); AddAttribute("TaxLotCost", taxLotCost.ToString()); // Aggregate the proposed orders positions. decimal proposedOrderQuantity = 0.0M; foreach (DataRowView dataRowView in appraisalDocument.proposedOrderView.FindRows(new object[] { driverAccount.AccountId, driverAccount.SecurityId, driverAccount.PositionTypeCode })) { ClientMarketData.ProposedOrderRow proposedOrderRow = (ClientMarketData.ProposedOrderRow)dataRowView.Row; proposedOrderQuantity += proposedOrderRow.Quantity * proposedOrderRow.TransactionTypeRow.QuantitySign; } AddAttribute("ProposedOrderQuantity", proposedOrderQuantity.ToString()); // Aggregate the orders. decimal orderQuantity = 0.0M; foreach (DataRowView dataRowView in appraisalDocument.orderView.FindRows(new object[] { driverAccount.AccountId, driverAccount.SecurityId, driverAccount.PositionTypeCode })) { ClientMarketData.OrderRow orderRow = (ClientMarketData.OrderRow)dataRowView.Row; orderQuantity += orderRow.Quantity * orderRow.TransactionTypeRow.QuantitySign; } AddAttribute("OrderQuantity", orderQuantity.ToString()); // Aggregate the allocations. decimal allocationQuantity = 0.0M; foreach (DataRowView dataRowView in appraisalDocument.allocationView.FindRows(new object[] { driverAccount.AccountId, driverAccount.SecurityId, driverAccount.PositionTypeCode })) { ClientMarketData.AllocationRow allocationRow = (ClientMarketData.AllocationRow)dataRowView.Row; allocationQuantity += allocationRow.Quantity * allocationRow.TransactionTypeRow.QuantitySign; } AddAttribute("AllocationQuantity", allocationQuantity.ToString()); }