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 static double Curve_GetFwdRate(string curveHandle, DateTime asOf, DateTime date, CurveTenor tenor, DayCount dayCount, DayRule dayRule, InterpMethod interpolation) { DateTime endDate = DateHandling.AddTenorAdjust(date, EnumToStr.CurveTenor(tenor), dayRule); if (ObjectMap.DiscCurves.ContainsKey(curveHandle)) { Curve curve = ObjectMap.DiscCurves[curveHandle]; return(curve.FwdRate(asOf, date, endDate, dayRule, dayCount, interpolation)); } else if (ObjectMap.FwdCurves.ContainsKey(curveHandle)) { Curve curve = ObjectMap.FwdCurves[curveHandle]; return(curve.FwdRate(asOf, date, endDate, dayRule, dayCount, interpolation)); } else { throw new InvalidOperationException(curveHandle + " does not exist in the objectMap."); } }
private void CopyViewToGoal(GoalModel selectedGoal) { if (repeatableRB2.IsChecked) { var startDate = DateHandling.GetStartDate(repeatableRB2.IsChecked && repeatableRB21.IsChecked, repeatableRB2.IsChecked && repeatableRB22.IsChecked, weekdayPicker.SelectedIndex, dayOfMonthPicker.SelectedIndex); selectedGoal.CreatedDate = startDate; selectedGoal.Deadline = DateHandling.GetDeadlineDateForRepeatingGoals(repeatableRB2.IsChecked && repeatableRB21.IsChecked, repeatableRB2.IsChecked && repeatableRB22.IsChecked, startDate); } else { selectedGoal.Deadline = DateTime.Parse(goalDeadlineEntry.Date.ToString()); } selectedGoal.LastUpdatedDate = DateTime.Now; selectedGoal.Title = goalNameEntry.Text; selectedGoal.Description = goalDescriptionEntry.Text; // selectedGoal.PrivateGoal = privateGoalCheckbox.IsChecked; selectedGoal.RepeatWeekly = weekdayPicker.SelectedIndex; selectedGoal.RepeatMonthly = dayOfMonthPicker.SelectedIndex; selectedGoal.RepeatType = repeatableRB1.IsChecked ? 0 : 1; selectedGoal.WeeklyOrMonthly = repeatableRB21.IsChecked ? 0 : 1; if (selectedGoal.TargetType == 1) { selectedGoal.StepByStepAmount = stepbystepPicker.SelectedIndex; selectedGoal.TargetValue = (selectedGoal.StepByStepAmount + 1).ToString(); selectedGoal.Checkbox1Comment = step1entry.Text; selectedGoal.Checkbox2Comment = step2entry.Text; selectedGoal.Checkbox3Comment = step3entry.Text; selectedGoal.Checkbox4Comment = step4entry.Text; selectedGoal.Checkbox5Comment = step5entry.Text; selectedGoal.Checkbox6Comment = step6entry.Text; selectedGoal.Checkbox7Comment = step7entry.Text; selectedGoal.Checkbox8Comment = step8entry.Text; selectedGoal.Checkbox9Comment = step9entry.Text; } else { selectedGoal.TargetValue = goalTargetEntry.Text; } }
public static void DateTest() { Console.WriteLine("--------- Day roll test"); DateTime MyDate = new DateTime(2017, 1, 27); DateTime MyDate2 = new DateTime(2025, 3, 27); Console.WriteLine("MyDate: " + DateHandling.AddTenorAdjust(MyDate, "5b", DayRule.F)); Console.WriteLine("MyDate: " + DateHandling.AddTenorAdjust(MyDate, "5b", DayRule.MF)); Console.WriteLine("MyDate: " + DateHandling.AddTenorAdjust(MyDate, "5b", DayRule.P)); Console.WriteLine("--------- Coverage test"); Console.WriteLine("ACT/360: " + DateHandling.Cvg(MyDate, MyDate2, DayCount.ACT360)); Console.WriteLine("30/360: " + DateHandling.Cvg(MyDate, MyDate2, DayCount.THIRTY360)); SwapSchedule MySchedule = new SwapSchedule(DateTime.Now, MyDate, MyDate2, DayCount.ACT360, DayRule.MF, CurveTenor.Fwd6M); MySchedule.Print(); MySchedule = new SwapSchedule(DateTime.Now, MyDate, MyDate2, DayCount.THIRTY360, DayRule.MF, CurveTenor.Fwd6M); MySchedule.Print(); SwapSchedule MySchedule2 = new SwapSchedule(DateTime.Now, MyDate, MyDate2, DayCount.THIRTY360, DayRule.MF, CurveTenor.Fwd1Y); MySchedule2.Print(); }
private async void CreateGoal(string userId, bool accepted, string challengeId) { var startDate = DateHandling.GetStartDate(repeatableRB2.IsChecked && repeatableRB21.IsChecked, repeatableRB2.IsChecked && repeatableRB22.IsChecked, weekdayPicker.SelectedIndex, dayOfMonthPicker.SelectedIndex); DateTime deadLineDate; if (repeatableRB2.IsChecked) { deadLineDate = DateHandling.GetDeadlineDateForRepeatingGoals(repeatableRB2.IsChecked && repeatableRB21.IsChecked, repeatableRB2.IsChecked && repeatableRB22.IsChecked, startDate); } else { deadLineDate = DateTime.Parse(goalDeadlineEntry.Date.ToString()); } GoalModel goal = new GoalModel() { Title = goalNameEntry.Text, Description = goalDescriptionEntry.Text, Deadline = deadLineDate, TargetValue = goalTargetEntry.Text, UserId = userId, GoalAccepted = accepted, ChallengeId = challengeId, CurrentValue = "0", ClosedDate = DateTime.MaxValue, CreatedDate = startDate, LastUpdatedDate = DateTime.Now, Progress = 0, GoalType = 2, TargetType = targetRB1.IsChecked ? 0 : 1, RepeatType = repeatableRB1.IsChecked ? 0 : 1, WeeklyOrMonthly = repeatableRB21.IsChecked ? 0 : 1, RepeatWeekly = weekdayPicker.SelectedIndex, RepeatMonthly = dayOfMonthPicker.SelectedIndex, StepByStepAmount = stepbystepPicker.SelectedIndex, Checkbox1 = step1CB.IsChecked, Checkbox1Comment = step1entry.Text, Checkbox2 = step2CB.IsChecked, Checkbox2Comment = step2entry.Text, Checkbox3 = step3CB.IsChecked, Checkbox3Comment = step3entry.Text, Checkbox4 = step4CB.IsChecked, Checkbox4Comment = step4entry.Text, Checkbox5 = step5CB.IsChecked, Checkbox5Comment = step5entry.Text, Checkbox6 = step6CB.IsChecked, Checkbox6Comment = step6entry.Text, Checkbox7 = step7CB.IsChecked, Checkbox7Comment = step7entry.Text, Checkbox8 = step8CB.IsChecked, Checkbox8Comment = step8entry.Text, Checkbox9 = step9CB.IsChecked, Checkbox9Comment = step9entry.Text }; //if (goal.RepeatMonthly == 28) // Last day of month //{ // goal.RepeatMonthly = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); //} await App.client.GetTable <GoalModel>().InsertAsync(goal); }
public static DateTime Helpers_AdjustDate(DateTime startDate, string dayRule) { DayRule dayRuleEnum = StrToEnum.DayRuleConvert(dayRule); return(DateHandling.AdjustDate(startDate, dayRuleEnum)); }
public static DateTime Helpers_AddTenorAdjust(DateTime date, string Tenor, string dayRule) { DayRule dayRuleEnum = StrToEnum.DayRuleConvert(dayRule); return(DateHandling.AddTenorAdjust(date, Tenor, dayRuleEnum)); }