Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi firends,
I need to get a list of accrued AccruedInterest based upon on the input values.
There will be three AccruedInterest under PositionDetail . one from the PositionDetail and other two from sub nodes SubAccountDetail

i have written some code to filter but its not working
here is my code
Please help.

C#
public static List<double> serviceaccrued(string cusip,string office,string account,string xmlstring)
     {
         XDocument doc = XDocument.Parse(xmlstring);
         List<double> aacruedlist = doc.Descendants("PositionSummary")
                      .Where(item =>
                      {
                          string cus = (string)item.Element("Cusip");
                          string ofc = (string)item.Element("PositionDetail").Element("Office").Value;
                          string acc = (string)item.Element("PositionDetail").Element("Account").Value;
                          return cus != null && cus == cusip && ofc == office && acc == account;
                      })
                      .ToList().Descendants("AccruedInterest")
                      .Select(acc => Convert.ToDouble(acc.Value)).ToList<double>();
         return aacruedlist;
     }


This is my XML formart
XML
<PositionSummary>
     <Symbol/>
     <SecurityDescription>AXA SUBORDINATED NOTES</SecurityDescription>
     <LatestPrice>134.77500000</LatestPrice>
     <UnitPrice>1.3477500000</UnitPrice>
     <ClosingPrice>1.3477500000</ClosingPrice>
     <SubIssueType>1</SubIssueType>
     <PriceFactor>1.0000000</PriceFactor>
     <MSDWSecurityCode>0000TBY37</MSDWSecurityCode>
     <IsRealTime>false</IsRealTime>
     <Cusip>054536AA5</Cusip>
     <CouponPercent>8.6000</CouponPercent>
     <MaturityDate>2030-12-15T00:00:00-05:00</MaturityDate>
     <CallPercent>0.000</CallPercent>
     <MoodyRating>A3</MoodyRating>
     <SNPRating>BBB</SNPRating>
     <Prerefunded>false</Prerefunded>
     <LineNumber>38</LineNumber>
     <IsExternal>false</IsExternal>
     <IsOpen>false</IsOpen>
     <PositionDetail>
       <Office>658</Office>
       <Account>123906</Account>
       <AccountType>1</AccountType>
       <SubIssueType>1</SubIssueType>
       <Quantity>0.000000</Quantity>
       <MarketValue>0.00000000000000000000000</MarketValue>
       <TradableQuanity>0.000000</TradableQuanity>
       <AccruedInterest>0.000000000000000000000</AccruedInterest>
       <PayDate>2015-06-15T00:00:00-04:00</PayDate>
       <IsExternalAccount>false</IsExternalAccount>
       <IsOpenOrder>false</IsOpenOrder>
       <PCTYield>6.38</PCTYield>
       <GainLossPercent>0</GainLossPercent>
       <MarginIndicator>1</MarginIndicator>
       <IssueTypeString>CORBND</IssueTypeString>
       <KeyAccount>2012-07-04-03.00.02.680996</KeyAccount>
       <ShowTotalCost>false</ShowTotalCost>
       <CostBaseAvailable>false</CostBaseAvailable>
       <CostBaseEditable>true</CostBaseEditable>
       <TradeControl>0</TradeControl>
       <LineNumber>35</LineNumber>
       <StrikePrice>0.00000</StrikePrice>
       <DivCGReinvest>-</DivCGReinvest>
       <SubAccountDetail>
         <DisciplineType>137</DisciplineType>
         <Quantity>-100000.000000</Quantity>
         <MarketValue>-134775.00000000000000000000000</MarketValue>
         <TradableQuanity>-100000.000000</TradableQuanity>
         <ShowTotalCost>false</ShowTotalCost>
         <CostBaseAvailable>false</CostBaseAvailable>
         <CostBaseEditable>true</CostBaseEditable>
         <LineNumber>33</LineNumber>
         <DivCGReinvest>-</DivCGReinvest>
         <PositionIndicator>S</PositionIndicator>
         <SafeKeepingQuantity>0.000000</SafeKeepingQuantity>
         <AccruedInterest>-883.889000000000000000000</AccruedInterest>
       </SubAccountDetail>
       <SubAccountDetail>
         <AccountType>1</AccountType>
         <DisciplineType>137</DisciplineType>
         <Quantity>100000.000000</Quantity>
         <MarketValue>134775.00000000000000000000000</MarketValue>
         <TradableQuanity>100000.000000</TradableQuanity>
         <ShowTotalCost>false</ShowTotalCost>
         <CostBaseAvailable>false</CostBaseAvailable>
         <CostBaseEditable>true</CostBaseEditable>
         <LineNumber>34</LineNumber>
         <DivCGReinvest>-</DivCGReinvest>
         <PositionIndicator>M</PositionIndicator>
         <SafeKeepingQuantity>0.000000</SafeKeepingQuantity>
         <AccruedInterest>883.889000000000000000000</AccruedInterest>
       </SubAccountDetail>
       <PositionIndicator>S</PositionIndicator>
       <SortName>BARTA                         </SortName>
       <ValuationDate>0001-01-01T00:00:00</ValuationDate>
       <IsAdvisory>false</IsAdvisory>
       <AdvisoryText>Non-Advisory</AdvisoryText>
       <SafeKeepingQuantity>0.000000</SafeKeepingQuantity>
       <TrakEligible/>
       <ExtAssetCustodianType>MSWM</ExtAssetCustodianType>
       <FXCcy>USD</FXCcy>
     </PositionDetail>
     <PositionDetail>
       <Office>658</Office>
       <Account>124040</Account>
       <AccountType>1</AccountType>
       <SubIssueType>1</SubIssueType>
       <Quantity>0.000000</Quantity>
       <MarketValue>0.00000000000000000000000</MarketValue>
       <TradableQuanity>0.000000</TradableQuanity>
       <AccruedInterest>0.000000000000000000000</AccruedInterest>
       <PayDate>2015-06-15T00:00:00-04:00</PayDate>
       <IsExternalAccount>false</IsExternalAccount>
       <IsOpenOrder>false</IsOpenOrder>
       <PCTYield>6.38</PCTYield>
       <GainLossPercent>0</GainLossPercent>
       <MarginIndicator>1</MarginIndicator>
       <IssueTypeString>CORBND</IssueTypeString>
       <KeyAccount>2012-07-04-03.00.02.681134</KeyAccount>
       <ShowTotalCost>false</ShowTotalCost>
       <CostBaseAvailable>false</CostBaseAvailable>
       <CostBaseEditable>true</CostBaseEditable>
       <TradeControl>0</TradeControl>
       <LineNumber>38</LineNumber>
       <StrikePrice>0.00000</StrikePrice>
       <DivCGReinvest>-</DivCGReinvest>
       <SubAccountDetail>
         <AccountType>1</AccountType>
         <DisciplineType>137</DisciplineType>
         <Quantity>100000.000000</Quantity>
         <MarketValue>134775.00000000000000000000000</MarketValue>
         <TradableQuanity>100000.000000</TradableQuanity>
         <ShowTotalCost>false</ShowTotalCost>
         <CostBaseAvailable>false</CostBaseAvailable>
         <CostBaseEditable>true</CostBaseEditable>
         <LineNumber>36</LineNumber>
         <DivCGReinvest>-</DivCGReinvest>
         <PositionIndicator>M</PositionIndicator>
         <SafeKeepingQuantity>0.000000</SafeKeepingQuantity>
         <AccruedInterest>883.889000000000000000000</AccruedInterest>
       </SubAccountDetail>
       <SubAccountDetail>
         <DisciplineType>137</DisciplineType>
         <Quantity>-100000.000000</Quantity>
         <MarketValue>-134775.00000000000000000000000</MarketValue>
         <TradableQuanity>-100000.000000</TradableQuanity>
         <ShowTotalCost>false</ShowTotalCost>
         <CostBaseAvailable>false</CostBaseAvailable>
         <CostBaseEditable>true</CostBaseEditable>
         <LineNumber>37</LineNumber>
         <DivCGReinvest>-</DivCGReinvest>
         <PositionIndicator>S</PositionIndicator>
         <SafeKeepingQuantity>0.000000</SafeKeepingQuantity>
         <AccruedInterest>-883.889000000000000000000</AccruedInterest>
       </SubAccountDetail>
       <PositionIndicator>M</PositionIndicator>
       <SortName>MORDINOIAJ                    </SortName>
       <ValuationDate>0001-01-01T00:00:00</ValuationDate>
       <IsAdvisory>false</IsAdvisory>
       <AdvisoryText>Non-Advisory</AdvisoryText>
       <SafeKeepingQuantity>0.000000</SafeKeepingQuantity>
       <TrakEligible/>
       <ExtAssetCustodianType>MSWM</ExtAssetCustodianType>
       <FXCcy>USD</FXCcy>
     </PositionDetail>
     <Subtotal>
       <Quantity>-100000.000000</Quantity>
       <MarketValue>-134775.00000000000000000000000</MarketValue>
       <AccruedInterest>0.000000000000000000000</AccruedInterest>
       <ShowTotalCost>false</ShowTotalCost>
       <LineNumber>39</LineNumber>
     </Subtotal>
     <Sector>-</Sector>
     <NSTDUnitOptionCode/>
     <IsStructuredProduct>false</IsStructuredProduct>
   </PositionSummary>


