// create filters 
 public EventsPostFilterGroup BuildEventsPostFilterGroup(RetrieveEventDataDelegate retrieveDataForEvents)
 {
     var filterTopGroup = new EventsPostFilterGroup();
     var subEventGroups = postFilterGroupViewModelList.Select(gp => gp.BuildEventsPostFilterGroup(retrieveDataForEvents));
     foreach (var eventsPostFilter in subEventGroups)
     {
         filterTopGroup.AddFilterToGroup(eventsPostFilter);
     }
     return filterTopGroup;
 }
 // create filters 
 public EventsPostFilterGroup BuildEventsPostFilterGroup(RetrieveEventDataDelegate retrieveDataForEvents)
 {
     var currentGroup = new EventsPostFilterGroup();            
     //var postFilters = postFilterItemViewModelList.Select(item => item.BuildEventsPostFilterFromModel(eventControl.RetrieveDataForEvents));
     
     var earliestYear = eventControl.EarliestPreSelectedYear;
       
     var postFilters = postFilterItemViewModelList.Select(item => item.BuildEventsPostFilterFromModel(earliestYear, retrieveDataForEvents));
     foreach (var eventsPostFilter in postFilters)
     {
         currentGroup.AddFilterToGroup(eventsPostFilter);
     }
     currentGroup.LogicalOp = LogicalOp;
     return currentGroup;
 }
        public DateTime[] GenerateFilteredDates(EventsPostFilterGroup filter)
        {
            if(eventDates == null || !eventDates.Any())
                return null;;

            return eventDates.Where(filter.IsMatch).ToArray();            
        }
        public IEnumerable<Tuple<string, DateTime, DatedDataCollectionGen<double>>> GenerateFilteredEvents(EventsPostFilterGroup filter)
        {
            if (eventDates == null || !eventDates.Any())
                yield return null;
                        
            if (eventDates != null)
                foreach (var eventDate in eventDates)
                {
                    if (filter.IsMatch(eventDate))
                    {
                        var date = eventDate;
                        foreach (var matchFilter in filter.MatchFilterNames(eventDate).Select((filterName, i) => new { filterName, r=filter.RetreiveRawDataForFilter(date)[i] }))
                        {
                            yield return new Tuple<string, DateTime, DatedDataCollectionGen<double>>(matchFilter.filterName, eventDate, matchFilter.r.Item2);
                        }
                    }

                }
        }
        public void ShouldFilterMovementOnEvents()
        {
            var eventDates = new DateTime[]
            {
                new DateTime(2015, 01, 30),
                new DateTime(2015, 02, 27),
                new DateTime(2015, 03, 31),
                new DateTime(2015, 04, 30),
                new DateTime(2015, 05, 29),
                new DateTime(2015, 06, 30),
                new DateTime(2015, 07, 31),
                new DateTime(2015, 08, 31),
                new DateTime(2015, 09, 30),
                new DateTime(2015, 10, 30),                
            };
            var eventBuilder = Singleton<EventFilterBuilder>.Instance;
            eventBuilder.eventDates = eventDates;

            var postFilter1 = eventBuilder.SdUpMove(FilterOperator.Greater, 1, 5, retrieveDataForEvents);

            // set up filter group            
            var filterTopGroup = new EventsPostFilterGroup();
            filterTopGroup.AddFilterToGroup(postFilter1);
            filterTopGroup.LogicalOp = LogicalOperator.And;
            
            var filteredEventDates = eventBuilder.GenerateFilteredDates(filterTopGroup);

            Assert.That(filteredEventDates.Any(), Is.True);
            Assert.That(filteredEventDates.First(), Is.EqualTo(new DateTime(2015, 08, 31)));
        }
        public void ShouldFilterRSIEvents()
        {
            var eventDates = new DateTime[]
            {
                new DateTime(2015, 01, 30),
                new DateTime(2015, 02, 27),
                new DateTime(2015, 03, 31),
                new DateTime(2015, 04, 30),
                new DateTime(2015, 05, 29),
                new DateTime(2015, 06, 30),
                new DateTime(2015, 07, 31),
                new DateTime(2015, 08, 31),
                new DateTime(2015, 09, 30),
                new DateTime(2015, 10, 30),                
            };
            var cc = new SI.Strategy.SeasonalityAnalysis.MultiProductParser.SeasonalityPlugin2();
            cc.Create();

            // set up instrument for testing
            cc.SetUpWrapper(ParserType.CMT_Yield, "UST1_2");
           

            var postFilter1 = EventFilterBuilder.RSIRise(FilterOperator.Greater, 30, 5, retrieveDataForEvents);            

            // set up filter group            
            var filterTopGroup = new EventsPostFilterGroup();
            filterTopGroup.AddFilterToGroup(postFilter1);            
            filterTopGroup.LogicalOp = LogicalOperator.And;

            var eventBuilder = new EventFilterBuilder {eventDates = eventDates};
            var filteredEventDates = eventBuilder.GenerateFilteredDates(filterTopGroup);

            Assert.That(filteredEventDates.Any(), Is.True);
            Assert.That(filteredEventDates.First(), Is.EqualTo(new DateTime(2015,09,30)));
        }
 public void AddFilterToGroup(EventsPostFilterGroup filterItem)
 {
     filterList.Add(filterItem);
 }