private bool CheckCondition(DateTime dateTime) { switch (m_dateType) { case DateType.Day: return(true); case DateType.TradingDay: return(CalendarCache.IsTradingDay(dateTime)); case DateType.WorkingDay: return(CalendarCache.IsWorkingDay(dateTime)); } CommUtils.Assert(false, "[CheckCondition]不支持的Date类型"); return(false); }
private bool CheckCondition(DateTime dateTime) { switch (m_unitType) { case TimeUnit.Day: return(true); case TimeUnit.TradingDay: return(CalendarCache.IsTradingDay(dateTime)); case TimeUnit.WorkingDay: return(CalendarCache.IsWorkingDay(dateTime)); default: return(false); } }
public void TestGetAllTradingDay() { var endDate = DateTime.Now.AddYears(20); var date = DateTime.Now.AddYears(-10); string result = string.Empty; while (date < endDate) { //CalendarCache.IsTradingDay if (CalendarCache.IsWorkingDay(date)) { result += date.ToString("yyyy-MM-dd"); result += "\r\n"; } date = date.AddDays(1); } Assert.IsTrue(CalendarCache.IsTradingDay(DateTime.Parse("2016-09-22"))); Assert.IsTrue(!CalendarCache.IsTradingDay(DateTime.Parse("2016-09-24"))); }
protected override object MakeObjectInstance() { var logicModel = new ProjectLogicModel(m_userName, m_project); var schedule = logicModel.DealSchedule.Instanse; var firstNoteAccrualDates = schedule.NoteAccrualDates.First().Value; var firstNoteName = schedule.NoteAccrualDates.First().Key; foreach (var key in schedule.NoteAccrualDates.Keys) { var noteAccrualDates = schedule.NoteAccrualDates[key]; CommUtils.AssertEquals(firstNoteAccrualDates.Length, noteAccrualDates.Length, "检测到证券期数不一致,[{0}]={1},[{2}]={3}", firstNoteName, firstNoteAccrualDates.Length, key, noteAccrualDates.Length); for (int i = 0; i < firstNoteAccrualDates.Length; i++) { CommUtils.Assert(firstNoteAccrualDates[i] == noteAccrualDates[i], "检测到第[{0}]期证券Accrual date不一致,[{1}]={2},[{3}]={4}", i + 1, firstNoteName, firstNoteAccrualDates[i].ToShortDateString(), key, noteAccrualDates[i].ToShortDateString()); } } //从第N期开始模型数据时,getDealSchedule中不包含前几期的PaymentDate List <DateTime> paymentDates = schedule.PaymentDates.ToList(); if (m_project.CnabsDealId.HasValue) { paymentDates = m_dbAdapter.Model.GetPaymentDates(m_project.CnabsDealId.Value); } var datasets = m_dbAdapter.Dataset.GetDatasetByProjectId(m_project.ProjectId); var paymentDate = paymentDates.First(x => x == m_paymentDay); var sequence = paymentDates.FindIndex(x => x == m_paymentDay); datasets = datasets.Where(x => x.PaymentDate.HasValue && x.PaymentDate.Value <= paymentDate).ToList(); var findDatasets = datasets.Where(x => x.PaymentDate.HasValue && x.PaymentDate.Value == paymentDate).ToList(); findDatasets.Sort((l, r) => l.AsOfDate.CompareTo(r.AsOfDate)); CommUtils.Assert(findDatasets.Count >= 1, "找不到偿付期为 [{0}] 的数据模型", DateUtils.DateToString(paymentDate)); var dataset = findDatasets[0]; var datasetId = dataset.DatasetId; var notes = m_dbAdapter.Dataset.GetNotes(m_project.ProjectId); var noteDatas = m_dbAdapter.Dataset.GetNoteDatas(datasetId); //初始化note信息 List <Note> cnabsNotes = new ProjectLogicModel(m_userName, m_project).Notes; var datasetFolder = m_dbAdapter.Dataset.GetDatasetFolder(m_project, dataset.AsOfDate); var variablesCsv = new VariablesHelper(datasetFolder); var futureVariablesPath = Path.Combine(datasetFolder, "FutureVariables.csv"); var variables = variablesCsv.GetVariablesByDate(dataset.PaymentDate.Value); var rateResetRecords = InterestRateUtils.RateResetRecords(variables); var idrObj = new IncomeDistributionReport(); idrObj.Sequence = sequence + 1; idrObj.SequenceCN = idrObj.Sequence.ToCnString(); idrObj.Security = new Dictionary <string, PaymentDetail>(); idrObj.PriorSecurityList = new List <PaymentDetail>(); idrObj.SubSecurityList = new List <PaymentDetail>(); idrObj.SecurityList = new List <PaymentDetail>(); idrObj.BeginAccrualDate = sequence == 0 ? schedule.FirstAccrualDate : schedule.NoteAccrualDates.First().Value[sequence - 1]; idrObj.EndAccrualDate = schedule.NoteAccrualDates.First().Value[sequence]; idrObj.AccrualDateSum = (idrObj.EndAccrualDate - idrObj.BeginAccrualDate).Days; for (int i = 0; i < notes.Count; i++) { var note = notes[i]; note.CouponString = InterestRateUtils.CalculateCurrentCouponRate(cnabsNotes[i].CouponString, rateResetRecords); var noteData = noteDatas.Single(x => x.NoteId == note.NoteId); CommUtils.Assert(noteData.HasValue, "兑付日为[{0}]的偿付期内,证券端现金流类型的工作未核对", paymentDate.ToShortDateString()); idrObj.Security[note.ShortName] = GeneratePaymentDetail(note, noteData, idrObj.Security.Count + 1); if (note.IsEquity) { idrObj.SubSecurityList.Add(GeneratePaymentDetail(note, noteData, idrObj.SubSecurityList.Count + 1)); } else { idrObj.PriorSecurityList.Add(GeneratePaymentDetail(note, noteData, idrObj.PriorSecurityList.Count + 1)); } idrObj.SecurityList.Add(GeneratePaymentDetail(note, noteData, idrObj.SecurityList.Count(x => x.Money != 0) + 1)); } Func <IEnumerable <PaymentDetail>, PaymentDetail> sum = (values) => new PaymentDetail { Residual = values.Sum(x => x.Residual), Principal = values.Sum(x => x.Principal), Interest = values.Sum(x => x.Interest), Money = values.Sum(x => x.Money), UnitCount = values.Sum(x => x.UnitCount), SumPaymentAmount = values.Sum(x => x.SumPaymentAmount) }; idrObj.Sum = sum(idrObj.Security.Values); idrObj.SumPrior = sum(idrObj.Security.Values.Where(x => !x.IsEquity)); idrObj.SumSub = sum(idrObj.Security.Values.Where(x => x.IsEquity)); GeneratePercentTable(idrObj, datasets, notes, schedule.PaymentDates); idrObj.RepayDetail = GenerateRepayDetail(idrObj.SecurityList, x => x.NameCN); idrObj.RepayDetailWithHyphen = GenerateRepayDetail(idrObj.SecurityList, x => x.NameCNHyphen); idrObj.RepayDetailWithHyphenByJinTai = GenerateRepayDetailByJinTai(idrObj.SecurityList, x => x.NameCNHyphen); idrObj.RepayPrincipalDetail = GenerateRepayPrincipalDetail(idrObj.SecurityList); idrObj.DenominationDetail = GenerateDenominationDetail(idrObj.SecurityList); idrObj.EquityRegisterDetail = GenerateEquityRegisterDetail(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.EquityRegisterDetailByJinTai = GenerateEquityRegisterDetailByJinTai(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.EquityRegisterDetailByZhongGang = GenerateEquityRegisterDetailByZhongGang(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.EquityRegisterDetailByYingBinGuan = GenerateEquityRegisterDetailByYingBinGuan(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.T = dataset.PaymentDate.Value; if (paymentDates.First() == idrObj.T) { idrObj.PreviousT = schedule.ClosingDate; } else { var previousIndex = paymentDates.IndexOf(idrObj.T) - 1; idrObj.PreviousT = paymentDates[previousIndex]; } idrObj.DurationDayCount = (idrObj.T - idrObj.PreviousT).Days; var t_1 = dataset.PaymentDate.Value.AddDays(-1); while (!CalendarCache.IsTradingDay(t_1)) { t_1 = t_1.AddDays(-1); } idrObj.T_1 = t_1; idrObj.Date = DateTime.Today; idrObj.TaskEndTime = m_timeStamp; return(idrObj); }