public bool GetLastYearSegmentInfo(ref double dblFraction, ref DateTime dtFraSegStartDate, ref DateTime dtFraSegEndDate, ref short iFraSegTPWeight, ref DateTime dtRemSegStartDate, ref DateTime dtRemSegEndDate, ref short iRemSegTPWeight, out bool pVal) { DateTime dtTmpEndDate; DateTime dtTmpStartDate; IBACalcPeriod pObjperiod; IBAFiscalYear FY; bool hr; pVal = false; if (m_pObjCalendar == null) { throw new Exception("Avg Convention not initialized."); } if (!(hr = m_pObjCalendar.GetFiscalYear(m_dtEndDate, out FY)) || !(hr = FY.GetPeriod(m_dtEndDate, out pObjperiod)) || !(hr = FY.GetPreviousPeriodWeights(m_dtEndDate, out iRemSegTPWeight)) || !(hr = FY.GetCurrentPeriodWeight(m_dtEndDate, out iFraSegTPWeight))) { return(hr); } dtTmpStartDate = FY.YRStartDate; dtTmpEndDate = FY.YREndDate; dtFraSegStartDate = pObjperiod.PeriodStart; dtFraSegEndDate = pObjperiod.PeriodEnd; dtRemSegStartDate = FY.YRStartDate; dblFraction = 0.5 * (double)(iFraSegTPWeight) / ((double)(iRemSegTPWeight) + (double)(iFraSegTPWeight) * 0.5); dtRemSegEndDate = dtFraSegStartDate.AddDays(-1); pVal = true; return(true); }
public bool GetLastYearSegmentInfo(ref double dblFraction, ref DateTime dtFraSegStartDate, ref DateTime dtFraSegEndDate, ref short iFraSegTPWeight, ref DateTime dtRemSegStartDate, ref DateTime dtRemSegEndDate, ref short iRemSegTPWeight, out bool pVal) { int iDays; int iTotalDays; DateTime dtSDate; DateTime dtEDate; DateTime dtPSDate; DateTime dtPEDate; ECALENDARCYCLE_CYCLETYPE eCType; IBACalcPeriod pObjPeriod; IBAFiscalYear FY; bool hr; pVal = false; if (m_pObjCalendar == null) { throw new Exception("Avg Convention not initialized."); } if (!(hr = m_pObjCalendar.GetFiscalYear(m_dtEndDate, out FY)) || !(hr = FY.GetPeriod(m_dtEndDate, out pObjPeriod))) { return(hr); } dtEDate = FY.YREndDate; dtSDate = FY.YRStartDate; eCType = FY.CycleType; if (eCType == ECALENDARCYCLE_CYCLETYPE.CYCLETYPE_MONTHLY) { if (!(hr = FY.GetPreviousPeriodWeights(m_dtEndDate, out iRemSegTPWeight)) || !(hr = FY.GetCurrentPeriodWeight(m_dtEndDate, out iFraSegTPWeight))) { return(hr); } dblFraction = 0.5 * (double)(iFraSegTPWeight) / ((double)(iRemSegTPWeight) + (double)(iFraSegTPWeight) * 0.5); dtFraSegStartDate = pObjPeriod.PeriodStart; dtFraSegEndDate = pObjPeriod.PeriodEnd; dtRemSegStartDate = dtSDate; dtRemSegEndDate = dtFraSegStartDate.AddDays(-1); } else { dtPSDate = pObjPeriod.PeriodStart; dtPEDate = pObjPeriod.PeriodEnd; iDays = (int)((m_dtEndDate - dtPSDate).TotalDays + 1); iTotalDays = (int)((dtPEDate - dtPSDate).TotalDays + 1); if (!(hr = FY.GetPreviousPeriodWeights(m_dtEndDate, out iRemSegTPWeight)) || !(hr = FY.GetCurrentPeriodWeight(m_dtEndDate, out iFraSegTPWeight))) { return(hr); } dblFraction = ((double)(iFraSegTPWeight) * (double)(iDays) / (double)(iTotalDays)) / ((double)(iRemSegTPWeight) + (double)(iFraSegTPWeight) * (double)(iDays) / (double)(iTotalDays)); dtFraSegStartDate = dtPSDate; dtFraSegEndDate = dtPEDate; dtRemSegStartDate = dtSDate; dtRemSegEndDate = dtFraSegStartDate.AddDays(-1); } return(false); }