internal void Create(BindingList<CurveReconciler.CompareItem> items_)
    {
      var grid = new BoundInfraGrid();
      grid.Bind(items_);
      grid.Dock=DockStyle.Fill;
      this.splitContainer1.Panel1.Controls.Add(grid);

      var chart = new SimpleWtsColumnChart();
      var sorted = items_.OrderBy(x => x.FIID);

      var headings = sorted.Select(x => x.SymmetryCode.Split(' ')[0]).ToArray();
      var values = sorted.Select(x => (x.DiffAsBps.HasValue) ? x.DiffAsBps.Value : 0d).ToArray();

      chart.SetYAxisFormat("##0.000#");
      chart.Dock = DockStyle.Fill;
      chart.Create(headings, values);
      this.splitContainer1.Panel2.Controls.Add(chart);
    }
    public void Create(WtsSeriesAnalyzer analyzer_, DateTime? startDate_=null, DateTime? endDate_=null)
    {
      var wtsDisplay = new SimpleWtsColumnChart();
      var c2vDisplay = new SimpleWtsColumnChart();
      var pnlDisplay = new SimpleWtsColumnChart();

      wtsDisplay.Dock = DockStyle.Fill;
      panel1.ClientArea.Controls.Add(wtsDisplay);

      c2vDisplay.Dock = DockStyle.Fill;
      panel2.ClientArea.Controls.Add(c2vDisplay);

      pnlDisplay.Dock = DockStyle.Fill;
      panel3.ClientArea.Controls.Add(pnlDisplay);

      ConstructGen<double> sourceWts = analyzer_.SourceWts;
      ConstructGen<double> sourceC2V = analyzer_.SourceC2V;
      ConstructGen<double> perf = analyzer_.Performance;

      if (startDate_ != null && endDate_ != null)
      {
        sourceWts = sourceWts.GetSubValues(startDate_.Value,endDate_.Value);
        sourceC2V = sourceC2V.GetSubValues(startDate_.Value, endDate_.Value);
        perf = perf.GetSubValues(startDate_.Value, endDate_.Value);
      }


      {
        IDictionary<string, double[]> wts = new Dictionary<string, double[]>();

        for (int i = 0; i < sourceWts.ArrayLength; ++i)
        {
          double[] w = sourceWts.GetColumnValues(i);
          double[] vals = new double[]
        {
          w.Min(),
          w.Average(),
          w.Max()
        };

          wts.Add(sourceWts.ColumnHeadings[i], vals);
        }

        wtsDisplay.Create<string, string>(wts, new string[] { "Min", "Avg", "Max" });
      }

      {
        IDictionary<string, double[]> c2v = new Dictionary<string, double[]>();

        for (int i = 0; i < sourceC2V.ArrayLength; ++i)
        {
          double[] w = sourceC2V.GetColumnValues(i);
          double[] vals = new double[]
        {
          w.Min(),
          w.Average(),
          w.Max()
        };

          c2v.Add(sourceC2V.ColumnHeadings[i], vals);
        }

        c2vDisplay.Create<string, string>(c2v, new string[] { "Min", "Avg", "Max" });
      }

      {
        double[] ds=new double[perf.ArrayLength];
        for(int i=0;i<ds.Length;++i)
          ds[i]=perf.GetColumnValues(i).Sum();
        pnlDisplay.Create(analyzer_.SourceWts.ColumnHeadings, ds);
      }

    }
