23 using System.Collections.Generic;
35 public CorporateFactorProvider(
string permtick, IEnumerable<CorporateFactorRow> data, DateTime? factorFileMinimumDate =
null) : base(permtick, data, factorFileMinimumDate)
54 if (factorDate.Date < searchDate.Date)
60 switch (dataNormalizationMode)
64 factor = factorFileRow.First().SplitFactor;
68 factor = factorFileRow.First().PriceScaleFactor;
71 throw new ArgumentOutOfRangeException();
88 if (splitDate.Date < searchDate.Date)
break;
112 priceFactorRatio = 0;
122 if (thisRow.PriceFactor != nextRow.PriceFactor)
124 priceFactorRatio = thisRow.PriceFactor / nextRow.PriceFactor;
125 referencePrice = thisRow.ReferencePrice;
159 if (thisRow.SplitFactor != nextRow.SplitFactor)
161 splitFactor = thisRow.SplitFactor / nextRow.SplitFactor;
162 referencePrice = thisRow.ReferencePrice;
178 var dividendsAndSplits =
new List<BaseData>();
181 Log.
Trace($
"{symbol} has no factors!");
182 return dividendsAndSplits;
189 var dividend = row.GetDividend(futureFactorFileRow, symbol, exchangeHours, decimalPlaces);
190 if (dividend.Distribution != 0m)
192 dividendsAndSplits.Add(dividend);
195 var split = row.GetSplit(futureFactorFileRow, symbol, exchangeHours);
196 if (split.SplitFactor != 1m)
198 dividendsAndSplits.Add(split);
201 futureFactorFileRow = row;
204 return dividendsAndSplits.OrderBy(d => d.Time.Date).ToList();
222 var factorFileRows =
new List<CorporateFactorRow>();
225 factorFileRows.Add(lastEntry);
229 var combinedData = splitsAndDividends.Concat(data)
230 .DistinctBy(e => $
"{e.GetType().Name}{e.Time.ToStringInvariant(DateFormat.EightCharacter)}")
231 .OrderByDescending(d => d.Time.Date);
233 foreach (var datum
in combinedData)
236 var split = datum as
Split;
238 if (dividend !=
null)
240 nextEntry = lastEntry.
Apply(dividend, exchangeHours);
241 lastEntry = nextEntry;
243 else if (split !=
null)
245 nextEntry = lastEntry.
Apply(split, exchangeHours);
246 lastEntry = nextEntry;
249 if (nextEntry !=
null)
252 if (nextEntry.
Date == factorFileRows.Last().Date)
254 factorFileRows[factorFileRows.Count - 1] = nextEntry;
258 factorFileRows.Add(nextEntry);
263 var firstFactorFileRow =
new CorporateFactorRow(firstEntry.Date, factorFileRows.Last().PriceFactor, factorFileRows.Last().SplitFactor, firstEntry.ReferencePrice == 0 ? 0 : firstEntry.ReferencePrice);
264 var existing = factorFileRows.FindIndex(row => row.Date == firstFactorFileRow.Date);
268 factorFileRows.Add(firstFactorFileRow);