/// <summary>
    /// 
    /// </summary>
    /// <param name="field"></param>
    /// <returns>Each Column is a different.  Each Row is a different index point</returns>
    public ConstructGenGen<int, double> GetCombined(DataAroundEventField field)
    {
      if (m_cache.ContainsKey(field))
        return m_cache[field];

      if (DataInterEvents == null || DataInterEvents.Length == 0)
        return null;

      var allEvents = DataInterEvents.Where(x => x.HasProcessedData).ToArray();

      var allindexes =
        allEvents.Select(x => x[field].Select(p => p.Index).ToArray()).SelectMany(x => x).OrderBy(x => x).ToArray();

      var minIndex = allindexes[0];
      var maxIndex = allindexes[allindexes.Length - 1];

      var combined = new ConstructGenGen<int, double>(allEvents.Select(x => x.EventSpan.ToString()).ToArray());

      for (int i = minIndex; i <= maxIndex; ++i)
        combined.SetValues(i, ExtensionMethods.CreateArrayRep(double.NaN, combined.ArrayLength));

      for (int eventIndex = 0; eventIndex < allEvents.Length; ++eventIndex)
      {
        foreach (var point in allEvents[eventIndex][field])
          combined.SetValue(point.Index, eventIndex, point.Value);
      }

      m_cache[field] = combined;

      //m_combined.DisplayInGrid("title", "span");

      return combined;
    }
Beispiel #2
0
    public ConstructGenGen<RelativeDate, Line> GetSubLinesAsRelativeDates(Func<RelativeDate, bool> shouldIncludeFunction_)
    {
      var data = LinesAsRelativeDates();
      var ret = new ConstructGenGen<RelativeDate, Line>(1);

      try
      {
        m_lock.EnterReadLock();

        foreach (var v in data.Keys.Where(x => shouldIncludeFunction_(x)))
          ret.SetValues(v, data.GetValues(v),ConstructGenGen<RelativeDate,Line>.KeyOptionsWhenAdding.AddEveryTime);
      }
      finally
      {
        m_lock.ExitReadLock();
      }

      return ret;
    }