Exemple #3
0
    public static void Go(DateTime date_)
    {
      LookFeel.SetupNoirModerneLookFeel();

      double thresholdForFlagging = 0.5d;

      var controlDict=new Dictionary<string,SimpleWtsColumnChart>();

      var listOfItems = Retriever.Retrieve(date_);

      var listOfAnomolies = new List<FlagListItem>();

      foreach (var distinctCurve in listOfItems.Select(x => x.CurveName).Distinct())
      {
        var curveSubset = listOfItems.Where(x => x.CurveName.Equals(distinctCurve));

        foreach (var distinctTenor in curveSubset.Select(x => x.Tenor).Distinct().OrderBy(x=>x))
        {
          var tenorAndCurveSubset = curveSubset.Where(x => x.Tenor == distinctTenor);

          var isins = new List<string>();
          var changeInMMS = new List<double>();

          foreach (var isin in tenorAndCurveSubset.OrderBy(x=>x.Maturity).Select(x => x.ISIN).Distinct())
          {
            var isinItems = tenorAndCurveSubset.Where(x => x.ISIN.Equals(isin)).OrderByDescending(x => x.ValueDate).ToArray();

            if (isinItems.Count() > 1)
            {
              isins.Add(isin);
              changeInMMS.Add((isinItems[0].MMS - isinItems[1].MMS) * 10000d);
            }
          }

          if (isins.Count() == 0)
            continue;

          for (int i = 1; i < isins.Count - 1; ++i)
          {
            var neighbourAverage = (changeInMMS[i - 1] + changeInMMS[i + 1]) / 2d;
            var diff = changeInMMS[i] - neighbourAverage;

            var bond = listOfItems.Where(x => string.Compare(isins[i], x.ISIN, true) == 0).First();

            if (Math.Abs(diff) >= thresholdForFlagging)
            {
              var timeToMaturity = bond.Maturity - DateTime.Today;

              // ignore bonds with less than one yeat to maturity
              if (timeToMaturity.Days < 252)
                continue;

              listOfAnomolies.Add(new FlagListItem()
              {
                MarkDate = date_,
                Curve = distinctCurve,
                Tenor = distinctTenor,
                Isin = isins[i],
                ChangeInMMS = changeInMMS[i],
                LeftBond = listOfItems.Where(x => string.Compare(isins[i-1], x.ISIN, true) == 0).First().Bond,
                ChangeInMMSLeft = changeInMMS[i - 1],
                RightBond = listOfItems.Where(x => string.Compare(isins[i+1], x.ISIN, true) == 0).First().Bond,
                ChangeInMMSRight = changeInMMS[i + 1],
                Bond=bond.Bond
              });
            }
          }

          var chart = new Controls.SimpleWtsColumnChart();
          chart.SetYAxisFormat("##0.000#");

          chart.Create(isins.ToArray(), changeInMMS.ToArray());
          chart.SetXAxisExtent(100);

          controlDict.Add(string.Format("{0}_{1}", distinctCurve, distinctTenor), chart);
        }
      }


      if (listOfAnomolies.Count <= 0) return;

      MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "beta: MMS change opportunity / change report", "body");
      msg.To.Clear();
      msg.To.Add("*****@*****.**");
      msg.To.Add("*****@*****.**");
      msg.IsBodyHtml = true;

      var builder = new StringBuilder();

      builder.AppendLine(string.Format("<h3>Unusual bond MMS moves on {0}</h3>", date_.ToString("dd-MMM-yyyy")));
      builder.AppendLine("<p>(Criteria is 0.5 bps difference from the average of the bonds either side)</p>");

      var grid = listOfAnomolies.DisplayInBoundGrid("blah", false);

      builder.AppendLine(grid.ToHTML());

      var resourceDict=new Dictionary<string,string>();

      foreach (string chartKey in listOfAnomolies.Select(x => string.Format("{0}_{1}", x.Curve, x.Tenor)).Distinct())
      {
        builder.AppendLine(string.Format("<h4>{0} - bp change in MMS per bond</h4>", chartKey));
        builder.AppendLine(string.Format("<img src=cid:{0}>", chartKey));

        var path = string.Format("{0}\\{1}_{2}.bmp", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), chartKey, date_.ToString("ddMMyyyy"));
        controlDict[chartKey].Chart.DataBind();
        LookFeel.ProcessChart(controlDict[chartKey]);
        controlDict[chartKey].Chart.SaveTo(path, System.Drawing.Imaging.ImageFormat.Bmp);
        resourceDict.Add(chartKey, path);
      }

      AlternateView htmlView = AlternateView.CreateAlternateViewFromString(builder.ToString(), null, "text/html");
      foreach (var k in resourceDict.Keys)
      {
        LinkedResource lr = new LinkedResource(resourceDict[k]);
        lr.ContentId = k;
        htmlView.LinkedResources.Add(lr);
      }

      msg.AlternateViews.Add(htmlView);


      try
      {
        Emailer.GetClient().Send(msg);
      }
      catch (Exception ex_)
      {
        Logger.Error("Error sending email", typeof (Analyzer), ex_);
      }

    }