Skip to main content
5 of 6
edited tags
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Deleting parts of groups that does not have equal dates

Find the intersection of dates within the pair and remove the other dates & corresponding prices. Also keep the list in same format as it currently is in.

Let me explain: Each stock has closing dates and prices. There are many groups of 2 stocks in the list.(all unique pairs) Within each stock pair(group) I want to delete the dates and corresponding prices if the dates does not match both stocks(finding the intersection of dates within the pairs.)

Input: Subsets[Partition[tt, 2, 3], {2}]
Output: {{{{"AAD AT Equity", 
"Date", $Failed, {2013, 8, 1, 0, 0, 0.}, {2013, 8, 2, 0, 0, 
 0.}, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}}, {"", 
"PX_LAST", 0.82, 1.77, 1.75, 1.72, 1.71}}, {{"ABC AT Equity", 
"Date", $Failed, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}, 
"", ""}, {"", "PX_LAST", 0.6808, 3.33, 3.35, "", 
""}}}, {{{"AAD AT Equity", 
"Date", $Failed, {2013, 8, 1, 0, 0, 0.}, {2013, 8, 2, 0, 0, 
 0.}, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}}, {"", 
"PX_LAST", 0.82, 1.77, 1.75, 1.72, 1.71}}, {{"ABP AT Equity", 
"Date", $Failed, {2013, 8, 2, 0, 0, 0.}, {2013, 8, 5, 0, 0, 
 0.}, {2013, 8, 6, 0, 0, 0.}, ""}, {"", "PX_LAST", 5.3942, 2.22, 
2.2, 2.2, ""}}}, {{{"AAD AT Equity", 
"Date", $Failed, {2013, 8, 1, 0, 0, 0.}, {2013, 8, 2, 0, 0, 
 0.}, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}}, {"", 
"PX_LAST", 0.82, 1.77, 1.75, 1.72, 1.71}}, {{"ACR AT Equity", 
"Date", $Failed, {2013, 8, 6, 0, 0, 0.}, "", "", ""}, {"", 
"PX_LAST", 1., 3.32, "", "", ""}}}, {{{"ABC AT Equity", 
"Date", $Failed, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}, 
"", ""}, {"", "PX_LAST", 0.6808, 3.33, 3.35, "", 
""}}, {{"ABP AT Equity", 
"Date", $Failed, {2013, 8, 2, 0, 0, 0.}, {2013, 8, 5, 0, 0, 
 0.}, {2013, 8, 6, 0, 0, 0.}, ""}, {"", "PX_LAST", 5.3942, 2.22, 
2.2, 2.2, ""}}}, {{{"ABC AT Equity", 
"Date", $Failed, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}, 
"", ""}, {"", "PX_LAST", 0.6808, 3.33, 3.35, "", 
""}}, {{"ACR AT Equity", "Date", $Failed, {2013, 8, 6, 0, 0, 0.}, 
"", "", ""}, {"", "PX_LAST", 1., 3.32, "", "", 
""}}}, {{{"ABP AT Equity", 
"Date", $Failed, {2013, 8, 2, 0, 0, 0.}, {2013, 8, 5, 0, 0, 
 0.}, {2013, 8, 6, 0, 0, 0.}, ""}, {"", "PX_LAST", 5.3942, 2.22, 
2.2, 2.2, ""}}, {{"ACR AT Equity", 
"Date", $Failed, {2013, 8, 6, 0, 0, 0.}, "", "", ""}, {"", 
"PX_LAST", 1., 3.32, "", "", ""}}}}

For the first pair of stocks I want to end up with this correct result:

{{{"AAD AT Equity", 
"Date", $Failed,, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}}, {"", 
"PX_LAST", 0.82, 1.72, 1.71}}, {{"ABC AT Equity", 
"Date", $Failed, {2013, 8, 5, 0, 0, 0.}, {2013, 8, 6, 0, 0, 0.}, 
"", ""}, {"", "PX_LAST", 0.6808, 3.33, 3.35, "", 
""}}}

As you can see, what has happened is that AAD equity have lost it two first trading dates in the list and its corresponding close price, and we end up with a pair of stocks with equal number of corresponding dates, and each stock have same amount of closing prices.

Note: I want this to be done for each pair.

ALEXANDER
  • 1.2k
  • 8
  • 21