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 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 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); }