Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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 GetLastYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            DateTime      dtSDate;
            DateTime      dtEDate;
            DateTime      dtPEDate;
            bool          hr;
            IBACalcPeriod pObjIPd;
            IBAFiscalYear FY;

            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);
            }
            dtEDate = FY.YREndDate;
            dtSDate = FY.YRStartDate;

            if (dtDate >= dtSDate && dtDate <= dtEDate &&
                m_dtStartDate >= dtSDate && m_dtStartDate <= dtEDate)
            {
                if (!(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd)))
                {
                    return(hr);
                }
                dtPEDate = pObjIPd.PeriodEnd;

                if (dtDate < dtPEDate)
                {
                    return(GetFirstYearFactor(dtDate, out pVal));
                }
                else
                {
                    pVal = 0;
                }
            }
            else
            {
                return(GetFirstYearFactor(dtDate, out pVal));
            }

            return(true);
        }
        public bool Initialize(IBACalendar calendar, DateTime PlacedInService, double Life)
        {
            int           iYear;
            int           iMonth;
            int           iDay;
            IBACalcPeriod pObjPeriod;
            IBAFiscalYear FY;
            bool          hr;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;


            if (calendar == null || PlacedInService <= DateTime.MinValue || Life <= 0)
            {
                return(false);
            }

            m_pObjCalendar = null;
            m_pObjCalendar = calendar;
            m_dtPISDate    = PlacedInService;
            m_dblLife      = Life;

            if (!(hr = m_pObjCalendar.GetFiscalYear(m_dtPISDate, out FY)) ||
                !(hr = FY.GetPeriod(m_dtPISDate, out pObjPeriod)))
            {
                return(hr);
            }
            dtTmpStartDate = FY.YRStartDate;
            dtTmpEndDate   = FY.YREndDate;
            //calc the deemed start date
            m_iPdNum = pObjPeriod.PeriodNum;
            //deemed start date
            m_dtStartDate = pObjPeriod.PeriodStart;

            //used the deemed start date to calc deemed end date
            iYear  = m_dtStartDate.Year + (int)(Life);
            iMonth = m_dtStartDate.Month + (int)((Life - (int)(Life)) * 12);
            iDay   = m_dtStartDate.Day;

            //deemed end date
            if (iMonth > 12)
            {
                iMonth -= 12;
                iYear++;
            }
            m_dtEndDate = new DateTime(iYear, iMonth, iDay).AddDays(-10);
            pObjPeriod  = null;
            FY          = null;
            if (!(hr = m_pObjCalendar.GetFiscalYear(m_dtEndDate, out FY)) ||
                !(hr = FY.GetPeriod(m_dtEndDate, out pObjPeriod)))
            {
                return(hr);
            }
            m_dtEndDate = pObjPeriod.PeriodEnd;
            return(true);
        }
Ejemplo n.º 5
0
        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 GetDisposalYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            IBACalcPeriod pObjIPd1;
            IBACalcPeriod pObjIPd2;
            IBAFiscalYear FY;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;
            short         iPeriodNum1;
            short         iPeriodNum2;
            double        dFYFactor1;
            double        dFYFactor2;
            bool          hr;

            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)
            {
                //in the same year as first year
                if (!(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd1)) ||
                    !(hr = FY.GetPeriod(dtDate, out pObjIPd2)))
                {
                    return(hr);
                }
                iPeriodNum1 = pObjIPd1.PeriodNum;
                iPeriodNum2 = pObjIPd2.PeriodNum;

                if (iPeriodNum1 == iPeriodNum2)
                {
                    //in the same month as the first month
                    pVal = 0;
                    //			if ( FAILED(hr = GetFirstYearFactor(dtDate, pVal)) )
                    //				return hr;
                }
                else
                {
                    //in diff month
                    if (!(hr = GetFirstYearFactor(m_dtStartDate, out dFYFactor1)) ||
                        !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                    {
                        return(hr);
                    }
                    pVal = dFYFactor1 - dFYFactor2;
                }
            }
            else
            {
                if (!(hr = FY.GetFiscalYearFraction(out dFYFactor1)) ||
                    !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                {
                    return(hr);
                }

                //		if ( dFYFactor1 >= RemainingLife && RemainingLife > 0.01 )
                //		{
                //			pVal = (dFYFactor1 - dFYFactor2) / RemainingLife;
                //		}
                //		else
                //		{
                pVal = dFYFactor1 - dFYFactor2;
                //		}
            }
            return(true);
        }
