/// <summary> /// Returns true if the specified date is the last trading day before a split event /// is to be fired /// </summary> /// <remarks> /// NOTE: The split event in the algorithm should be fired at the end or AFTER this /// date. This is the date in the file that a factor is applied, so for example MSFT /// has a split on 1999.03.29, but in the factor file the split factor is applied on /// 1999.03.26, which is the first trading day BEFORE the actual split date. /// </remarks> public bool HasSplitEventOnNextTradingDay(DateTime date, out decimal splitFactor) { splitFactor = 1; var index = SortedFactorFileData.IndexOfKey(date); if (index > -1 && index < SortedFactorFileData.Count - 1) { // grab the next key to ensure it's a split event var thisRow = SortedFactorFileData.Values[index]; var nextRow = SortedFactorFileData.Values[index + 1]; // if the split factors have changed then it's a split event if (thisRow.SplitFactor != nextRow.SplitFactor) { splitFactor = thisRow.SplitFactor / nextRow.SplitFactor; return(true); } } return(false); }
/// <summary> /// Returns true if the specified date is the last trading day before a dividend event /// is to be fired /// </summary> /// <remarks> /// NOTE: The dividend event in the algorithm should be fired at the end or AFTER /// this date. This is the date in the file that a factor is applied, so for example, /// MSFT has a 31 cent dividend on 2015.02.17, but in the factor file the factor is applied /// to 2015.02.13, which is the first trading day BEFORE the actual effective date. /// </remarks> /// <param name="date">The date to check the factor file for a dividend event</param> /// <param name="priceFactorRatio">When this function returns true, this value will be populated /// with the price factor ratio required to scale the closing value (pf_i/pf_i+1)</param> public bool HasDividendEventOnNextTradingDay(DateTime date, out decimal priceFactorRatio) { priceFactorRatio = 0; var index = SortedFactorFileData.IndexOfKey(date); if (index > -1 && index < SortedFactorFileData.Count - 1) { // grab the next key to ensure it's a dividend event var thisRow = SortedFactorFileData.Values[index]; var nextRow = SortedFactorFileData.Values[index + 1]; // if the price factors have changed then it's a dividend event if (thisRow.PriceFactor != nextRow.PriceFactor) { priceFactorRatio = thisRow.PriceFactor / nextRow.PriceFactor; return(true); } } return(false); }