Beispiel #1
0
 public static double DateFrequency2YearFraction(DateFrequency df)
 {
     switch (df)
     {
         case DateFrequency.Annual:
             return 1;
         case DateFrequency.Semiannual:
             return 0.5;
         case DateFrequency.Monthly:
             return 1.0 / 12;
         case DateFrequency.ThreePerAnnum:
             return 4.0 / 12;
         case DateFrequency.Quarterly:
             return 3.0 / 12;
         case DateFrequency.BiWeekly:
             return 2.0 / 52;
         case DateFrequency.Weekly:
             return 1.0 / 52;
         case DateFrequency.Daily:
             return 1.0 / 365;
         case DateFrequency.EveryTwoYears:
             return 2;
         case DateFrequency.EveryThreeYears:
             return 3;
         default:
             throw new Exception("Freq2Period: wrong input frequency!");
     }
 }
 /// <summary>
 /// Initializes the object.
 /// </summary>
 /// <param name="startDate">The start date.</param>
 /// <param name="endDate">The end date.</param>
 /// <param name="frequency">The frequency of the dates generated.</param>
 public ModelParameterDateSequence(DateTime startDate, DateTime endDate, DateFrequency frequency)
 {
     StartDate = startDate;
     EndDate = endDate;
     Frequency = frequency;
     GenerateSequenceFromStartDate = true;
     FollowFrequency = true;
     SkipPeriods = new ModelParameter((double)0);
 }
        /// <summary>
        /// Automatically generates Dates and stores them in 'Generated' property
        /// </summary>
        /// <param name="startDate">Start of generated sequence</param>
        /// <param name="endDate">End of generated sequence</param>
        /// <param name="days">Array of string days in week</param>
        /// <param name="frequency">Accepted values: 'Weekly', 'Biweekly', 'Monthly'</param>
        public DateGenerator(DateTime startDate, DateTime endDate, List <DayOfWeek> days, DateFrequency frequency)
        {
            StartDate = startDate;
            EndDate   = endDate;
            Days      = days;
            Frequency = frequency;

            Generate();
        }
Beispiel #4
0
        public DetailReportForm(List <DailyStatus> dailyStatuses, DateFrequency reportDateFreq, int fracDigNum)
        {
            this._dailyStatuses  = dailyStatuses;
            this._reportDateFreq = reportDateFreq;

            this.DecimalFormat = "{0:N" + fracDigNum.ToString() + "}";

            InitializeComponent();
        }
 /// <summary>
 /// Initializes the object.
 /// </summary>
 /// <param name="startDate">The start date.</param>
 /// <param name="endDate">The end date.</param>
 /// <param name="frequency">The frequency of the dates generated.</param>
 public ModelParameterDateSequence(DateTime startDate, DateTime endDate, DateFrequency frequency)
 {
     StartDate = startDate;
     EndDate   = endDate;
     Frequency = frequency;
     GenerateSequenceFromStartDate = true;
     FollowFrequency  = true;
     SkipPeriods      = new ModelParameter((double)0);
     SkipPeriodsArray = new ModelParameter((double)0);
 }
        /// <summary>
        /// Gets the string representation of the specified DateFrequency value.
        /// </summary>
        /// <param name="frequency">The DateFrequency to use.</param>
        /// <returns>The string representation of the specified DateFrequency object.</returns>
        public static string StringRepresentation(this DateFrequency frequency)
        {
            switch (frequency)
            {
            case DateFrequency.BiWeekly:
                return("Bi-weekly");

            case DateFrequency.Semiannual:
                return("Semi-annual");

            default:
                return(frequency.ToString());
            }
        }
        /// <summary>
        /// Adds a certain number of time to the specified date. The amount of time to be
        /// added is based on the value of the frequency and the number of periods to
        /// add to the start date.
        /// </summary>
        /// <param name="frequency">The frequency of the dates generation.</param>
        /// <param name="date">The reference date.</param>
        /// <param name="periods">The number of periods to add to the start date.</param>
        /// <param name="add">A value indicating if the period has to be added.</param>
        /// <returns>The DateTime where the specified number of periods has been added to
        /// the start date.</returns>
        public DateTime AddPeriod(DateFrequency frequency, DateTime date, int periods, bool add)
        {
            periods = add ? periods : -periods;
            switch (frequency)
            {
            case DateFrequency.Daily:
                return(date.AddDays(periods));

            case DateFrequency.Weekly:
                return(date.AddDays(7 * periods));

            case DateFrequency.BiWeekly:
                return(date.AddDays(14 * periods));

            case DateFrequency.Monthly:
                return(date.AddMonths(periods));

            case DateFrequency.EveryTwoMonths:
                return(date.AddMonths(2 * periods));

            case DateFrequency.Quarterly:
                return(date.AddMonths(3 * periods));

            case DateFrequency.ThreePerAnnum:
                return(date.AddMonths(4 * periods));

            case DateFrequency.Semiannual:
                return(date.AddMonths(6 * periods));

            case DateFrequency.Annual:
                return(date.AddYears(periods));

            case DateFrequency.EveryTwoYears:
                return(date.AddYears(2 * periods));

            case DateFrequency.EveryThreeYears:
                return(date.AddYears(3 * periods));

            default:
                return(date);
            }
        }
