static void formatXaxis(ref GraphPane gPane)
        {
            DateTime minX = new DateTime(DateTime.Now.Year, 1, 1);
            DateTime maxX = new DateTime(DateTime.Now.Year, 12,31);
            double rangeX;
            rangeX = maxX.ToOADate() - minX.ToOADate();
            gPane.Legend.Position = LegendPos.InsideTopRight;

            gPane.XAxis.Scale.Min = minX.ToOADate() - (.025 * rangeX);
            gPane.XAxis.Scale.Max = maxX.ToOADate() + (.025 * rangeX);
            gPane.XAxis.Scale.MajorUnit = ZedGraph.DateUnit.Month;
            gPane.XAxis.Scale.MinorUnit = ZedGraph.DateUnit.Day;
            gPane.XAxis.Scale.Format = "MMMM";
        }
Example #2
0
        public static void SetCellDateTime(WorksheetPart worksheetPart, DateTime value, string columnName, uint rowIndex)
        {
            Cell cell = GetCell(worksheetPart.Worksheet, columnName, rowIndex);

            cell.CellValue = new CellValue(value.ToOADate().ToString("0.000#####"));
            cell.DataType = new EnumValue<CellValues>(CellValues.Number);
        }
Example #3
0
        public static void SetCellDate(WorksheetPart worksheetPart, DateTime value, string columnName, DocumentFormat.OpenXml.Spreadsheet.Row row)
        {
            Cell cell = GetCell(worksheetPart.Worksheet, columnName, row);

            cell.CellValue = new CellValue(value.ToOADate().ToString("0"));
            cell.DataType = new EnumValue<CellValues>(CellValues.Number);
        }
Example #4
0
 public DateCell(string id, DateTime dateTime, uint index)
 {
     this.DataType = CellValues.Date;
     this.CellReference = id + index;
     //this.StyleIndex = 10;
     this.CellValue = new CellValue { Text = dateTime.ToOADate().ToString() }; ;
 }
    public static double CalculateBEPrice(DateTime settle, DateTime maturity, decimal yield, decimal coupon)
    {
      var singleton = FinCADWrapper.Instance();
      lock (singleton.GetLock())
      {
        using (SLog.NDC("aaBond_BE_p"))
        {
          var ret = new double[] { double.NaN };

          FinCADHelpers.LogFinCADError(
            FincadFunctions.aaBond_BE_p(
              d_s: settle.ToOADate(),
              d_m: maturity.ToOADate(),
              cpn: (double)coupon * 0.01,
              princ_m: 100,
              yield: (double)yield,
              stat: new int[] { 1 },
              d_dated: 0,
              d_f_cpn: 0,
              return_stat: ref ret)
            );

          return FinCADHelpers.FinCADSingleResult(ret);
        }
      }
    }
Example #6
0
 private static DataPoint CreateDataPoint(double x, string axisLabel, DateTime start, DateTime end, string text, Color color) {
   var point = new DataPoint(x, new double[] { start.ToOADate(), end.ToOADate() });
   point.Color = color;
   point.Label = text;
   point.AxisLabel = axisLabel;
   return point;
 }
Example #7
0
        public Graph(System.Windows.Forms.CheckedListBox.CheckedItemCollection data, DateTime minDate, DateTime maxDate, ISaleService iSaleService, int mode, IReportService iReportService, ITimeSettingService iTimeSettingService, IProgramService iProgramService)
        {
            InitializeComponent();
            fillColor(colorList);
            _data = data;
            _minDate = minDate;
            _maxDate = maxDate;
            _iSaleService = iSaleService;
            _iReportService = iReportService;
            _iTimeSettingService = iTimeSettingService;
            _iProgramService = iProgramService;

            this.chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
            chart1.ChartAreas.Add("area");
            chart1.ChartAreas[0].AxisX.LabelStyle.Format = "dd-MM";
            chart1.ChartAreas["area"].AxisX.Interval = 1;
            chart1.ChartAreas["area"].AxisX.IntervalType = DateTimeIntervalType.Days;
            chart1.ChartAreas["area"].AxisX.IntervalOffset = 1;

            chart1.ChartAreas["area"].AxisX.Minimum = minDate.ToOADate();
            chart1.ChartAreas["area"].AxisX.Maximum = maxDate.ToOADate();
            if (mode == 1)
            {
                drawQuantity();
                label1.Text = "Quantity";
            }
            else
            {
                drawEfficiency();
                label1.Text = "Efficiency";
            }
        }
