Ejemplo n.º 1
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 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);
        }
        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.º 4
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.º 5
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 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);
        }