Thanks in advance
Posted
Comments
barneyman 23-Jul-15 7:05am    
have a look at xpath queries

You need to apply filter on PositionDetail instead of PositionSummary.

Try the code below, it will work in your scenario:
C#
List<double> aacruedlist = doc.Descendants("PositionSummary").ToList().Descendants("PositionDetail")
.Where(item =>
{
   string cus = (string)item.Parent.Element("Cusip");
   string ofc = (string)item.Element("Office").Value;
   string acc = (string)item.Element("Account").Value;
   return cus != null && cus == cusip && ofc == office && acc == account;
}).ToList().Descendants("AccruedInterest")
.Select(acc => Convert.ToDouble(acc.Value)).ToList<double>();</double></double>
 
Share this answer
 
Comments
jinesh sam 23-Jul-15 14:55pm    
Here the cusip is under PositionSummary not under PositionDetail
So the where condition will work?
Abhipal Singh 23-Jul-15 15:34pm    
Yes, it will work "string cus = (string)item.Parent.Element("Cusip");" statement will read the Cusip from PositionDetail's parent, which is PositionSummary.
To get duplicates, try this:

C#
var doubles = xdoc.Descendants("PositionDetail")
            .Descendants("AccruedInterest")
            .GroupBy(item=>item.Value)
            .Select(grp=>new
            {
                AccruedInterest = grp.Key,
                Count = grp.Count()
            });


Result:
AccruedInterest               Count
0.000000000000000000000       2
-883.889000000000000000000    2
883.889000000000000000000     2
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900