Example #8
0
 public DateCell(string header, DateTime dateTime, int index)
 {
     this.DataType = CellValues.Date;
     this.CellReference = header + index;
     this.StyleIndex = 1;
     this.CellValue = new CellValue { Text = dateTime.ToOADate().ToString() }; ;
 }
    public static double CalculatePTYield(DateTime settle, DateTime maturity, decimal price, decimal coupon)
    {
      var singleton = FinCADWrapper.Instance();
      lock (singleton.GetLock())
      {
        using (SLog.NDC("aaBond_PT_y"))
        {
          var ret = new double[] { double.NaN };

          FinCADHelpers.LogFinCADError(
            FincadFunctions.aaBond_PT_intl_y(
              d_s: settle.ToOADate(),
              d_m: maturity.ToOADate(),
              d_dated: 0,
              d_f_cpn: 0,
              cpn: (double) coupon*0.01,
              princ: 100,
              price: (double) price,
              freq: 1, // annual 
              acc: 2, // accrual method is act/act (isda)
              stat: new int[] {1}, // return the yield
              return_stat: ref ret)
            );

          return FinCADHelpers.FinCADSingleResult(ret);
        }
      }
    }
Example #10
0
        /// The AddNewPoint function is called for each series in the chart when
        /// new points need to be added.  The new point will be placed at specified
        /// X axis (Date/Time) position with a Y value in a range +/- 1 from the previous
        /// data point's Y value, and not smaller than zero.
        public void AddNewPoint(DateTime timeStamp, System.Windows.Forms.DataVisualization.Charting.Series ptSeries, int min, int max)
        {
            double newVal = 0;

              if (ptSeries.Points.Count > 0)
              {
            newVal = ptSeries.Points[ptSeries.Points.Count - 1].YValues[0] + ((rand.NextDouble() * 2) - 1);
              }

              if (newVal < 0)
            newVal = 0;

              // Add new data point to its series.
              ptSeries.Points.AddXY(timeStamp.ToOADate(), rand.Next(min, max));

              // remove all points from the source series older than 1.5 minutes.
              double removeBefore = timeStamp.AddSeconds((double)(30) * (-1)).ToOADate();
              //remove oldest values to maintain a constant number of data points
              while (ptSeries.Points[0].XValue < removeBefore)
              {
            ptSeries.Points.RemoveAt(0);
              }

              chart1.ChartAreas[0].AxisX.Minimum = ptSeries.Points[0].XValue;
              chart1.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds(30).ToOADate();

              chart1.ChartAreas[1].AxisX.Minimum = ptSeries.Points[0].XValue;
              chart1.ChartAreas[1].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds(30).ToOADate();

              chart1.ChartAreas[2].AxisX.Minimum = ptSeries.Points[0].XValue;
              chart1.ChartAreas[2].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds(30).ToOADate();

              chart1.Invalidate();
        }
Example #11
0
 public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
 {
     ValidateArguments(arguments, 2);
     var date = System.DateTime.FromOADate(ArgToDecimal(arguments, 0));
     var monthsToAdd = ArgToInt(arguments, 1);
     var resultDate = new System.DateTime(date.Year, date.Month, 1).AddMonths(monthsToAdd + 1).AddDays(-1);
     return CreateResult(resultDate.ToOADate(), DataType.Date);
 }
 public void DateFunctionShouldReturnACorrectDate()
 {
     var expectedDate = new DateTime(2012, 4, 3);
     var func = new Date();
     var args = FunctionsHelper.CreateArgs(2012, 4, 3);
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(expectedDate.ToOADate(), result.Result);
 }
 public void DateFunctionShouldMonthFromPrevYearIfMonthIsNegative()
 {
     var expectedDate = new DateTime(2011, 11, 3);
     var func = new Date();
     var args = FunctionsHelper.CreateArgs(2012, -1, 3);
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(expectedDate.ToOADate(), result.Result);
 }