Ejemplo n.º 7
0
        public bool GetLastYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            IBAFiscalYear FY;
            IBACalcPeriod pObjIPd1;
            IBACalcPeriod pObjIPd2;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;
            double        dFYFactor1;
            double        dFYFactor2;
            short         iPeriodNum1;
            short         iPeriodNum2;
            bool          hr;

            pVal = 0.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 (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)
            {
                //the dispdate is in the first year
                if (!(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd1)) ||
                    !(hr = FY.GetPeriod(dtDate, out pObjIPd2)))
                {
                    return(hr);
                }
                iPeriodNum1 = pObjIPd1.PeriodNum;
                iPeriodNum2 = pObjIPd2.PeriodNum;

                if (iPeriodNum1 == iPeriodNum2)
                {
                    //if in the same m_onth, the factor should be the same
                    pVal = 0;
                    //            if ( FAILED(hr = GetFirstYearFactor(dtDate, pVal)) )
                    //				return hr;
                }
                else
                {
                    //if in the diff m_onth, find the difference
                    //
                    //-+---------------+------------------------------|------.
                    // startdate      dispdate                      year end
                    // |<-- the diff ->|
                    // "the dif" x "anual amount" is the amt for this period
                    if (!(hr = GetFirstYearFactor(m_dtStartDate, out dFYFactor1)) ||
                        !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                    {
                        return(hr);
                    }
                    pVal = dFYFactor1 - dFYFactor2;
                }
            }
            else
            {
                //in diff year
                if (!(hr = FY.GetFiscalYearFraction(out dFYFactor1)) ||
                    !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                {
                    return(hr);
                }
                pVal = dFYFactor1 - dFYFactor2;
            }

            return(true);
        }
        public bool GetDisposalYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            IBACalcPeriod pObjIPd;
            IBAFiscalYear FY;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;
            DateTime      dtMidDate;
            DateTime      dtPEndDate;
            double        dFYFraction;
            double        dFYFactor;
            bool          hr;

            pVal = 0.0;

            if (m_pObjCalendar == null)
            {
                throw new Exception("Avg Convention not initialized.");
            }

            if (dtDate <= DateTime.MinValue)
            {
                dtDate = m_dtEndDate;
            }

            if (!(hr = m_pObjCalendar.GetFiscalYear(dtDate, out FY)) ||
                !(hr = FY.GetMidYearDate(out dtMidDate)))
            {
                return(hr);
            }
            dtTmpStartDate = FY.YRStartDate;
            dtTmpEndDate   = FY.YREndDate;


            //    mobjIFY.GetPeriod mdtStartDate, objIPd
            if (m_bFirstHalf)
            {
                //if PIS is in the first half of the year
                if (dtDate >= dtTmpStartDate && dtDate <= dtTmpEndDate &&
                    m_dtStartDate >= dtTmpStartDate && m_dtStartDate <= dtTmpEndDate)
                {
                    // In first year
                    if (!(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd)))
                    {
                        return(hr);
                    }
                    dtPEndDate = pObjIPd.PeriodEnd;

                    if (dtDate < dtPEndDate)
                    {
                        if (!(hr = GetFirstYearFactor(dtDate, out pVal)))
                        {
                            return(hr);
                        }
                    }
                    else
                    {
                        if (!(hr = FY.GetFiscalYearFraction(out dFYFraction)) ||
                            !(hr = GetFirstYearFactor(dtDate, out dFYFactor)))
                        {
                            return(hr);
                        }
                        pVal = 0.5 * (dFYFraction - dFYFactor);
                    }
                }
                else //if( dtDate >= dtTmpStartDate && dtDate <= dtTmpEndDate &&
                //m_dtEndDate >= dtTmpStartDate && m_dtEndDate <= dtTmpEndDate )
                {
                    // in the last year
                    if (!(hr = FY.GetMidYearDate(out dtMidDate)))
                    {
                        return(hr);
                    }
                    if (dtDate < dtMidDate)
                    {
                        pVal = 0;
                    }
                    else
                    {
                        if (!(hr = FY.GetFiscalYearFraction(out dFYFraction)))
                        {
                            return(hr);
                        }
                        if (dFYFraction > RemainingLife)
                        {
                            pVal = RemainingLife * 0.5;
                        }
                        else
                        {
                            pVal = dFYFraction * 0.5;
                        }
                    }
                }
                //        else
                //		{
                //			if ( FAILED(hr = FY.GetFiscalYearFraction(out dFYFraction)) ||
                //				 FAILED(hr = GetFirstYearFactor(dtDate, out dFYFactor)) )
                //				return hr;
                //            pVal = 0.5 * (dFYFraction - dFYFactor);
                //        }
            }
            else // PIS in second half of the year.
            {
                if (dtDate < m_dtStartDate)
                {
                    // In PIS year
                    //			if ( dtDate > dtMidDate )
                    //			{
                    //				if ( FAILED(hr = FY.GetFiscalYearFraction(out dFYFraction)) ||
                    //					 FAILED(hr = GetFirstYearFactor(dtMidDate, out dFYFactor)) )
                    //					return hr;
                    //				pVal = dFYFraction - 0.5 * dFYFactor;
                    //			}
                    //			else
                    pVal = 0;
                }
                else //if( dtDate >= dtTmpStartDate && dtDate <= dtTmpEndDate &&
                //m_dtEndDate >= dtTmpStartDate && m_dtEndDate <= dtTmpEndDate )
                {
                    // in the last year
                    if (!(hr = FY.GetFiscalYearFraction(out dFYFraction)) ||
                        !(hr = FY.GetMidYearDate(out dtMidDate)))
                    {
                        return(hr);
                    }

                    if (dFYFraction > RemainingLife)
                    {
                        if (dtDate < dtMidDate)
                        {
                            pVal = RemainingLife * 0.5;
                        }
                        else
                        {
                            pVal = RemainingLife;
                        }
                    }
                    else
                    {
                        if (dtDate < dtMidDate)
                        {
                            pVal = dFYFraction * 0.5;
                        }
                        else
                        {
                            pVal = dFYFraction;
                        }
                    }
                }
                //else
                //{
                //	if ( FAILED(hr = FY.GetFiscalYearFraction(out dFYFraction)) ||
                //		 FAILED(hr = GetFirstYearFactor(dtDate, out dFYFactor)) )
                //		return hr;
                //    pVal = 0.5 * (dFYFraction - dFYFactor);
                //}
            }

            return(true);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public bool GetDisposalYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            IBACalcPeriod pObjIPd1;
            IBACalcPeriod pObjIPd2;
            IBAFiscalYear FY;
            DateTime      dtSDate;
            DateTime      dtEDate;
            short         iPNum1;
            short         iPNum2;
            double        dFactor1;
            double        dFactor2;
            bool          hr;

            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);
            }
            dtSDate = FY.YRStartDate;
            dtEDate = FY.YREndDate;

            m_pMonthlyYear.FiscalYearInfo = FY;
            m_pMonthlyYear.DeemedFYDates();

            if (dtDate >= dtSDate && dtDate <= dtEDate &&
                m_dtStartDate >= dtSDate && m_dtStartDate <= dtEDate)
            {
                //the dispdate is in the first year
                if (!(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd1)) ||
                    !(hr = FY.GetPeriod(dtDate, out pObjIPd2)))
                {
                    return(hr);
                }
                iPNum1 = pObjIPd1.PeriodNum;
                iPNum2 = pObjIPd2.PeriodNum;

                if (iPNum1 == iPNum2)
                {
                    //if in the same month, the factor should be the same
                    pVal = 0;
                    return(true);
                    //            return GetFirstYearFactor(m_pMonthlyYear.GetFullMonthDate(dtDate), pVal);
                }
                else
                {
                    //if in the diff month, find the difference
                    //
                    //-+---------------+------------------------------|------.
                    // startdate      dispdate                      year end
                    // |<-- the diff .|
                    // "the dif" x "anual amount" is the amt for this period
                    if (!(hr = GetFirstYearFactor(m_dtStartDate, out dFactor1)) ||
                        !(hr = GetFirstYearFactor(m_pMonthlyYear.GetFullMonthDate(dtDate), out dFactor2)))
                    {
                        return(hr);
                    }
                    pVal = dFactor1 - dFactor2;
                }
            }
            else
            {
                //in diff year
                if (!(hr = FY.GetFiscalYearFraction(out dFactor1)))
                {
                    return(hr);
                }

                //		if ( dFactor1 >= RemainingLife && RemainingLife > 0.01 )
                //		{
                //			pVal = m_pMonthlyYear.GetLastYearFactor(m_pMonthlyYear.GetFullMonthDate(dtDate)) / RemainingLife;
                //		}
                //		else
                //		{
                pVal = m_pMonthlyYear.GetLastYearFactor(m_pMonthlyYear.GetFullMonthDate(dtDate));
                //		}
            }

            return(true);
        }
