private static DateTime Aux_GetRoundDate(this DateTime dt, TenorUnit tu) { int nb_units = dt.GetNumberOfUnit(tu); switch (tu) { case TenorUnit.Hour: case TenorUnit.Min: case TenorUnit.Sec: break; case TenorUnit.Month: case TenorUnit.Day: nb_units -= 1; break; case TenorUnit.Year: case TenorUnit.None: nb_units = 0; break; } dt = dt.AddTenor(new Tenor(-nb_units, tu)); TenorUnit tuN = tu.GetLowerUnit(skipWeek: true); if (tuN == TenorUnit.None) { return(dt); } else { return(dt.Aux_GetRoundDate(tuN)); } }
public static DateTime AddTenor(this DateTime dt, Tenor tnr, bool isRounded = false) { if (!isRounded) { return(dt.AddTenor(tnr)); } else { DateTime dt2 = dt.GetRoundDate(tnr.Unit); return(dt2.AddTenor(tnr)); } }
public void GetOnGoingPnLs(bool extra = false) { DateTime dateBefore = FXMH.LastRealDate_NoLive; var dataRef = GetAllocationToTable(dateBefore); double refPnL = dataRef["Total"].TotalPnLWithFees; this.PublishDebug($"PnL Report - {dateBefore}"); DateTime dateYear = dateBefore.GetRoundDate(TenorUnit.Year); var dataYear = GetAllocationToTable(dateYear); this.PublishInfo($"{dateYear} - Ongoing Year PnL: {Math.Round(refPnL - dataYear["Total"].TotalPnLWithFees, 2)} {Fiat.ToFullName()}"); DateTime dateMonth = dateBefore.GetRoundDate(TenorUnit.Month); var dataMonth = GetAllocationToTable(dateMonth); this.PublishInfo($"{dateMonth} - Ongoing Month PnL: {Math.Round(refPnL - dataMonth["Total"].TotalPnLWithFees, 2)} {Fiat.ToFullName()}"); DateTime dateWeek = dateBefore.GetRoundDate(TenorUnit.Week); var dataWeek = GetAllocationToTable(dateWeek); this.PublishInfo($"{dateWeek} - Ongoing Week PnL: {Math.Round(refPnL - dataWeek["Total"].TotalPnLWithFees, 2)} {Fiat.ToFullName()}"); DateTime dateDay = dateBefore.GetRoundDate(TenorUnit.Day); var dataDay = GetAllocationToTable(dateDay); this.PublishInfo($"{dateDay} - Ongoing Day PnL: {Math.Round(refPnL - dataDay["Total"].TotalPnLWithFees, 2)} {Fiat.ToFullName()}"); DateTime date30D = dateBefore.AddTenor(new Tenor("-30D"), isRounded: true); var data30D = GetAllocationToTable(date30D); this.PublishInfo($"{date30D} - 30 Days PnL: {Math.Round(refPnL - data30D["Total"].TotalPnLWithFees, 2)} {Fiat.ToFullName()}"); if (extra) { for (int i = 1; i < 30; i++) { DateTime date_i = dateBefore.AddTenor(new Tenor($"-{i}W"), isRounded: true); var data_i = GetAllocationToTable(date_i); this.PublishInfo($"{date_i} - {i} Weeks PnL: {Math.Round(refPnL - data_i["Total"].TotalPnLWithFees, 2)} {Fiat.ToFullName()}"); } } }
public static DateTime AddTenor(this DateTime dt, string tnrString, bool isRounded = false) { return(dt.AddTenor(new Tenor(tnrString), isRounded)); }