#EQD-5718 【缺陷转需求】-国联民生-利息端计息方式与结算规则扩充
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Qdp.Foundation.Implementations;
|
||||
using Qdp.Foundation.Implementations;
|
||||
using Qdp.Pricing.Base.Enums;
|
||||
using Qdp.Pricing.Base.Implementations;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -220,5 +220,199 @@ namespace YLErp.QdpModule
|
||||
var monthlyDates = GetDefaultKoObservationDatesForSnowbal(startDate, endDate);
|
||||
return monthlyDates.Select(x => (Date)x).ToArray();
|
||||
}
|
||||
|
||||
public static DateTime[] GetDatesWithFixedTerm(
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
string termStr,
|
||||
string calendarStr,
|
||||
BusinessDayConvention bdc = BusinessDayConvention.None,
|
||||
bool alignEnd = false,
|
||||
string calcMode = "01")
|
||||
{
|
||||
if (!Term.IsTerm(termStr))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var calendarName = string.IsNullOrEmpty(calendarStr) ? "chn" : calendarStr.ToLower();
|
||||
return GetDatesWithFixedTerm(startDate, endDate, new Term(termStr), calendarName, bdc, alignEnd, calcMode);
|
||||
}
|
||||
|
||||
public static DateTime[] GetDatesWithFixedTerm(
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
Term term,
|
||||
string calendarStr,
|
||||
BusinessDayConvention bdc = BusinessDayConvention.None,
|
||||
bool alignEnd = false,
|
||||
string calcMode = "01")
|
||||
{
|
||||
var calendarName = string.IsNullOrEmpty(calendarStr) ? "chn" : calendarStr.ToLower();
|
||||
return alignEnd
|
||||
? GetDatesWithFixedTermStartAlignEnd(startDate, endDate, term, calendarName, bdc, calcMode)
|
||||
: GetDatesWithFixedTermStartAlignStart(startDate, endDate, term, calendarName, bdc, calcMode);
|
||||
}
|
||||
|
||||
private static DateTime[] GetDatesWithFixedTermStartAlignEnd(
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
Term term,
|
||||
string calendarName,
|
||||
BusinessDayConvention bdc = BusinessDayConvention.None,
|
||||
string calcMode = "01")
|
||||
{
|
||||
var qdpStart = new Date(startDate);
|
||||
var qdpEnd = new Date(endDate);
|
||||
var dates = new List<Date>();
|
||||
var calendar = CalendarImpl.Get(calendarName);
|
||||
|
||||
if (calcMode == "11")
|
||||
{
|
||||
while (qdpEnd >= qdpStart)
|
||||
{
|
||||
dates.Add(qdpEnd);
|
||||
qdpEnd = term.Prev(qdpEnd);
|
||||
}
|
||||
}
|
||||
else if (calcMode == "10")
|
||||
{
|
||||
qdpEnd = term.Prev(qdpEnd);
|
||||
while (qdpEnd >= qdpStart)
|
||||
{
|
||||
dates.Add(qdpEnd);
|
||||
qdpEnd = term.Prev(qdpEnd);
|
||||
}
|
||||
}
|
||||
else if (calcMode == "01")
|
||||
{
|
||||
while (qdpEnd > qdpStart)
|
||||
{
|
||||
dates.Add(qdpEnd);
|
||||
qdpEnd = term.Prev(qdpEnd);
|
||||
}
|
||||
}
|
||||
else if (calcMode == "00")
|
||||
{
|
||||
qdpEnd = term.Prev(qdpEnd);
|
||||
while (qdpEnd > qdpStart)
|
||||
{
|
||||
dates.Add(qdpEnd);
|
||||
qdpEnd = term.Prev(qdpEnd);
|
||||
}
|
||||
}
|
||||
|
||||
if (dates.Count == 0)
|
||||
{
|
||||
dates.Add(new Date(endDate));
|
||||
}
|
||||
|
||||
dates = dates.Select(d => calendar.Adjust(d, bdc)).Distinct().ToList();
|
||||
dates.Reverse();
|
||||
return dates.Select(x => x.DateTime).ToArray();
|
||||
}
|
||||
|
||||
private static DateTime[] GetDatesWithFixedTermStartAlignStart(
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
Term term,
|
||||
string calendarName,
|
||||
BusinessDayConvention bdc = BusinessDayConvention.None,
|
||||
string calcMode = "01")
|
||||
{
|
||||
var qdpStart = new Date(startDate);
|
||||
var qdpEnd = new Date(endDate);
|
||||
var dates = new List<Date>();
|
||||
var calendar = CalendarImpl.Get(calendarName);
|
||||
|
||||
if (calcMode == "11")
|
||||
{
|
||||
while (qdpStart <= qdpEnd)
|
||||
{
|
||||
dates.Add(qdpStart);
|
||||
qdpStart = term.Next(qdpStart);
|
||||
}
|
||||
}
|
||||
else if (calcMode == "10")
|
||||
{
|
||||
while (qdpStart < qdpEnd)
|
||||
{
|
||||
dates.Add(qdpStart);
|
||||
qdpStart = term.Next(qdpStart);
|
||||
}
|
||||
}
|
||||
else if (calcMode == "01")
|
||||
{
|
||||
qdpStart = term.Next(qdpStart);
|
||||
while (qdpStart <= qdpEnd)
|
||||
{
|
||||
dates.Add(qdpStart);
|
||||
qdpStart = term.Next(qdpStart);
|
||||
}
|
||||
}
|
||||
else if (calcMode == "00")
|
||||
{
|
||||
qdpStart = term.Next(qdpStart);
|
||||
while (qdpStart < qdpEnd)
|
||||
{
|
||||
dates.Add(qdpStart);
|
||||
qdpStart = term.Next(qdpStart);
|
||||
}
|
||||
}
|
||||
|
||||
dates = dates.Select(d => calendar.Adjust(d, bdc)).Distinct().ToList();
|
||||
|
||||
if (dates.Count == 0)
|
||||
{
|
||||
dates.Add(qdpEnd);
|
||||
}
|
||||
|
||||
return dates.Select(x => x.DateTime).ToArray();
|
||||
}
|
||||
|
||||
public static ObservationSettleDateResult[] GetObservationAndSettleDates(
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
string termStr,
|
||||
string calendarStr,
|
||||
int settlementRules,
|
||||
BusinessDayConvention bdc = BusinessDayConvention.None,
|
||||
bool alignEnd = false,
|
||||
string calcMode = "01")
|
||||
{
|
||||
if (!Term.IsTerm(termStr))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var calendarName = string.IsNullOrEmpty(calendarStr) ? "chn" : calendarStr.ToLower();
|
||||
var calendar = CalendarImpl.Get(calendarName);
|
||||
var term = new Term(termStr);
|
||||
|
||||
DateTime[] observationDates = alignEnd
|
||||
? GetDatesWithFixedTermStartAlignEnd(startDate, endDate, term, calendarName, bdc, calcMode)
|
||||
: GetDatesWithFixedTermStartAlignStart(startDate, endDate, term, calendarName, bdc, calcMode);
|
||||
|
||||
var results = new List<ObservationSettleDateResult>();
|
||||
foreach (var obsDate in observationDates)
|
||||
{
|
||||
var settleDate = obsDate.AddDays(settlementRules);
|
||||
settleDate = calendar.Adjust(new Date(settleDate), bdc).DateTime;
|
||||
|
||||
results.Add(new ObservationSettleDateResult
|
||||
{
|
||||
ObservationDate = obsDate,
|
||||
SettleDate = settleDate
|
||||
});
|
||||
}
|
||||
|
||||
return results.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class ObservationSettleDateResult
|
||||
{
|
||||
public DateTime ObservationDate { get; set; }
|
||||
public DateTime SettleDate { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user