public bool GetFirstYearSegmentInfo(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_dtPISDate, out FY))) { return(hr); } dtTmpStartDate = FY.YRStartDate; dtTmpEndDate = FY.YREndDate; if (!(hr = FY.GetPeriod(m_dtPISDate, out pObjPeriod)) || !(hr = FY.GetCurrentPeriodWeight(m_dtPISDate, out iFraSegTPWeight))) { return(hr); } dtFraSegStartDate = pObjPeriod.PeriodStart; dtFraSegEndDate = pObjPeriod.PeriodEnd; if (m_dtStartDate >= dtTmpStartDate && m_dtStartDate <= dtTmpEndDate && m_dtEndDate >= dtTmpStartDate && m_dtEndDate <= dtTmpEndDate) { dtTmpEndDate = m_dtEndDate; } dtRemSegEndDate = dtTmpEndDate; if (dtFraSegEndDate == dtTmpEndDate) { iRemSegTPWeight = 0; dblFraction = 1; dtRemSegStartDate = dtTmpEndDate; dtRemSegEndDate = dtTmpEndDate; } else { if (!(hr = FY.GetPeriodWeights(dtFraSegEndDate.AddDays(+1), dtTmpEndDate, out iRemSegTPWeight))) { return(hr); } dblFraction = 0.5 * (iFraSegTPWeight) / ((double)(iRemSegTPWeight) + 0.5 * (iFraSegTPWeight)); dtRemSegStartDate = dtFraSegEndDate.AddDays(1); } pVal = true; return(true); }
public bool GetFirstYearSegmentInfo(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_dtPISDate, out FY)) || !(hr = FY.GetPeriod(m_dtPISDate, out pObjPeriod))) { return(hr); } dtEDate = FY.YREndDate; dtSDate = FY.YRStartDate; eCType = FY.CycleType; if (m_dtStartDate >= dtSDate && m_dtStartDate <= dtEDate && m_dtEndDate >= dtSDate && m_dtEndDate <= dtEDate) { dtEDate = m_dtEndDate; } // if( m_dtStartDate > dtEDate || m_dtStartDate < dtSDate ) // return S_FALSE; if (eCType == ECALENDARCYCLE_CYCLETYPE.CYCLETYPE_MONTHLY) { } else { dtPEDate = pObjPeriod.PeriodEnd; dtPSDate = pObjPeriod.PeriodStart; iDays = (int)((dtPEDate - m_dtPISDate).TotalDays + 1); iTotalDays = (int)((dtPEDate - dtPSDate).TotalDays + 1); if (!(hr = FY.GetCurrentPeriodWeight(m_dtPISDate, out iFraSegTPWeight))) { return(hr); } if (dtPEDate == dtEDate) { iRemSegTPWeight = 0; dblFraction = 1; dtFraSegStartDate = dtPSDate; dtFraSegEndDate = dtPEDate; dtRemSegStartDate = dtEDate; dtRemSegEndDate = dtEDate; } else { if (!(hr = FY.GetPeriodWeights(dtPEDate.AddDays(+1), dtEDate, out iRemSegTPWeight))) { return(hr); } dblFraction = ((double)(iFraSegTPWeight) * (double)(iDays) / (double)(iTotalDays)) / ((double)(iRemSegTPWeight) + (double)(iFraSegTPWeight) * (double)(iDays) / (double)(iTotalDays)); dtFraSegStartDate = dtPSDate; dtFraSegEndDate = dtPEDate; dtRemSegStartDate = dtFraSegEndDate.AddDays(+1); dtRemSegEndDate = dtEDate; } } return(false); }