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);
    }
Beispiel #2
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_);
      }

    }