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 GetFirstYearFactor(DateTime dtDate, out double pVal) { short iPeriods; short iCurWeight; short iAnuWeight; DateTime dtTmpEndDate; DateTime dtTmpStartDate; IBAFiscalYear FY; bool hr; pVal = 0.0; if (m_pObjCalendar == null) { throw new Exception("Avg Convention not initialized."); } if (dtDate <= DateTime.MinValue) { throw new Exception("Avg Convention not initialized."); } if (!(hr = m_pObjCalendar.GetFiscalYear(dtDate, out FY)) || !(hr = FY.GetRemainingPeriodWeights(dtDate, out iPeriods)) || !(hr = FY.GetCurrentPeriodWeight(dtDate, out iCurWeight)) || !(hr = FY.GetTotalAnnualPeriodWeights(out iAnuWeight))) { return(hr); } dtTmpStartDate = FY.YRStartDate; dtTmpEndDate = FY.YREndDate; pVal = ((double)(iPeriods) + (double)(iCurWeight)) / iAnuWeight; 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) { 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 GetFirstYearFactor(DateTime dtDate, out double pVal) { IBAFiscalYear FY; int iDays; int iTotalDays; short iPeriods; short iCurWeight; short iAnuWeight; IBACalcPeriod pObjPeriod; DateTime dtTmpEndDate; DateTime dtTmpStartDate; DateTime dtTmpEDate; DateTime dtTmpSDate; bool hr; pVal = 0.0; if (m_pObjCalendar == null) { throw new Exception("Avg Convention not initialized."); } if (dtDate <= DateTime.MinValue) { throw new Exception("Avg Convention not initialized."); } if (!(hr = m_pObjCalendar.GetFiscalYear(dtDate, out FY))) { return(hr); } dtTmpStartDate = FY.YRStartDate; dtTmpEndDate = FY.YREndDate; if (!(hr = FY.GetPeriod(dtDate, out pObjPeriod))) { return(hr); } dtTmpEDate = pObjPeriod.PeriodEnd; dtTmpSDate = pObjPeriod.PeriodStart; if (!(hr = FY.GetRemainingPeriodWeights(dtDate, out iPeriods)) || !(hr = FY.GetCurrentPeriodWeight(dtDate, out iCurWeight)) || !(hr = FY.GetTotalAnnualPeriodWeights(out iAnuWeight))) { return(hr); } iDays = ((int)((dtTmpEDate - dtDate).TotalDays + 1)); iTotalDays = ((int)((dtTmpEDate - dtTmpSDate).TotalDays + 1)); pVal = ((double)(iPeriods) + iCurWeight * (iDays) / (double)(iTotalDays)) / (double)(iAnuWeight); 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); }
public bool GetFirstYearFactor(DateTime dtDate, out double pVal) { short iPeriods; short iRemPeriods = 0; short iCurWeight; short iAnuWeight; bool bFirstHalf = false; DateTime dtTmpEndDate; DateTime dtTmpStartDate; DateTime dtMidDate; IBAFiscalYear FY; bool hr; pVal = 0.0; if (m_pObjCalendar == null) { throw new Exception("Avg Convention not initialized."); } if (dtDate <= DateTime.MinValue) { throw new Exception("Avg Convention not initialized."); } if (!(hr = m_pObjCalendar.GetFiscalYear(dtDate, out FY))) { return(false); } dtTmpStartDate = FY.YRStartDate; dtTmpEndDate = FY.YREndDate; FY.GetMidPeriodDate(dtDate, out dtMidDate); FY.GetRemainingPeriodWeights(dtDate, out iPeriods); FY.GetCurrentPeriodWeight(dtDate, out iCurWeight); FY.GetTotalAnnualPeriodWeights(out iAnuWeight); if (dtDate < dtMidDate) { bFirstHalf = true; } //if deemed start date and deemed end date fall in the same year //(which happens only when life < 1year) //we need to fix first year factor by subtracting period weights //after deemed end period if (m_dtStartDate >= dtTmpStartDate && m_dtEndDate < dtTmpEndDate) { if (!(hr = FY.GetRemainingPeriodWeights(m_dtEndDate, out iRemPeriods))) { return(hr); } } if (bFirstHalf) { pVal = ((double)(iPeriods) + (double)(iCurWeight) - (double)(iRemPeriods)) / iAnuWeight; } else { pVal = ((double)(iPeriods) - (double)(iRemPeriods)) / iAnuWeight; } return(true); }
public bool GetDisposalYearFactor(double RemainingLife, DateTime dtDate, out double pVal) { IBAFiscalYear FY; IBACalcPeriod pObjIPd1; IBACalcPeriod pObjIPd2; DateTime dtTmpEndDate; DateTime dtTmpStartDate; DateTime dtMidDate; DateTime dtMidDate2; double dFYFactor1; double dFYFactor2; short iPeriodNum1; short iPeriodNum2; short iPeriods1; short iCurWeight1; short iPeriods2; short iCurWeight2; short iAnuWeight; bool hr; // if ( RemainingLife > 0.99 && RemainingLife < 0.01 ) // return GetLastYearFactor(RemainingLife, dtDate, pVal); pVal = 0; if (m_pObjCalendar == null) { throw new Exception("Avg Convention not initialized."); } if (dtDate <= DateTime.MinValue) { dtDate = m_dtEndDate; } if (dtDate < m_dtStartDate) { dtDate = m_dtStartDate; } if (!(hr = m_pObjCalendar.GetFiscalYear(dtDate, out FY))) { return(hr); } dtTmpStartDate = FY.YRStartDate; dtTmpEndDate = FY.YREndDate; if (dtDate >= dtTmpStartDate && dtDate <= dtTmpEndDate && m_dtStartDate >= dtTmpStartDate && m_dtStartDate <= dtTmpEndDate) { // // We are in the first year // if (!(hr = FY.GetPeriod(dtDate, out pObjIPd2)) || !(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd1)) || !(hr = FY.GetMidPeriodDate(m_dtStartDate, out dtMidDate2)) || !(hr = FY.GetMidPeriodDate(dtDate, out dtMidDate))) { return(hr); } iPeriodNum1 = pObjIPd1.PeriodNum; iPeriodNum2 = pObjIPd2.PeriodNum; if (!(hr = FY.GetRemainingPeriodWeights(dtDate, out iPeriods1)) || !(hr = FY.GetCurrentPeriodWeight(dtDate, out iCurWeight1)) || !(hr = FY.GetRemainingPeriodWeights(m_dtStartDate, out iPeriods2)) || !(hr = FY.GetCurrentPeriodWeight(m_dtStartDate, out iCurWeight2)) || !(hr = FY.GetTotalAnnualPeriodWeights(out iAnuWeight))) { return(hr); } if (iPeriodNum1 == iPeriodNum2 || (iPeriodNum1 + 1 == iPeriodNum2 && m_dtStartDate >= dtMidDate)) { if (dtDate < dtMidDate) { pVal = 0; } else { pVal = ((double)(iCurWeight1)) / iAnuWeight; } } else { if (dtDate >= dtMidDate) { pVal = (double)(iCurWeight2 + iPeriods2 - iPeriods1) / iAnuWeight; } else { pVal = (double)(iCurWeight2 + iPeriods2 - iPeriods1 - iCurWeight1) / iAnuWeight; } } } else { if (!(hr = FY.GetFiscalYearFraction(out dFYFactor1)) || !(hr = GetFirstYearFactor(dtDate, out dFYFactor2))) { return(hr); } pVal = dFYFactor1 - dFYFactor2; } return(true); }