49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates the moving average composite data source
|
|
/// </summary>
|
|
/// <param name="gainLossList"></param>
|
|
/// <param name="useGainLoss"></param>
|
|
/// <returns></returns>
|
|
public static CompositeDataSource CreateCompositeDataSource(DMAValues dmaValues)
|
|
{
|
|
if (null == dmaValues) return Empty();
|
|
List<DMAValue> sortedValues = new List<DMAValue>(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;
|
|
}
|
|
}
|
|
} |