19 using System.Globalization;
22 using System.Collections.Generic;
32 private decimal _splitFactor;
33 private decimal _priceFactor;
38 public DateTime
Date {
get;
private set; }
53 UpdatePriceScaleFactor();
69 UpdatePriceScaleFactor();
86 public CorporateFactorRow(DateTime date, decimal priceFactor, decimal splitFactor, decimal referencePrice = 0)
100 public static List<CorporateFactorRow>
Parse(IEnumerable<string> lines, out DateTime? factorFileMinimumDate)
102 factorFileMinimumDate =
null;
104 var rows =
new List<CorporateFactorRow>();
107 foreach (var line
in lines)
112 if (line.Contains(
"inf") || line.Contains(
"e+"))
117 var row =
Parse(line);
120 if (row.PriceScaleFactor > 0)
128 factorFileMinimumDate = rows.Min(ffr => ffr.Date).AddDays(-1);
146 throw new ArgumentException(
"Unable to apply dividend with reference price of zero.");
153 if (
Date < previousTradingDay)
155 throw new ArgumentException(Invariant(
156 $
"Factor file row date '{Date:yyy-MM-dd}' is before dividend previous trading date '{previousTradingDay.Date:yyyy-MM-dd}'."
184 throw new ArgumentException(
"Unable to apply split with type warning. Only actual splits may be applied");
189 throw new ArgumentException(
"Unable to apply split with reference price of zero.");
196 if (
Date < previousTradingDay)
198 throw new ArgumentException(Invariant(
199 $
"Factor file row date '{Date:yyy-MM-dd}' is before split date '{split.Time.Date:yyyy-MM-dd}'."
224 throw new InvalidOperationException(Invariant(
225 $
"Unable to resolve dividend for '{symbol.ID}' at {Date:yyyy-MM-dd}. Price factor is zero."
253 throw new InvalidOperationException(Invariant(
254 $
"Unable to resolve split for '{symbol.ID}' at {Date:yyyy-MM-dd}. Split factor is zero."
275 var csv = line.Split(
',');
290 source = source ==
null ?
"" : $
",{source}";
291 return $
"{Date.ToStringInvariant(DateFormat.EightCharacter)}," +
292 Invariant($
"{Math.Round(PriceFactor, 7)},") +
293 Invariant($
"{Math.Round(SplitFactor, 8)},") +
294 Invariant($
"{Math.Round(ReferencePrice, 4).Normalize()}") +
307 return Invariant($
"{Date:yyyy-MM-dd}: {PriceScaleFactor:0.0000} {SplitFactor:0.0000}");
314 private void UpdatePriceScaleFactor()