Ejemplo n.º 11
0
        public bool GetLastYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            IBAFiscalYear FY;
            IBACalcPeriod pObjIPd1;
            IBACalcPeriod pObjIPd2;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;
            short         iPeriodNum1;
            short         iPeriodNum2;
            double        dFYFactor1;
            double        dFYFactor2;
            bool          hr;

            pVal = 0.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)
            {
                //in the same year as first year
                if (!(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd1)) ||
                    !(hr = FY.GetPeriod(dtDate, out pObjIPd2)))
                {
                    return(hr);
                }
                iPeriodNum1 = pObjIPd1.PeriodNum;
                iPeriodNum2 = pObjIPd2.PeriodNum;
                if (iPeriodNum1 == iPeriodNum2)
                {
                    //in the same month as the first month
                    if (!(hr = GetFirstYearFactor(dtDate, out pVal)))
                    {
                        return(hr);
                    }
                }
                else
                {
                    //in diff month
                    if (!(hr = GetFirstYearFactor(m_dtStartDate, out dFYFactor1)) ||
                        !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                    {
                        return(hr);
                    }
                    pVal = dFYFactor1 - dFYFactor2;
                }
            }
            else
            {
                IBACalcPeriod pObjPeriod;
                DateTime      periodEnd;


                if (!(hr = FY.GetPeriod(dtDate, out pObjPeriod)) ||
                    !(hr = GetFirstYearFactor(dtDate, out dFYFactor1)))
                {
                    return(hr);
                }
                periodEnd = pObjPeriod.PeriodEnd;

                if (periodEnd >= dtTmpEndDate)
                {
                    dFYFactor2 = 0;
                }
                else
                {
                    if (!(hr = GetFirstYearFactor(periodEnd.AddDays(+1), out dFYFactor2)))
                    {
                        return(hr);
                    }
                }

                pVal = dFYFactor1 - dFYFactor2;
            }
            return(true);
        }
