public static DateTime AdjustDate(DateTime unadjustedDate, DayRule dayRule = DayRule.N) { // if unadjusted date is business day: no adjustment. if (IsBusinessDay(unadjustedDate) || dayRule == DayRule.N) { return(unadjustedDate); } else if (dayRule == DayRule.F) { return(AddBusinessDay(unadjustedDate)); } else if (dayRule == DayRule.P) { return(SubtractBusinessDay(unadjustedDate)); } else if (dayRule == DayRule.MF) { int monthUnadjusted = unadjustedDate.Month; int monthAdjusted = AddBusinessDay(unadjustedDate).Month; if (monthUnadjusted == monthAdjusted) { return(AddBusinessDay(unadjustedDate)); } else { return(SubtractBusinessDay(unadjustedDate)); } } else { throw new InvalidOperationException("DayRule is not valid."); } }
public void AddTime_Time_Less_Then_Previous_Time_Should_Throw_ArgumentException() { var rule = new DayRule() .AddTime(new TimeSpan(0, 2, 0, 0), 0); Assert.Throws <ArgumentException>(() => rule.AddTime(new TimeSpan(0, 1, 0, 0), 0)); }
public static void DayCompoundingTest() { DateTime AsOf = new DateTime(2017, 1, 15); DateTime Start = new DateTime(2017, 1, 31); DateTime End = new DateTime(2017, 2, 19); DayRule DayRule = DayRule.F; DayCount DayCount = DayCount.ACT360; DateTime Temp = Start; double Compound = 1; while (Temp < End) { double Rate = 0.1; DateTime NewDate = DateHandling.AddTenorAdjust(Temp, "1B", DayRule); double Days = NewDate.Subtract(Temp).TotalDays; Console.WriteLine("Day: " + Temp.DayOfWeek + " to " + NewDate.DayOfWeek + ". Days: " + Days); Temp = NewDate; Compound *= (1 + Rate * Days / 365); Console.Write(" .. Compound: " + Compound + " . "); } Compound = (Compound - 1) / (DateHandling.Cvg(Start, End, DayCount)); Console.WriteLine("Compound: " + Compound); DateTime End2 = DateHandling.AddTenorAdjust(Start, "68M"); SwapSchedule SwapSchedule = new SwapSchedule(AsOf, Start, End2, DayCount.ACT360, DayRule.MF, CurveTenor.Fwd6M, StubPlacement.Beginning); SwapSchedule.Print(); SwapSchedule SwapSchedule2 = new SwapSchedule(AsOf, Start, End2, DayCount.ACT360, DayRule.MF, CurveTenor.Fwd6M, StubPlacement.End); SwapSchedule2.Print(); }
public void AddTime_Add_Times_In_Ascending_Order_Should_Not_Throw_Exception() { var rule = new DayRule() .AddTime(new TimeSpan(1, 0, 0), 0) .AddTime(new TimeSpan(2, 0, 0), 0) .AddTime(new TimeSpan(3, 0, 0), 0) .AddTime(new TimeSpan(4, 0, 0), 0); }
private DateRule(string name, DateType type, YearRule yearRule, MonthRule monthRule, DayRule dayRule) { Name = name; Type = type; YearRule = yearRule; MonthRule = monthRule; DayRule = dayRule; }
public ADouble FwdRate(DateTime asOf, DateTime startDate, DateTime endDate, DayRule dayRule, DayCount dayCount, InterpMethod interpolation) { ADouble ps = DiscFactor(asOf, startDate, dayCount, interpolation); ADouble pe = DiscFactor(asOf, endDate, dayCount, interpolation); ADouble cvg = DateHandling.Cvg(startDate, endDate, dayCount); return((ps / pe - 1.0) / cvg); }
public void AddTime_Configuration_Is_Ended_Should_Throw_InvalidOperationException() { var rule = new DayRule() .AddTime(new TimeSpan(0, 1, 0, 0), 0) .EndConfiguration(); Assert.Throws <InvalidOperationException>(() => rule.AddTime(new TimeSpan(0, 1, 0, 0), 0)); }
public ConsistentDayAttribute() { Rule = new DayRule(); var resolver = new MessageResolver(Configuration.MessageProvider, Configuration.MessageCache); ErrorMessage = resolver.GetMessage(Rule); }
public static DateTime AddTenorAdjust(DateTime date, string tenor, DayRule dayRule = DayRule.N) { // Current implementation: holidays is only weekends. This means that if we add tenor // a business day tenor (B) we will never risk ending up on a holiday. DateTime unadjustedDate = AddTenor(date, tenor, dayRule); return(AdjustDate(unadjustedDate, dayRule)); }
public void GetTollFee_Call_Before_Calling_EndConfiguration_Throws_InvalidOperationException() { var vehicle = new Mock <IVehicle>(); var rule = new DayRule() .AddTime(new TimeSpan(1, 0, 0), 0); Assert.Throws <InvalidOperationException>(() => rule.GetTollFee(vehicle.Object, new DateTime(2018, 12, 22))); }
public static double LinearRate_Curve_GetFwdRate(string curveHandle, DateTime asOf, DateTime startDate, string tenorStr, string dayCountStr, string dayRuleStr, string interpolationStr) { CurveTenor tenor = StrToEnum.CurveTenorFromSimpleTenor(tenorStr); InterpMethod interpolation = StrToEnum.InterpolationConvert(interpolationStr); DayCount dayCount = StrToEnum.DayCountConvert(dayCountStr); DayRule dayRule = StrToEnum.DayRuleConvert(dayRuleStr); return(LinearRateFunctions.Curve_GetFwdRate(curveHandle, asOf, startDate, tenor, dayCount, dayRule, interpolation)); }
public static string LinearRate_OisSwap_Make(string baseHandle, DateTime asOf, string startTenor, string endTenor, string settlementLag, string dayCountFixedStr, string dayCountFloatStr, string dayRuleStr, double notional, double fixedRate, int tradeSign) { DayCount dayCountFloat = StrToEnum.DayCountConvert(dayCountFloatStr); DayCount dayCountFixed = StrToEnum.DayCountConvert(dayCountFixedStr); DayRule dayRule = StrToEnum.DayRuleConvert(dayRuleStr); LinearRateFunctions.OisSwap_Make(baseHandle, asOf, startTenor, endTenor, settlementLag, dayCountFixed, dayCountFloat, dayRule, notional, fixedRate, tradeSign); return(baseHandle); }
public static string LinearRate_FixedLeg_Make(string baseHandle, DateTime asOf, DateTime startDate, DateTime endDate, double fixedRate, string frequency, string dayCount, string dayRule, double notional) { CurveTenor tenorEnum = StrToEnum.CurveTenorConvert(frequency); DayCount dayCountEnum = StrToEnum.DayCountConvert(dayCount); DayRule dayRuleEnum = StrToEnum.DayRuleConvert(dayRule); LinearRateFunctions.FixedLeg_Make(baseHandle, asOf, startDate, endDate, fixedRate, tenorEnum, dayCountEnum, dayRuleEnum, notional); return(baseHandle); }
protected SwapLeg(DateTime asOf, DateTime startDate, DateTime endDate, CurveTenor referenceTenor, DayCount dayCount, DayRule dayRule, double notional) { Schedule = new MasterThesis.SwapSchedule(asOf, startDate, endDate, dayCount, dayRule, referenceTenor); this.Tenor = referenceTenor; this.DayRule = dayRule; this.DayCount = dayCount; this.Notional = notional; this.AsOf = asOf; this.StartDate = startDate; this.EndDate = endDate; }
public Deposit(DateTime asOf, string startTenor, string endTenor, string settlementLag, double fixedRate, DayCount dayCount, DayRule dayRule, double notional, int tradeSign) { AsOf = asOf; StartDate = DateHandling.AddTenorAdjust(asOf, startTenor, dayRule); StartDate = DateHandling.AddTenorAdjust(StartDate, settlementLag, dayRule); EndDate = DateHandling.AddTenor(StartDate, endTenor, dayRule); Notional = notional; TradeSign = tradeSign; FixedRate = fixedRate; DayRule = dayRule; DayCount = dayCount; }
public void SetValues(DateTime asOf, DateTime startDate, DateTime endDate, DayCount dayCount, DayRule dayRule) { UnAdjEndDates = new List <DateTime>(); UnAdjStartDates = new List <DateTime>(); AdjStartDates = new List <DateTime>(); AdjEndDates = new List <DateTime>(); Coverages = new List <double>(); AsOf = asOf; StartDate = startDate; EndDate = endDate; DayCount = dayCount; DayRule = dayRule; }
public void GetTollFee_Time_Less_Then_First_Added_Time() { var expectedTollFee = 10; var vehicle = new Mock <IVehicle>(); var rule = new DayRule() .AddTime(new TimeSpan(1, 0, 0), 5) .AddTime(new TimeSpan(3, 0, 0), expectedTollFee) .EndConfiguration(); var tollFee = rule.GetTollFee(vehicle.Object, new DateTime(2018, 12, 22, 0, 30, 0)); Assert.Equal(expectedTollFee, tollFee); }
public FwdCurveRepresentation(Curve curve, CurveTenor tenor, DateTime asOf, DayCount dayCount, DayRule dayRule, InterpMethod interpolation) { Dates = curve.Dates; _zcbValues = curve.Values; Dimension = curve.Dimension; Tenor = tenor; AsOf = asOf; _fwdDayCount = dayCount; _fwdDayRule = dayRule; _interpolation = interpolation; ConstructZcbCurveFromDatesAndValues(); ConstructFwdRates(); }
private ModificationsRuleRequest CreateRequest(DayRule dayRule, ModifyDay md, int priority, PrintDayTemplate printTemplate) { return(new ModificationsRuleRequest() { DayRuleId = dayRule.Id, Date = md.MoveDateCalculated, Priority = priority, ShortName = md.ShortName, AsAddition = md.AsAddition, IsLastName = md.IsLastName, UseFullName = md.UseFullName, PrintDayTemplateId = printTemplate?.Id, Filter = md.Filter }); }
public IrSwap(DateTime asOf, DateTime startDate, DateTime endDate, double fixedRate, CurveTenor fixedFreq, CurveTenor floatFreq, DayCount fixedDayCount, DayCount floatDayCount, DayRule fixedDayRule, DayRule floatDayRule, double notional, int tradeSign, double spread = 0.0) { FloatLeg = new FloatLeg(asOf, startDate, endDate, floatFreq, floatDayCount, floatDayRule, notional, spread); FixedLeg = new FixedLeg(asOf, startDate, endDate, fixedRate, fixedFreq, fixedDayCount, fixedDayRule, notional); if (tradeSign == 1 || tradeSign == -1) { TradeSign = tradeSign; } else { throw new InvalidOperationException("TradeSign has to be 1 (pay fixed) or -1 (pay float)"); } }
public OisSwap(DateTime asOf, string startTenor, string endTenor, string settlementLag, DayCount dayCountFixed, DayCount dayCountFloat, DayRule dayRule, double notional, double fixedRate, int tradeSign) { DateTime startDate = DateHandling.AddTenorAdjust(asOf, startTenor, dayRule); startDate = DateHandling.AddTenorAdjust(startDate, settlementLag, dayRule); DateTime endDate = DateHandling.AddTenorAdjust(startDate, endTenor, dayRule); this.AsOf = asOf; this.StartDate = startDate; this.EndDate = endDate; this.FloatSchedule = new OisSchedule(asOf, startTenor, endTenor, settlementLag, dayCountFloat, dayRule); this.FixedSchedule = new OisSchedule(asOf, startTenor, endTenor, settlementLag, dayCountFixed, dayRule); this.Notional = notional; this.FixedRate = fixedRate; this.TradeSign = tradeSign; }
private void Initialize(DateTime asOf, DateTime startDate, DateTime endDate, CurveTenor referenceIndex, DayCount dayCount, DayRule dayRule, double fixedRate, double notional, int tradeSign) { this.StartDate = startDate; this.EndDate = endDate; this.DayCount = dayCount; this.DayRule = dayRule; this.FixedRate = fixedRate; this.ReferenceIndex = referenceIndex; this.AsOf = asOf; this.Notional = notional; if (tradeSign == 1 || tradeSign == -1) { TradeSign = tradeSign; } else { throw new InvalidOperationException("TradeSign of FRA has to be 1 or -1 (1 = pay fixed)"); } }
public FwdCurveRepresentation(Curve_AD curve, CurveTenor tenor, DateTime asOf, DayCount dayCount, DayRule dayRule, InterpMethod interpolation) { Dates = curve.Dates; Dimension = curve.Dimension; Tenor = tenor; AsOf = asOf; _fwdDayCount = dayCount; _fwdDayRule = dayRule; _interpolation = interpolation; for (int i = 0; i < Dimension; i++) { Values.Add(curve.Values[i].Value); } ConstructZcbCurveFromDatesAndValues(); ConstructFwdRates(); }
public static string DayRule(DayRule DayRule) { switch (DayRule) { case DayRule.MF: return("MF"); case DayRule.F: return("F"); case DayRule.P: return("P"); case DayRule.N: return("N"); default: return("ERROR"); } }
private DayRule GetDayRule(ICustomInterpreted element) { DayRule result = null; if (element is ModifyReplacedDay modifyReplacedDay) { if (modifyReplacedDay.Kind == KindOfReplacedDay.Menology) { result = _dbContext.GetMenologyRule(_typiconVersionId, modifyReplacedDay.DateToReplaceCalculated); } else { result = _dbContext.GetTriodionRule(_typiconVersionId, modifyReplacedDay.DateToReplaceCalculated); } } else if ((element is ModifyDay modifyDay) && (modifyDay.MoveDateCalculated.Year == _modifiedYear.Year)) { result = ProcessingDayRule; } return(result); }
public static DateTime AddTenor(DateTime date, string tenor, DayRule dayRule = DayRule.N) { // To do: proper handling of business days and so forth. int tenorNumber = GetTenorNumberFromTenor(tenor); DateTime newDate; // Roll date forward (unadjusted) switch (GetTenorFromTenor(tenor)) { case Tenor.D: newDate = date.AddDays((double)tenorNumber); break; case Tenor.B: // Accounts for weekends but not holidays. newDate = AddBusinessDays(date, tenorNumber); break; case Tenor.W: newDate = date.AddDays((double)tenorNumber * 7); break; case Tenor.M: newDate = date.AddMonths(tenorNumber); break; case Tenor.Y: newDate = date.AddYears(tenorNumber); break; default: throw new InvalidOperationException("Tenorletter not valid (input D,B,W,M or Y)"); } return(newDate); }
public FixedLeg(DateTime AsOf, DateTime StartDate, DateTime EndDate, double FixedRate, CurveTenor Frequency, DayCount DayCount, DayRule DayRule, double Notional, StubPlacement stub = StubPlacement.NullStub) : base(AsOf, StartDate, EndDate, Frequency, DayCount, DayRule, Notional) { this.FixedRate = FixedRate; }
public FloatLeg(DateTime AsOf, DateTime StartDate, DateTime EndDate, CurveTenor Frequency, DayCount DayCount, DayRule DayRule, double Notional, double Spread = 0.0, StubPlacement stub = StubPlacement.NullStub) : base(AsOf, StartDate, EndDate, Frequency, DayCount, DayRule, Notional) { this.Spread = Spread; }
public Futures(DateTime asOf, string startTenor, string endTenor, CurveTenor referenceIndex, DayCount dayCount, DayRule dayRule, double fixedRate, double notional, int tradeSign, double?convexity = null) { DateTime startDate = DateHandling.AddTenorAdjust(asOf, startTenor, dayRule); DateTime endDate = DateHandling.AddTenorAdjust(startDate, endTenor, dayRule); FraSameSpec = new Fra(asOf, startDate, endDate, referenceIndex, dayCount, dayRule, fixedRate, notional, tradeSign); if (convexity == null) { Convexity = CalcSimpleConvexity(asOf, startDate, endDate, dayCount); } else { Convexity = (double)convexity; } }
public Futures(DateTime asOf, DateTime startDate, DateTime endDate, CurveTenor referenceIndex, DayCount dayCount, DayRule dayRule, double fixedRate, double notional, int tradeSign, double?convexity = null) { FraSameSpec = new Fra(asOf, startDate, endDate, referenceIndex, dayCount, dayRule, fixedRate, notional, tradeSign); if (convexity == null) { Convexity = CalcSimpleConvexity(asOf, startDate, endDate, dayCount); } else { Convexity = (double)convexity; } }