Beispiel #8
0
        public static double DateFrequency2YearFraction(DateFrequency df)
        {
            switch (df)
            {
            case DateFrequency.Annual:
                return(1);

            case DateFrequency.Semiannual:
                return(0.5);

            case DateFrequency.Monthly:
                return(1.0 / 12);

            case DateFrequency.EveryTwoMonths:
                return(2.0 / 12);

            case DateFrequency.ThreePerAnnum:
                return(4.0 / 12);

            case DateFrequency.Quarterly:
                return(3.0 / 12);

            case DateFrequency.BiWeekly:
                return(2.0 / 52);

            case DateFrequency.Weekly:
                return(1.0 / 52);

            case DateFrequency.Daily:
                return(1.0 / 365);

            case DateFrequency.EveryTwoYears:
                return(2);

            case DateFrequency.EveryThreeYears:
                return(3);

            default:
                throw new Exception("Freq2Period: wrong input frequency!");
            }
        }
        /// <summary>
        /// Initializes the object based on the current expressions using the given object as
        /// context.
        /// </summary>
        /// <param name="context">The context for the expressions.</param>
        /// <returns>false if the initialization is unsuccessfull; otherwise false.</returns>
        private bool InitializeObject(Project context)
        {
            try
            {
                startDate = GetDate(context as Project, StartDateExpression.Expr.GetValue(0, 0).ToString()).Date;
            }
            catch (Exception ex)
            {
                context.AddError("Start date is not valid. Details: " + ex.Message);
                return true;
            }

            try
            {
                endDate = GetDate(context as Project, EndDateExpression.Expr.GetValue(0, 0).ToString()).Date;
            }
            catch (Exception ex)
            {
                context.AddError("End date is not valid. Details: " + ex.Message);
                return true;
            }

            try
            {
                frequency = GetDateFrequency((Project)context, FrequencyExpression);
            }
            catch (Exception ex)
            {
                context.AddError("Frequency is not valid. Details: " + ex.Message);
                return true;
            }

            try
            {
                skipPeriodsParsed = (int)SkipPeriods.V();
            }
            catch (Exception ex)
            {
                context.AddError("The number of periods to skip is not valid. Details: " + ex.Message);
                return true;
            }

            return false;
        }
 /// <summary>
 /// Adds a certain number of time to the specified date. The amount of time to be
 /// added is based on the value of the frequency and the number of periods to
 /// add to the start date.
 /// </summary>
 /// <param name="frequency">The frequency of the dates generation.</param>
 /// <param name="date">The reference date.</param>
 /// <param name="periods">The number of periods to add to the start date.</param>
 /// <param name="add">A value indicating if the period has to be added.</param>
 /// <returns>The DateTime where the specified number of periods has been added to
 /// the start date.</returns>
 public DateTime AddPeriod(DateFrequency frequency, DateTime date, int periods, bool add)
 {
     periods = add ? periods : -periods;
     switch (frequency)
     {
         case DateFrequency.Daily:
             return date.AddDays(periods);
         case DateFrequency.Weekly:
             return date.AddDays(7 * periods);
         case DateFrequency.BiWeekly:
             return date.AddDays(14 * periods);
         case DateFrequency.Monthly:
             return date.AddMonths(periods);
         case DateFrequency.Quarterly:
             return date.AddMonths(3 * periods);
         case DateFrequency.ThreePerAnnum:
             return date.AddMonths(4 * periods);
         case DateFrequency.Semiannual:
             return date.AddMonths(6 * periods);
         case DateFrequency.Annual:
             return date.AddYears(periods);
         case DateFrequency.EveryTwoYears:
             return date.AddYears(2 * periods);
         case DateFrequency.EveryThreeYears:
             return date.AddYears(3 * periods);
         default:
             return date;
     }
 }
