using System; using System.Linq; using System.Collections.Generic; using System.Text; using MarketData.Numerical; using MarketData.Utils; namespace MarketData.MarketDataModel { public class TimeSeriesCollection : List { public TimeSeriesCollection() { } public TimeSeriesCollection(List elements) { if (null == elements) return; foreach (TimeSeriesElement element in elements) Add(element); } // Returns the intersection of both sets on the common dates public static AlignDatesResult AlignDates(TimeSeriesCollection tsA,TimeSeriesCollection tsB) { List tsADates=(from ts in tsA select ts.AsOf).ToList(); List tsBDates=(from ts in tsB select ts.AsOf).ToList(); List tsIntersect=tsADates.Intersect(tsBDates).Distinct().ToList(); tsA=new TimeSeriesCollection((from ts in tsA where tsIntersect.Any(x=>x.Equals(ts.AsOf)) select ts).ToList()); tsB=new TimeSeriesCollection((from ts in tsB where tsIntersect.Any(x=>x.Equals(ts.AsOf)) select ts).ToList()); return new AlignDatesResult(tsA,tsB); } public float[] ToFloat() { float[] values = new float[Count]; for (int index = 0; index < Count; index++) values[index] = (float)this[index].Value; return values; } public bool ContainsNegativeValues() { int count= (from TimeSeriesElement element in this where element.Value < 0 select element).Count(); return count > 0 ? true : false; } public TimeSeriesCollection RemoveNegativeValues() { return new TimeSeriesCollection((from TimeSeriesElement element in this where element.Value >= 0 select element).ToList()); } public override String ToString() { StringBuilder sb=new StringBuilder(); if(0==this.Count)return null; sb.Append(TimeSeriesElement.StringForType(this[0].Type)); sb.Append(","); for(int index=0;index