using System; using System.Collections.Generic; using System.Linq; using Eremex.AvaloniaUI.Charts; using MarketData.MarketDataModel; using MarketData.MarketDataModel.GainLoss; using PortfolioManager.DataSeriesViewModels; namespace PortfolioManager.Models { public class MovingAverageModel { private MovingAverageModel() { } public static CompositeDataSource Empty() { CompositeDataSource compositeDataSource = new CompositeDataSource() { DataAdapter = new SortedDateTimeDataAdapter() }; return compositeDataSource; } /// /// Creates the moving average composite data source /// /// /// /// public static CompositeDataSource CreateCompositeDataSource(DMAValues dmaValues) { if (null == dmaValues) return Empty(); List sortedValues = new List(dmaValues.OrderBy(x => x.Date)); SortedDateTimeDataAdapter sortedDateTimeDataAdapter = new SortedDateTimeDataAdapter(); foreach (DMAValue dmaValue in sortedValues) { sortedDateTimeDataAdapter.Add(dmaValue.Date,dmaValue.MAValue); } CompositeDataSource compositeDataSource = new CompositeDataSource() { DataAdapter = sortedDateTimeDataAdapter }; return compositeDataSource; } } }