Beispiel #11
0
        double func(double x)
        {
            DateFrequency df = (DateFrequency)(int)x;

            return(DateFrequency2YearFraction(df));
        }
Beispiel #12
0
        private bool PrepareInputCheck()
        {
            try { this.Input_RegAddInv = Convert.ToDecimal(this.txtRegAddInv.Text); } catch { this.Input_RegAddInv = -1; }
            try { this.Input_AdjustRegInv = Convert.ToDecimal(this.txtAdjustRegInv.Text); } catch { this.Input_AdjustRegInv = -1; }

            if (this.Input_InvType == InvType.Once || this.Input_InvType == InvType.OnceAndRegular)
            {
                if (this.Input_OnceInv < 100)
                {
                    MessageBox.Show("一次性投入金额不能低于100元.", "输入有误");
                    return(false);
                }
            }

            if (this.Input_InvType == InvType.Regular || this.Input_InvType == InvType.OnceAndRegular)
            {
                if (this.Input_RegAddInv < 100)
                {
                    MessageBox.Show("定投金额不能低于100元.", "输入有误");
                    return(false);
                }

                if (this.Input_RegInvAdjType != RegInvAdjType.None)
                {
                    if (this.Input_AdjustRegInv < 100)
                    {
                        MessageBox.Show("定投增加金额不能低于100元.", "输入有误");
                        return(false);
                    }
                }
            }

            if (this.Input_InvTime < 1)
            {
                MessageBox.Show("投资时长不能短于1天.", "输入有误");
                return(false);
            }
            if (this.Input_SevChargeRate < 0)
            {
                MessageBox.Show("手续费率不能低于0%.", "输入有误");
                return(false);
            }

            if (this.Input_IsFixedReturn)
            {
                if (this.Input_FixedAnnualReturnsRate < 0)
                {
                    MessageBox.Show("固定平均年化收益率不能低于0%.", "输入有误");
                    return(false);
                }
            }
            else
            {
                if (this.Input_MinAnnualReturnsRate < 0)
                {
                    MessageBox.Show("最小年化收益率不能低于0%.", "输入有误");
                    return(false);
                }
                if (this.Input_MaxAnnualReturnsRate < 0)
                {
                    MessageBox.Show("最大年化收益率不能低于0%.", "输入有误");
                    return(false);
                }
                if (this.Input_MaxAnnualReturnsRate < this.Input_MinAnnualReturnsRate)
                {
                    MessageBox.Show("最大年化收益率不能低于最小年化收益率.", "输入有误");
                    return(false);
                }
                if (this.Input_MinLossRate < 0)
                {
                    MessageBox.Show("最小亏损率不能低于0%.", "输入有误");
                    return(false);
                }
                if (this.Input_MaxLossRate < 0)
                {
                    MessageBox.Show("最大亏损率不能低于0%.", "输入有误");
                    return(false);
                }
                if (this.Input_MaxLossRate < this.Input_MinLossRate)
                {
                    MessageBox.Show("最大亏损率不能低于最小亏损率.", "输入有误");
                    return(false);
                }
                if (this.Input_LossProb < 0)
                {
                    MessageBox.Show("亏损概率不能低于0%.", "输入有误");
                    return(false);
                }
            }

            int flag = this.cmbRegCycleUnit.SelectedIndex;

            this.Input_RegAddDateUnit = flag == 0 ? DateUnit.Year : (flag == 1 ? DateUnit.Month : DateUnit.Day);
            flag = this.cmbInvTimeUnit.SelectedIndex;
            this.Input_InvTimeDateUnit = flag == 0 ? DateUnit.Year : (flag == 1 ? DateUnit.Month : DateUnit.Day);
            flag = this.cmbShareOutCycleUnit.SelectedIndex;
            this.Input_ShareOutFreq = flag == 0 ? DateFrequency.Daily : DateFrequency.Monthly;
            flag = this.cmbCarryOverCycleUnit.SelectedIndex;
            this.Input_CarryOverFreq = flag == 0 ? DateFrequency.Daily : DateFrequency.Monthly;
            flag = this.cmbReportDetailUnit.SelectedIndex;
            this.Input_ReportDateFreq = flag == 0 ? DateFrequency.Daily : DateFrequency.Monthly;

            this.Input_FracDigNum = Int32.Parse(this.cmbFracDigNum.SelectedItem.ToString());

            switch (this.Input_InvTimeDateUnit)
            {
            case DateUnit.Year:
                this._endDay = this._startDay.AddYears(this.Input_InvTime);
                break;

            case DateUnit.Month:
                this._endDay = this._startDay.AddMonths(this.Input_InvTime);
                break;

            case DateUnit.Day:
                this._endDay = this._startDay.AddDays(this.Input_InvTime);
                break;

            default:
                break;
            }

            return(true);
        }
 /// <summary>
 /// Initializes the object.
 /// </summary>
 /// <param name="startDate">The start date.</param>
 /// <param name="endDate">The end date.</param>
 /// <param name="frequency">The frequency of the dates generated.</param>
 public ModelParameterDateSequence(DateTime startDate, DateTime endDate, DateFrequency frequency)
 {
     StartDate = startDate;
     EndDate = endDate;
     Frequency = frequency;
 }
        /// <summary>
        /// Initializes the object based on the current expressions using the given object as
        /// context.
        /// </summary>
        /// <param name="context">The context for the expressions.</param>
        /// <returns>false if the initialization is unsuccessfull; otherwise false.</returns>
        private bool InitializeObject(Project context)
        {
            try
            {
                startDate = GetDate(context as Project, StartDateExpression);
            }
            catch (Exception ex)
            {
                context.AddError("Start date is not valid. Details: " + ex.Message);
                return true;
            }

            try
            {
                endDate = GetDate(context as Project, EndDateExpression);
            }
            catch (Exception ex)
            {
                context.AddError("End date is not valid. Details: " + ex.Message);
                return true;
            }

            try
            {
                frequency = GetDateFrequency((Project)context, FrequencyExpression);
            }
            catch (Exception ex)
            {
                context.AddError("Frequency is not valid. Details: " + ex.Message);
                return true;
            }

            return false;
        }
 /// <summary>
 /// Adds a certain number of time to the specified date. The amount of time to be
 /// added is based on the value of the frequency and the number of periods to
 /// add to the start date.
 /// </summary>
 /// <param name="frequency">The frequency of the dates generation.</param>
 /// <param name="startDate">The start date.</param>
 /// <param name="periods">The number of periods to add to the start date.</param>
 /// <returns>The DateTime where the specified number of periods has been added to
 /// the start date.</returns>
 private DateTime AddPeriod(DateFrequency frequency, DateTime startDate, int periods)
 {
     switch (frequency)
     {
         case DateFrequency.Daily:
             return startDate.AddDays(periods);
         case DateFrequency.Weekly:
             return startDate.AddDays(7 * periods);
         case DateFrequency.BiWeekly:
             return startDate.AddDays(14 * periods);
         case DateFrequency.Monthly:
             return startDate.AddMonths(periods);
         case DateFrequency.Quarterly:
             return startDate.AddMonths(3 * periods);
         case DateFrequency.Semiannual:
             return startDate.AddMonths(6 * periods);
         case DateFrequency.Annual:
             return startDate.AddYears(periods);
         default:
             return startDate;
     }
 }