public void AppliesSplitWithPreviousTradingDateEqualToRowDate() { var row = new CorporateFactorRow(new DateTime(2018, 08, 23), 1m, 2m, 123m); var dividend = new Split(Symbols.SPY, row.Date.AddDays(1), 123m, 2m, SplitType.SplitOccurred); var updated = row.Apply(dividend, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork)); Assert.AreEqual("20180823,1,4,123", updated.GetFileFormat()); }
public void ToCsv() { var row = new CorporateFactorRow(new DateTime(2000, 01, 01), 1m, 2m, 123m); var actual = row.GetFileFormat("source"); var expected = "20000101,1,2,123,source"; Assert.AreEqual(expected, actual); }
private static CorporateFactorProvider GetFactorFile_LODE20191127() { const string factorFileContents = @" 19980102,1,5,8.5,qq 20171109,1,5,0.12,qq 20501231,1,1,0,qq "; DateTime? factorFileMinimumDate; var reader = new StreamReader(factorFileContents.ToStream()); var enumerable = new StreamReaderEnumerable(reader).Where(line => line.Length > 0); var factorFileRows = CorporateFactorRow.Parse(enumerable, out factorFileMinimumDate); return(new CorporateFactorProvider("lode", factorFileRows, factorFileMinimumDate)); }
/// <summary> /// Calculates the split factor of a <see cref="Split"/> /// </summary> /// <param name="split">The next <see cref="Split"/></param> /// <param name="previousCorporateFactorRow">The previous <see cref="CorporateFactorRow"/> generated</param> /// <returns><see cref="CorporateFactorRow"/> that represents the split event</returns> private CorporateFactorRow CalculateNextSplitFactor(BaseData split, CorporateFactorRow previousCorporateFactorRow) { var eventDayData = GetDailyDataForDate(split.Time); // If you don't have the equity data nothing can be done if (eventDayData == null) { return(null); } TradeBar previousClosingPrice = FindPreviousTradableDayClosingPrice(eventDayData.Time); return(new CorporateFactorRow( previousClosingPrice.Time, previousCorporateFactorRow.PriceFactor, (previousCorporateFactorRow.SplitFactor / split.Value).RoundToSignificantDigits(6), previousClosingPrice.Close )); }
private static CorporateFactorProvider GetFactorFile_AAPL2018_05_11() { const string factorFileContents = @" 19980102,0.8893653,0.0357143,16.25 20000620,0.8893653,0.0357143,101 20050225,0.8893653,0.0714286,88.97 20120808,0.8893653,0.142857,619.85 20121106,0.8931837,0.142857,582.85 20130206,0.8972636,0.142857,457.285 20130508,0.9024937,0.142857,463.71 20130807,0.908469,0.142857,464.94 20131105,0.9144679,0.142857,525.58 20140205,0.9198056,0.142857,512.59 20140507,0.9253111,0.142857,592.34 20140606,0.9304792,0.142857,645.57 20140806,0.9304792,1,94.96 20141105,0.9351075,1,108.86 20150204,0.9391624,1,119.55 20150506,0.9428692,1,125.085 20150805,0.9468052,1,115.4 20151104,0.9510909,1,122.01 20160203,0.9551617,1,96.34 20160504,0.9603451,1,94.19 20160803,0.9661922,1,105.8 20161102,0.9714257,1,111.6 20170208,0.9764128,1,132.04 20170510,0.9806461,1,153.26 20170809,0.9846939,1,161.1 20171109,0.9885598,1,175.87 20180208,0.9921138,1,155.16 20180510,0.9961585,1,190.03 20501231,1,1,0 "; DateTime?factorFileMinimumDate; var reader = new StreamReader(factorFileContents.ToStream()); var enumerable = new StreamReaderEnumerable(reader).Where(line => line.Length > 0); var factorFileRows = CorporateFactorRow.Parse(enumerable, out factorFileMinimumDate); return(new CorporateFactorProvider("aapl", factorFileRows, factorFileMinimumDate)); }
// AAPL experiences a 0.73 dividend distribution on 2018.05.11 private static CorporateFactorProvider GetFactorFile_AAPL2018_05_08() { const string factorFileContents = @" 19980102,0.8927948,0.0357143,16.25 20000620,0.8927948,0.0357143,101 20050225,0.8927948,0.0714286,88.97 20120808,0.8927948,0.142857,619.85 20121106,0.8966279,0.142857,582.85 20130206,0.9007235,0.142857,457.285 20130508,0.9059737,0.142857,463.71 20130807,0.9119721,0.142857,464.94 20131105,0.9179942,0.142857,525.58 20140205,0.9233525,0.142857,512.59 20140507,0.9288793,0.142857,592.34 20140606,0.9340673,0.142857,645.57 20140806,0.9340673,1,94.96 20141105,0.9387135,1,108.86 20150204,0.942784,1,119.55 20150506,0.9465051,1,125.085 20150805,0.9504563,1,115.4 20151104,0.9547586,1,122.01 20160203,0.9588451,1,96.34 20160504,0.9640485,1,94.19 20160803,0.9699181,1,105.8 20161102,0.9751718,1,111.6 20170208,0.9801781,1,132.04 20170510,0.9844278,1,153.26 20170809,0.9884911,1,161.1 20171109,0.992372,1,175.87 20180208,0.9959397,1,155.16 20501231,1,1,0 "; DateTime?factorFileMinimumDate; var reader = new StreamReader(factorFileContents.ToStream()); var enumerable = new StreamReaderEnumerable(reader).Where(line => line.Length > 0); var factorFileRows = CorporateFactorRow.Parse(enumerable, out factorFileMinimumDate); return(new CorporateFactorProvider("aapl", factorFileRows, factorFileMinimumDate)); }
/// <summary> /// Calculates the price factor of a <see cref="Dividend"/> /// </summary> /// <param name="dividend">The next dividend</param> /// <param name="previousCorporateFactorRow">The previous <see cref="CorporateFactorRow"/> generated</param> /// <returns><see cref="CorporateFactorRow"/> that represents the dividend event</returns> private CorporateFactorRow CalculateNextDividendFactor(BaseData dividend, CorporateFactorRow previousCorporateFactorRow) { var eventDayData = GetDailyDataForDate(dividend.Time); // If you don't have the equity data nothing can be calculated if (eventDayData == null) { return(null); } TradeBar previousClosingPrice = FindPreviousTradableDayClosingPrice(eventDayData.Time); // adjust the dividend for both price and split factors (!) var priceFactor = previousCorporateFactorRow.PriceFactor * (1 - dividend.Value * previousCorporateFactorRow.SplitFactor / previousClosingPrice.Close); return(new CorporateFactorRow( previousClosingPrice.Time, priceFactor.RoundToSignificantDigits(7), previousCorporateFactorRow.SplitFactor, previousClosingPrice.Close )); }
/// <summary> /// Generates the <see cref="CorporateFactorRow"/> that represents a intraday dividend split. /// Applies the dividend first. /// </summary> /// <param name="intraDayDividendSplit"><see cref="IntraDayDividendSplit"/> instance that holds the intraday dividend and split information</param> /// <param name="last">The last <see cref="CorporateFactorRow"/> generated recursivly</param> /// <returns><see cref="CorporateFactorRow"/> that represents an intraday dividend and split</returns> private CorporateFactorRow CalculateIntradayDividendSplit(IntraDayDividendSplit intraDayDividendSplit, CorporateFactorRow last) { var row = CalculateNextDividendFactor(intraDayDividendSplit.Dividend, last); return(CalculateNextSplitFactor(intraDayDividendSplit.Split, row)); }