這裏是pariList
(這是List of Tuple
)C#LINQ過濾元組的名單給定名單
List<Tuple<dynamic, dynamic>> PairList = new List<Tuple<dynamic, dynamic>> =
{({ Symbol = a, Close = 1.0, Date = 2/1/2016, Vol = 0 }, { Symbol = b, Close = 1.6, Date = 2/1/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.0, Date = 2/1/2016, Vol = 0 }, { Symbol = c, Close = 2.0, Date = 2/1/2016 , Vol = 0 })}
{({ Symbol = b, Close = 1.6, Date = 2/1/2016, Vol = 0 }, { Symbol = c, Close = 2.0, Date = 2/1/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.1, Date = 2/2/2016, Vol = 0 }, { Symbol = b, Close = 1.2, Date = 2/2/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.1, Date = 2/2/2016, Vol = 0 }, { Symbol = c, Close = 2.1, Date = 2/2/2016, Vol = 0 })}
{({ Symbol = b, Close = 1.2, Date = 2/2/2016, Vol = 0 }, { Symbol = c, Close = 2.1, Date = 2/2/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.4, Date = 2/3/2016, Vol = 0 }, { Symbol = b, Close = 1.4, Date = 2/3/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.4, Date = 2/3/2016, Vol = 0 }, { Symbol = c, Close = 1.4, Date = 2/3/2016, Vol = 0 })}
{({ Symbol = b, Close = 1.4, Date = 2/3/2016, Vol = 0 }, { Symbol = c, Close = 1.4, Date = 2/3/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.7, Date = 2/4/2016, Vol = 0.214285714285714 }, { Symbol = b, Close = 1.8, Date = 2/4/2016, Vol = 0.218217890235992 })}
{({ Symbol = a, Close = 1.7, Date = 2/4/2016, Vol = 0.214285714285714 }, { Symbol = c, Close = 2.7, Date = 2/4/2016, Vol = 0.464743364189122 })}
{({ Symbol = b, Close = 1.8, Date = 2/4/2016, Vol = 0.218217890235992 }, { Symbol = c, Close = 2.7, Date = 2/4/2016, Vol = 0.464743364189122 })}
{({ Symbol = a, Close = 1.8, Date = 2/5/2016, Vol = 0.122450941145067 }, { Symbol = b, Close = 1.2, Date = 2/5/2016, Vol = 0.169725025739105 })}
{({ Symbol = a, Close = 1.8, Date = 2/5/2016, Vol = 0.122450941145067 }, { Symbol = c, Close = 1.2, Date = 2/5/2016, Vol = 0.301649178342484 })}
{({ Symbol = b, Close = 1.2, Date = 2/5/2016, Vol = 0.169725025739105 }, { Symbol = c, Close = 1.2, Date = 2/5/2016, Vol = 0.301649178342484 })}
......
......
而現在,我在一個特殊的日子選擇一些對
var wantedCombinations = pairList
.Where(pair => pair.Item1.Date == Beginday)
.Select(pair => new { Item = pair, Volspread = Math.Abs(pair.Item1.Vol - pair.Item2.Vol) })
.OrderBy(o => o.Volspread)
.Take(FirstSelect)
.Select(item =>item.Item)
.ToList();
那麼如何使'pairList'只在每個日期離開wantedCombinations
中的那些選定對。 e.g
選擇{a, b}, {a, c}
,然後pairList
成爲
{({ Symbol = a, Close = 1.0, Date = 2/1/2016, Vol = 0 }, { Symbol = b, Close = 1.6, Date = 2/1/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.0, Date = 2/1/2016, Vol = 0 }, { Symbol = c, Close = 2.0, Date = 2/1/2016 , Vol = 0 })}
{({ Symbol = a, Close = 1.1, Date = 2/2/2016, Vol = 0 }, { Symbol = b, Close = 1.2, Date = 2/2/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.1, Date = 2/2/2016, Vol = 0 }, { Symbol = c, Close = 2.1, Date = 2/2/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.4, Date = 2/3/2016, Vol = 0 }, { Symbol = b, Close = 1.4, Date = 2/3/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.4, Date = 2/3/2016, Vol = 0 }, { Symbol = c, Close = 1.4, Date = 2/3/2016, Vol = 0 })}
{({ Symbol = a, Close = 1.7, Date = 2/4/2016, Vol = 0.214285714285714 }, { Symbol = b, Close = 1.8, Date = 2/4/2016, Vol = 0.218217890235992 })}
{({ Symbol = a, Close = 1.7, Date = 2/4/2016, Vol = 0.214285714285714 }, { Symbol = c, Close = 2.7, Date = 2/4/2016, Vol = 0.464743364189122 })}
{({ Symbol = a, Close = 1.8, Date = 2/5/2016, Vol = 0.122450941145067 }, { Symbol = b, Close = 1.2, Date = 2/5/2016, Vol = 0.169725025739105 })}
{({ Symbol = a, Close = 1.8, Date = 2/5/2016, Vol = 0.122450941145067 }, { Symbol = c, Close = 1.2, Date = 2/5/2016, Vol = 0.301649178342484 })}
......
......
而且最好是實現一個Linq查詢這兩個步驟?
@吉拉德格林,例如,我在2016年2月3日獲得了一對({a,2/3/2016},{c,2/3/2016}),({a,2/3/2016},{b,2/3/2016})',那麼我希望'pairList'每天只留下一對符號'{a,c},{a,b}'第三個代碼。 – user6703592