Initial Commit
This commit is contained in:
49
PortfolioManager/Models/MovingAverageModel.cs
Normal file
49
PortfolioManager/Models/MovingAverageModel.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user