Example #14
0
 public void DayShouldReturnDayInMonth()
 {
     var date = new DateTime(2012, 3, 12);
     var func = new Day();
     var args = FunctionsHelper.CreateArgs(date.ToOADate());
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(12, result.Result);
 }
Example #15
0
 /// <summary>
 /// Convert a Datetime to Unix Timestamp
 /// </summary>
 public static double DateTimeToUnixTimeStamp(DateTime time) {
     double timestamp = 0;
     try {
         timestamp = (time - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
     } catch (Exception err) {
         Log.Error("Time.DateTimeToUnixTimeStamp(): " + time.ToOADate().ToString() + err.Message);
     }
     return timestamp;
 }
 public void DateStringCompileResult()
 {
     var expected = new DateTime(2013, 1, 15);
     string dateString = expected.ToString("d");
     CompileResult result = new CompileResult(dateString, DataType.String);
     Assert.IsFalse(result.IsNumeric);
     Assert.IsTrue(result.IsDateString);
     Assert.AreEqual(expected.ToOADate(), result.ResultNumeric);
 }
Example #17
0
 public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
 {
     ValidateArguments(arguments, 3);
     var year = ArgToInt(arguments, 0);
     var month = ArgToInt(arguments, 1);
     var day = ArgToInt(arguments, 2);
     var date = new System.DateTime(year, 1, 1);
     month -= 1;
     date = date.AddMonths(month);
     date = date.AddDays((double)(day - 1));
     return CreateResult(date.ToOADate(), DataType.Date);
 }
 public static double CalculateGBP6mLiborSwapRate(double[,] dfCurve, DateTime spot, DateTime value, DateTime maturity, string holidayCenter)
 {
     var singleton = FinCADWrapper.Instance();
     lock (singleton.GetLock())
     {
         using (SLog.NDC("aaParSwap"))
         {
             double ret = double.NaN;
             FinCADHelpers.LogFinCADError(FincadFunctions.aaParSwap(value.ToOADate(), maturity.ToOADate(), spot.ToOADate(), 0, 0, 2, 4, 4, aaHolidaysWrapper.Holidays(holidayCenter), 4, 2, dfCurve, ref ret));
             return ret;
         }
     }
 }
Example #19
0
 public static double CalculateDEPrice(DateTime settle, DateTime maturity, decimal yield, decimal coupon)
 {
     var singleton = FinCADWrapper.Instance();
     lock (singleton.GetLock())
     {
         using (SLog.NDC("aaBond_DE_p"))
         {
             var ret = new double[] { double.NaN };
             FinCADHelpers.LogFinCADError(FincadFunctions.aaBond_DE_p(settle.ToOADate(), maturity.ToOADate(), 0, 0, (double)coupon * 0.01, 100, (double)yield, 1, new int[] { 1 }, ref ret));
             return FinCADHelpers.FinCADSingleResult(ret);
         }
     }
 }
 public static DateTime RollDate(DateTime date, int days, string calendar)
 {
     var singleton = FinCADWrapper.Instance();
     lock (singleton.GetLock())
     {
         using (SLog.NDC("aaDate_Settle"))
         {
             double ret = double.NaN;
             FinCADHelpers.LogFinCADError(FincadFunctions.aaDate_Settle(date.ToOADate(), days, aaHolidaysWrapper.Holidays(calendar), ref ret));
             return DateTime.FromOADate(ret);
         }
     }
 }
Example #21
0
 public static double CalculateImpliedVolatility(double bpv_, double underlyingPx_, double strike_, DateTime expiry_, DateTime valueDate_, double optionPrice_, double rate_, OptionType optionType_, AccrualMethod accMethod_ = AccrualMethod.Actual365_Fixed)
 {
   var singleton = FinCADWrapper.Instance();
   lock (singleton.GetLock())
   {
     using (SLog.NDC("aaBL_ivW"))
     {
       double ret = 0d;
       FinCADHelpers.LogFinCADError(FincadFunctions.aaBL_iv(underlyingPx_, strike_, expiry_.ToOADate(), valueDate_.ToOADate(), optionPrice_, rate_, (int)optionType_, (int)accMethod_, ref ret));
       return ret;
     }
   }
 }
Example #22
0
 public static double CalculateFRYield(DateTime settle, DateTime maturity, decimal price, decimal coupon)
 {
     var singleton = FinCADWrapper.Instance();
     lock (singleton.GetLock())
     {
         using (SLog.NDC("aaBond_FR_yields"))
         {
             var ret = new double[] { double.NaN };
             FinCADHelpers.LogFinCADError(FincadFunctions.aaBond_FR_yields(1 /*?*/, settle.ToOADate(), maturity.ToOADate(), (double)coupon * 0.01, (double)price, aaHolidaysWrapper.Holidays("TARGET"), new int[] { 1 }, ref ret));
             return FinCADHelpers.FinCADSingleResult(ret);
         }
     }
 }
Example #23
0
 public static DateTime RollDate(DateTime date, int units, int method, int convention, string calendar)
 {
     var singleton = FinCADWrapper.Instance();
     lock (singleton.GetLock())
     {
         using (SLog.NDC("aaDateAdjust"))
         {
             double ret = double.NaN;
             FinCADHelpers.LogFinCADError(FincadFunctions.aaDateAdjust(date.ToOADate(), units, method, convention, aaHolidaysWrapper.Holidays(calendar), ref ret));
             return DateTime.FromOADate(ret);
         }
     }
 }
 public static double[,] CalculateCashflowStrip(DateTime settle, DateTime maturity, decimal coupon)
 {
     var singleton = FinCADWrapper.Instance();
     lock (singleton.GetLock())
     {
         using (SLog.NDC("aaBond_strip_cf"))
         {
             var ret = new double[0, 0];
             var dfCurve = new double[1, 2] { { 1, 1 } };
             FinCADHelpers.LogFinCADError(FincadFunctions.aaBond_strip_cf(settle.ToOADate(), maturity.ToOADate(), 0, 0, 0, (double)coupon * 0.01, 100, 2, 3, new double[0], 1, 0, 1, dfCurve, ref ret));
             return ret;
         }
     }
 }
Example #25
0
        private ChartArea AddArea( string name, DateTime startdate )
        {
            var area = resultsChart.ChartAreas.Add( name + "ChartArea" );
            area.Visible = false;
            area.AxisX.IntervalType = DateTimeIntervalType.Weeks;
            area.AxisX.Interval = 1;
            area.AxisY.IsMarginVisible = true;

            area.AxisX.Minimum = startdate.ToOADate();
            area.AxisX.IsMarginVisible = false;
            area.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
            area.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;

            return area;
        }
Example #26
0
        public void SetTimeRange(DateTime From, DateTime To)
        {
            State.Wait();

            if (DataChart.Series.Count() <= 0)
                return;

            bool found = false;

            for (int index = 0; index < DataChart.Series.Count(); index++ )
            {
                Series tempSeries = Stock[StockFile.STOCKTYPE.OPENING]; //hard copy here

                for (int i = 0; i < tempSeries.Points.Count(); )
                {
                    //The order by default seems to be in reverse, so this should be first
                    if (tempSeries.Points[i].XValue >= To.ToOADate())
                    {
                        tempSeries.Points.Remove(tempSeries.Points[i]);
                        found = true;
                    }

                    //error checking in a pain, but meh
                    if (i >= tempSeries.Points.Count())
                        break;

                    if (tempSeries.Points[i].XValue < From.ToOADate())
                    {
                        tempSeries.Points.Remove(tempSeries.Points[i]);
                        found = true;
                    }

                    if (!found)
                        i++; //basically keep the index unless it is found to not match, because the index for the next should be the same

                    found = false;
                }

                DataChart.Series.RemoveAt(index);
                DataChart.Series.Insert(index, tempSeries);
            }

            DataChart.ChartAreas["StockArea"].RecalculateAxesScale();

            GC.Collect();

            State.Clear();
        }
        public void AddNewPoint(DateTime timeStamp, Series ptSeries, float nexVal)
        {
            ptSeries.Points.AddXY(timeStamp.ToOADate(), nexVal);

            double removeBefore = timeStamp.AddSeconds((double)(9) * (-1)).ToOADate();

            while (ptSeries.Points[0].XValue < removeBefore)
            {
                ptSeries.Points.RemoveAt(0);
            }

            chart.ChartAreas[0].AxisX.Minimum = ptSeries.Points[0].XValue;
            chart.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds(10).ToOADate();

            chart.Invalidate();
        }
Example #28
0
    static void WorkDays(DateTime[] holidays, DateTime date)
    {
        // Calculates today date
        DateTime now = DateTime.Parse(DateTime.Now.ToShortDateString());

        // Calculates all days
        int allDays = (int)Math.Abs(now.ToOADate() - date.ToOADate());

        // If the date is before today
        if (now > date)
        {
            DateTime temp = now;
            now = date;
            date = temp;
        }

        // Checks all days
        int holiday = 0;
        for (DateTime d = now; d < date; d = d.AddDays(1))
        {
            // Calculates the holidays from the weekends
            if (d.DayOfWeek.ToString() == "Sunday" || d.DayOfWeek.ToString() == "Saturday") holiday++;
            else
            {
                // Checks for some other holidays
                foreach (DateTime h in holidays)
                {
                    if (h.Day == d.Day && h.Month == d.Month) holiday++;
                }
            }
        }

        // Print the result
        Console.Write("\nFrom {0} to {1} there are ", now.ToString("dd MMMM yyyy"), date.ToString("dd MMMM yyyy"));

        // Prints the workdays
        Console.ForegroundColor = ConsoleColor.Green;
        Console.Write(allDays - holiday);
        Console.ResetColor();
        Console.Write(" workdays and ");

        // Prints the holidays
        Console.ForegroundColor = ConsoleColor.Green;
        Console.Write(holiday);
        Console.ResetColor();
        Console.WriteLine(" holidays");
    }
Example #29
0
 public void AverageArray()
 {
     // In the case of arrays, Average DOES NOT parse and include numeric strings, date strings, bools, unparsable strings, etc.
     Average average = new Average();
     var date1 = new DateTime(2013, 1, 5);
     var date2 = new DateTime(2013, 1, 15);
     double value = 2000;
     var result = average.Execute(new FunctionArgument[]
     {
         new FunctionArgument(new FunctionArgument[]
         {
             new FunctionArgument(1000.ToString("n")),
             new FunctionArgument(value),
             new FunctionArgument(6000.ToString("n")),
             new FunctionArgument(true),
             new FunctionArgument(date1),
             new FunctionArgument(date2.ToString("d")),
             new FunctionArgument("test")
         })
     }, ParsingContext.Create());
     Assert.AreEqual((2000 + date1.ToOADate()) / 2, result.Result);
 }
Example #30
0
        private void add2chart(string seriesName, string chartName, DateTime time, float value)
        {
            Series series = chart.Series.FindByName(seriesName);
            if (series == null)
            {
                series = new Series(seriesName) { ChartArea = chartName, ChartType = SeriesChartType.SplineArea, XValueType = ChartValueType.DateTime };
                chart.Series.Add(series);
            }

            series.Points.AddXY(time.ToOADate(), (double)value);

            DateTime now = DateTime.Now;
            chart.ChartAreas[chartName].AxisX.Maximum = now.ToOADate();
            chart.ChartAreas[chartName].AxisX.Minimum = (now.AddSeconds(-10)).ToOADate();
            foreach (var p in series.Points.Where(p => p.XValue < now.AddSeconds(-10).ToOADate()).ToArray())
            {
                series.Points.Remove(p);
            }

            var maxValue = series.Points.Max(p => p.YValues[0]);
            if (chart.ChartAreas[chartName].AxisY.Maximum < maxValue) chart.ChartAreas[chartName].AxisY.Maximum  = maxValue;
        }