Beispiel #3
0
    private void reload2CMTSpread_TopLeftChart()
    {
      lcdCurveSpread_TopLeft.ClearSeries();

      if (m_source.Primary == BondMarket.None || m_source.Secondary == BondMarket.None ||
          m_source.Primary == m_source.Secondary)
        return;

      lblCurveSpread.Text = string.Format("{0} {1} CMT Spread", m_source.Primary, m_source.Secondary);

      // first for the history...

      var histSpread =
        CMTHelper.GetHistoricalSpreads(m_source.Primary, m_source.Secondary, m_source.Focus)
          .TakeEndValues(m_source.HistWinLength);

      // if we've got enough hsitory
      if (histSpread.Keys.Count == m_source.HistWinLength)
      {
        var con = new ConstructGenGen<string, double>(new[] {"high", "low", "avg"});

        for (int i = 0; i < CMTLine.DisplayPoints.Length; ++i)
        {
          var point = (int) CMTLine.DisplayPoints[i];
          var spreadOfPoint = histSpread.GetColumnValues(point - 1);

          con.SetValues(point.ToString(), new[] {spreadOfPoint.Max()*10000d, spreadOfPoint.Min()*10000d, spreadOfPoint.Average()*10000d});
        }

        lcdCurveSpread_TopLeft.AddBoxSeries("range", con, 0, 1, 2, 2, 2, null, Color.White);
      }

      var chart = lcdCurveSpread_TopLeft.AddSeries<CMTLineDiff>(
        source_: getSpreadObject(),
        xAxisValues_: CMTLine.DisplayPoints.Select(x => string.Format("{0}", x)).ToArray(),
        valueFields_: CMTLine.DisplayPoints.Select(x => string.Format("Y{0}", x)).ToArray(),
        desc_: "cmtspread",
        yAxisExtent_:40,
        color_: Color.Red,
        yLabelFormat_: "###0.0",
        lineThickness_: 0);

      lcdCurveSpread_TopLeft.Chart.Data.ZeroAligned = true;
      var lcapp = (LineChartAppearance)chart.ChartTypeAppearance;
      lcapp.MidPointAnchors = true;

      var la = new LineAppearance();
      la.IconAppearance.Icon = Infragistics.UltraChart.Shared.Styles.SymbolIcon.Diamond;
      la.IconAppearance.IconSize = Infragistics.UltraChart.Shared.Styles.SymbolIconSize.Medium;
      la.Thickness = 0;

      lcapp.LineAppearances.Add(la);


    }
    public SysTimeSeries MultiplyOut(DatedDataCollectionGen<double> allocation_, int offset_)
    {
      if (!HasData || allocation_==null) return null;

      var con = new ConstructGenGen<DateTime, double>(Data.ColumnHeadings);

      foreach (var date in Data.Keys)
        con.SetValues(date, Data.GetValues(date).MultiplyBy(allocation_.ValueOnDate(date,offset_)));

      return new SysTimeSeries {Data = con};
    }
    public void ReRead()
    {
      ConstructGenGen<string, double> con = new ConstructGenGen<string, double>(2);
      con.ColumnHeadings = new string[]
      {
        EnumDescriptionAttribute.GetDescription(m_args.XAxis),
        EnumDescriptionAttribute.GetDescription(m_args.YAxis)
      };

      foreach (var v in m_func())
      {
        con.SetValues(v.Inst, new double[] { v.GetRawStat(m_args.XAxis), v.GetRawStat(m_args.YAxis) });
      }

      m_scatter.Create(con);
    }
    private void analyse()
    {
      if (m_lastApplied == null)
        return;

      seasAverageNormalized.ClearSeries();
      seasProbability.ClearSeries();

      var allLevels = m_lastApplied.GetCombined(DataAroundEventField.Filled_Level);
      var allDiffs = m_lastApplied.GetCombined(DataAroundEventField.Filled_Daily_Diff);

      var subsetLevels = new ConstructGenGen<int, double>(allLevels.ColumnHeadings);
      var subsetDiffs = new ConstructGenGen<int, double>(allLevels.ColumnHeadings);

      //
      // get all the values for the subset that's been defined
      //

      foreach (var indexPoint in allLevels.Keys)
      {
        if (indexPoint < m_args.AnalysisStartIndex)
          continue;

        if (indexPoint > m_args.AnalysisEndIndex)
          break;

        subsetLevels.SetValues(indexPoint, allLevels.GetValues(indexPoint));
        subsetDiffs.SetValues(indexPoint, allDiffs.GetValues(indexPoint));
      }

      //
      // calculate and apply probabilities
      //

      var probType = ProbabilityCalcType.UpsMinusDownsOverNumber;
      var probabilities = new double[subsetDiffs.Keys.Count];

      for (int i = 0; i < subsetDiffs.Keys.Count; ++i)
      {
        var valsForIndexPoint = allDiffs.GetValues(allDiffs.Keys[i]);
        probabilities[i] = ProbabilityCalc.CalcProb(valsForIndexPoint, probType);
      }

      // add probability column chart

      seasProbability.AddColumnChart("Probability", subsetLevels.Keys.Select(x => x.ToString()).ToArray(),
        probabilities, ProbabilityCalc.GetMaxValue(probType));
      seasProbability.AddLegend();
    

      // 
      // calculate normlized series on subset
      //

      var normdValues = new ConstructGenGen<int, double>(allLevels.ColumnHeadings);
      var keys = subsetLevels.Keys.Select(x => x.ToString()).ToArray();

      for(int i=0;i<subsetLevels.ArrayLength;++i)
      {
        var normd = subsetLevels.GetColumnValues(i).Normalize();

        normdValues.SetColumnValues(i, subsetLevels.Keys.ToArray(), normd);
      }

      //
      // calculate average normalized series
      //

      var averageNorms = new double[normdValues.Keys.Count];
      //var dispersionMeasure = new double[normdValues.Keys.Count];

      for (int i = 0; i < averageNorms.Length; ++i)
      {
        var valuesToUse = normdValues.GetValues(normdValues.Keys[i]).Where(x => double.IsNaN(x) == false).ToArray();

        averageNorms[i] = valuesToUse.Average();
        //dispersionMeasure[i] = Statistics.Stdev(valuesToUse.Select(x=>x-averageNorms[i]).ToArray());
      }

      // 
      // normalize the average and display
      //

      averageNorms = averageNorms.Normalize();

      seasAverageNormalized.AddLineChart("Seasonal pattern", keys, averageNorms);
      //seasAverageNormalized.AddColumnChart("stdev", keys, dispersionMeasure, dispersionMeasure.Max());

      seasAverageNormalized.AddLegend();
    }