refactor(dotnet): normalize factor input dates
This commit is contained in:
@@ -26,8 +26,8 @@ namespace QuantEngine.Core.Domain
|
||||
return new FactorOutputs(0, 0, 0, 0, 0, 1.0, 0);
|
||||
}
|
||||
|
||||
var sortedStock = stockBars.OrderBy(b => b.TradeDate).ToList();
|
||||
var sortedIndex = indexBars?.OrderBy(b => b.TradeDate).ToList() ?? new List<PriceHistoryDailyRecord>();
|
||||
var sortedStock = NormalizeBars(stockBars);
|
||||
var sortedIndex = NormalizeBars(indexBars);
|
||||
return new FactorOutputs(
|
||||
CalculateMomentum(sortedStock, 20),
|
||||
CalculateMomentum(sortedStock, 60),
|
||||
@@ -38,6 +38,20 @@ namespace QuantEngine.Core.Domain
|
||||
CalculateRs20D(sortedStock, sortedIndex));
|
||||
}
|
||||
|
||||
private static List<PriceHistoryDailyRecord> NormalizeBars(List<PriceHistoryDailyRecord>? bars)
|
||||
{
|
||||
if (bars == null || bars.Count == 0)
|
||||
{
|
||||
return new List<PriceHistoryDailyRecord>();
|
||||
}
|
||||
|
||||
return bars
|
||||
.OrderBy(b => b.TradeDate)
|
||||
.GroupBy(b => b.TradeDate)
|
||||
.Select(g => g.Last())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static double CalculateMomentum(List<PriceHistoryDailyRecord> bars, int period)
|
||||
{
|
||||
if (bars.Count <= period) return 0.0;
|
||||
|
||||
Reference in New Issue
Block a user