Ejemplo n.º 12
0
        public bool GetLastYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            IBAFiscalYear FY;
            IBACalcPeriod pObjIPd1;
            IBACalcPeriod pObjIPd2;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;
            short         iPeriodNum1;
            short         iPeriodNum2;
            double        dFYFactor1;
            double        dFYFactor2;
            bool          hr;

            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)
            {
                if (!(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd1)) ||
                    !(hr = FY.GetPeriod(dtDate, out pObjIPd2)))
                {
                    return(hr);
                }
                iPeriodNum1 = pObjIPd1.PeriodNum;
                iPeriodNum2 = pObjIPd2.PeriodNum;

                //if the dispdate is in the first year
                if (iPeriodNum1 >= iPeriodNum2)
                {
                    //in the same period
                    if (!(hr = GetFirstYearFactor(m_dtStartDate, out dFYFactor1)) ||
                        !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                    {
                        return(hr);
                    }

                    pVal = dFYFactor1 - dFYFactor2;
                }
                else
                {
                    //in different period
                    if (!(hr = GetFirstYearFactor(m_dtStartDate, out dFYFactor1)) ||
                        !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                    {
                        return(hr);
                    }

                    pVal = dFYFactor1 - dFYFactor2;
                }
            }
            else
            {
                //other years
                if (!(hr = FY.GetFiscalYearFraction(out dFYFactor1)) ||
                    !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                {
                    return(hr);
                }

                pVal = dFYFactor1 - dFYFactor2;
            }
            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);
        }
        public bool Initialize(IBACalendar calendar, DateTime PlacedInService, double Life)
        {
            int           iYear;
            int           iMonth;
            int           iDay;
            IBACalcPeriod pObjPeriod;
            IBAFiscalYear FY;
            bool          hr;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;
            DateTime      dtMidDate;
            bool          bFirstHalf = false;

            if (calendar == null || PlacedInService <= DateTime.MinValue || Life <= 0)
            {
                return(false);
            }

            m_pObjCalendar = null;
            m_pObjCalendar = calendar;
            m_dtPISDate    = PlacedInService;
            m_dblLife      = Life;

            m_pObjCalendar.GetFiscalYear(m_dtPISDate, out FY);
            dtTmpStartDate = FY.YRStartDate;
            dtTmpEndDate   = FY.YREndDate;
            FY.GetPeriod(m_dtPISDate, out pObjPeriod);
            FY.GetMidPeriodDate(m_dtPISDate, out dtMidDate);

            //determine the pis in fisrt or second half of a month
            if (m_dtPISDate < dtMidDate)
            {
                bFirstHalf = true;
            }

            //calc the deemed start date
            if (bFirstHalf)
            {
                //place in first half(full month)
                m_dtStartDate = pObjPeriod.PeriodStart;
            }
            else
            {
                //place in second half(next month)
                m_dtStartDate = pObjPeriod.PeriodEnd;
                m_dtStartDate = m_dtStartDate.AddDays(1);
            }

            //calc the deemed end date
            iYear  = (m_dtStartDate.Year) + (int)(m_dblLife);
            iMonth = (m_dtStartDate.Month) + (int)((m_dblLife - (int)(m_dblLife)) * 12);
            iDay   = (m_dtStartDate.Day);

            //the deemed end date
            if (iMonth > 12)
            {
                iMonth -= 12;
                iYear++;
            }
            m_dtEndDate = new DateTime(iYear, iMonth, iDay).AddDays(-1);

            //    m_dtStartDate = m_dtPISDate;

            return(true);
        }
        public bool GetLastYearFactor(double RemainingLife, DateTime dtDate, out double pVal)
        {
            IBAFiscalYear FY;
            IBACalcPeriod pObjIPd1;
            IBACalcPeriod pObjIPd2;
            DateTime      dtTmpEndDate;
            DateTime      dtTmpStartDate;
            DateTime      dtMidDate;
            double        dFYFactor1;
            double        dFYFactor2;
            short         iPeriodNum1;
            short         iPeriodNum2;
            bool          hr;

            pVal = 0.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)
            {
                if (!(hr = FY.GetPeriod(dtDate, out pObjIPd2)) ||
                    !(hr = FY.GetPeriod(m_dtStartDate, out pObjIPd1)) ||
                    !(hr = FY.GetMidPeriodDate(m_dtStartDate, out dtMidDate)))
                {
                    return(hr);
                }

                iPeriodNum1 = pObjIPd1.PeriodNum;
                iPeriodNum2 = pObjIPd2.PeriodNum;
                if (iPeriodNum1 == iPeriodNum2 ||
                    (iPeriodNum1 + 1 == iPeriodNum2 && m_dtStartDate >= dtMidDate))
                {
                    if (!(hr = FY.GetMidPeriodDate(dtDate, out dtMidDate)))
                    {
                        return(hr);
                    }

                    if (dtDate < dtMidDate)
                    {
                        if (!(hr = GetFirstYearFactor(m_dtStartDate, out pVal)))
                        {
                            return(hr);
                        }
                    }
                    else
                    {
                        dtMidDate = pObjIPd2.PeriodEnd;
                        if (!(hr = GetFirstYearFactor(dtMidDate.AddDays(+1), out pVal)))
                        {
                            return(hr);
                        }
                    }
                }
                else
                {
                    if (!(hr = GetFirstYearFactor(m_dtStartDate, out dFYFactor1)) ||
                        !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                    {
                        return(hr);
                    }

                    pVal = dFYFactor1 - dFYFactor2;
                }
            }
            else
            {
                if (!(hr = FY.GetFiscalYearFraction(out dFYFactor1)) ||
                    !(hr = GetFirstYearFactor(dtDate, out dFYFactor2)))
                {
                    return(hr);
                }

                pVal = dFYFactor1 - dFYFactor2;
            }

            return(true);
        }