/// <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;
    }
示例#2
0
    public void Create(DatedDataCollectionGen<double> x_, DatedDataCollectionGen<double> y_, string xName_, string yName_)
    {
      var con = new ConstructGenGen<string,double>(2);
      con.ColumnHeadings = new string[] { xName_, yName_ };

      var ds = new DatedDataCollectionGen<double>[] { x_, y_ };

      for (int y = 0; y < ds.Length; ++y)
        for (int i = 0; i < ds[y].Length; ++i)
          con.SetValue(ds[y].Dates[i].ToString("dd-MMM-yyyy"), y, ds[y].Data[i]);

      Create(con);
    }
示例#3
0
    public ConstructGenGen<RelativeDate, double> GenerateHourlySums(DayField field_)
    {
      Func<RelativeDate, RelativeDate, bool> areSameHour = (a, b) => a.UnderlyingDate.IsSameHourAs(b.UnderlyingDate);

      try
      {
        var data = LinesAsRelativeDates();

        m_lock.EnterReadLock();

        var con = new ConstructGenGen<RelativeDate, double>(1);

        if (data == null) return null;

        var hour = data.Keys[0];

        var sum = 0d;

        foreach (var rd in data.Keys)
        {
          if (areSameHour(hour, rd))
            sum += data.GetValue(rd, 0).GetValue(field_);
          else
          {
            con.SetValue(new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone), 0, sum);
            sum = 0;
            hour = rd;
          }
        }

        // do we need to commit last value
        var lastHour = new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone);

        if (con.LastKey() != lastHour)
          con.SetValue(lastHour, 0, sum);

        return con;
      }
      finally
      {
        m_lock.ExitReadLock();
      }
    }
示例#4
0
    public ConstructGenGen<RelativeDate, Line> LinesAsRelativeDates()
    {
      if (m_data != null ) return m_data;

      try
      {
        m_lock.EnterWriteLock();
        m_data = new ConstructGenGen<RelativeDate, Line>(1);

        if(Lines!=null)
          foreach (var item in Lines)
          {
            item.CalcSeriesValue(DefaultTail);
            m_data.SetValue(new RelativeDate(IndexedDates, item.GmtDateAsDate().ToTZfromGMT(DispTimeZone),DispTimeZone), 0, item,
              ConstructGenGen<RelativeDate, Line>.KeyOptionsWhenAdding.AddEveryTime);
          }

        return m_data;
      }
      finally
      {
        m_lock.ExitWriteLock();
      }
    }
示例#5
0
    public ConstructGenGen<RelativeDate, OIValue> BackOIAsRelativeDatesConstruct()
    {
      if (m_con_OI_to != null) return m_con_OI_to;

      m_con_OI_to = new ConstructGenGen<RelativeDate, OIValue>(1);

      foreach (var dateIndex in IndexedDates)
      {
        // create a RelativeDate for the IndexDates
        var rd = new RelativeDate(IndexedDates, dateIndex.Date, DispTimeZone);

        // shift it to the following morning (which is where we want to stamp the closing OI for the day)
        rd = rd.GetNextDayStart();

        m_con_OI_to.SetValue(
          key_: rd,
          index_: 0,
          value_: new OIValue(OI_Back==null ? double.NaN : OI_Back.ValueOnExactDate_Else(dateIndex.Date, double.NaN), OIStatus.Actual));
      }

      m_con_OI_to.SortKeys();

      return m_con_OI_to;
    }
示例#6
0
    public ConstructGenGen<RelativeDate, double> GenerateHourlyPoints(DayField field_)
    {
      Func<RelativeDate, RelativeDate, bool> areSameHour = (a, b) => a.UnderlyingDate.IsSameHourAs(b.UnderlyingDate);

      try
      {
        var data = LinesAsRelativeDates();

        m_lock.EnterReadLock();

        var con = new ConstructGenGen<RelativeDate, double>(1);

        if (data == null) return null;

        var hour = data.Keys[0];
        con.SetValue(new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone), 0, data.GetValue(hour, 0).GetValue(field_));


        foreach (var rd in data.Keys)
        {
          if (areSameHour(hour, rd))
            continue;

          hour = rd;
          con.SetValue(new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone), 0, data.GetValue(rd, 0).GetValue(field_));
        }

        return con;
      }
      finally
      {
        m_lock.ExitReadLock();
      }
    }
    private static ConstructGenGen<string, double> toYears(DatedDataCollectionGen<double> monthlyValues_)
    {
      var ret =
        new ConstructGenGen<string, double>(new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" });

      for (int i = 0; i < monthlyValues_.Length; ++i)
      {
        var date = monthlyValues_.Dates[i];

        if (date.Year == DateTime.Today.Year)
          break;

        ret.SetValue(date.Year.ToString(), date.Month - 1, monthlyValues_.Data[i]);
      }

      return ret;
    }
示例#8
0
    private static async Task populateKnown(CarbonClient cc_)
    {
      var knownMonikers = AssetClassMonikerRoots.Roots.Select(x => string.Format("{0}.secmaster", x));

      m_list = new ConstructGenGen<string, SecMasterEntry>(new[] {"Value"});

      foreach (var moniker in knownMonikers)
      {
        Logger.Info(string.Format("Loading secmaster document [{0}]...", moniker), typeof (SecMasters));

        var s = await DataFrameHelper.GetDataFrameByColumn(
          name_: moniker,
          keyExtractor_: x => x.ToString(),
          valueExtractor_: (idx,col) =>
          {
            var invertValue = col[idx["invert"]];

            bool invert;

            if (invertValue is bool)
              invert = (bool) col[idx["invert"]];
            else
              bool.TryParse(invertValue.ToString(), out invert);

            var method = (string) col[idx["method"]];

            PnlMethod mthd = PnlMethod.Arithmetic;

            switch(method.ToLower())
            {
              case "arithmetic":
                mthd = PnlMethod.Arithmetic;break;
              case "geometric":
                mthd = PnlMethod.Geometric;break;
              case "swaps":
                mthd = PnlMethod.Swap;break;
              case "credit":
                mthd = PnlMethod.Credit;break;
              default:
                Logger.Warn(string.Format("Unknown pricing method of '{0}'. Will default to arithmetic.", method),
                  typeof (SecMasters));
                break;
            }

            return new SecMasterEntry
            {
              Invert = invert,
              Method = mthd
            };
          },
          cc_: cc_);

        if(s!=null)
          foreach (var key in s.Keys)
          {
            var val = s.GetValue(key, 0);
            val.Name = key;

            if (m_list.HasKey(key))
            {
              var currentValue = m_list.GetValue(key, 0);

              if (!currentValue.Equals(val))
              {
                Logger.Error(
                  string.Format(
                    "Entry for {0} is being overwritten with different values from another list.  PriorSettings={1}.  NewSettings={2}",
                    val.Name, currentValue, val), typeof (SecMasters));
              }
            }

            m_list.SetValue(key, 0, val);
          }

      }
    }
    public ConstructGenGen<RelativeDate, double> GetOIFrontBackOpenInterestValues(RollGeneration generation_)
    {
      if (m_oiInterestValues != null)
        return m_oiInterestValues;

      var day = GetDay(generation_);

      var hour = day.DispTimeZone == DisplayTimeZone.NYK ? 15 : 16;

      var ret = new ConstructGenGen<RelativeDate, double>(new[] { "Front", "Back" });

      foreach (var date in day.Dates)
      {
        var relDate = new RelativeDate(day.Dates, date.AddHours(hour));

        ret.SetValue(relDate, 0, day.OI_From.ValueOnDate(date));
        ret.SetValue(relDate, 1, day.OI_To.ValueOnDate(date));
      }

      return m_oiInterestValues = ret;
    }
示例#10
0
    public ConstructGenGen<RelativeDate,double> GetMinuteFrontBackOpenInterestValues(RollGeneration generation_)
    {
      var day = GetDay(generation_);

      var hour = day.DispTimeZone == DisplayTimeZone.NYK ? 15 : 16;

      var oiDates =
        day.Dates.Select(x => new Tuple<DateTime, RelativeDate>(x, new RelativeDate(day.Dates, x.AddHours(hour))));

      var ret = new ConstructGenGen<RelativeDate, double>(new[] {"Front", "Back"});

      try
      {
        m_lock.EnterReadLock();

        var startDate = day.Dates.Min();
        var frontStartingValue = day.OI_From.ValueOnDate(startDate, -1);
        var backStartingValue = day.OI_To.ValueOnDate(startDate, -1);

        double priorValueFront = frontStartingValue;
        double priorValueBack = backStartingValue;

        for (int i = 0; i < m_data.Keys.Count; ++i)
        {
          var key = m_data.Keys[i];

          if (i == 0)
          {
            ret.SetValue(key, 0, frontStartingValue, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AddEveryTime);
            ret.SetValue(key, 1, backStartingValue, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AssumeKeyAlreadyThere);
            continue;
          }

          var matchOnExactOI = oiDates.FirstOrDefault(x => x.Item2 == key);

          bool handled = false;

          if (matchOnExactOI!=null)
          {
            var frontOI = priorValueFront = day.OI_From.ValueOnExactDate(matchOnExactOI.Item1);
            var backOI = priorValueBack = day.OI_To.ValueOnExactDate(matchOnExactOI.Item1);

            if (!frontOI.IsZero() || !backOI.IsZero())
            {
              ret.SetValue(key, 0, frontOI, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AddEveryTime);
              ret.SetValue(key, 1, backOI, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AssumeKeyAlreadyThere);
              handled = true;
            }
          }

          if(!handled)
          {
            var line = m_data.GetValue(key, (int)generation_);

            double increment = line == null ? 0d : line.SpreadVolume;

            ret.SetValue(key, 0, priorValueFront - increment, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AddEveryTime);
            ret.SetValue(key, 1, priorValueBack + increment, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AssumeKeyAlreadyThere);

            priorValueFront -= increment;
            priorValueBack += increment;
          }
        }
      }
      finally
      {
        m_lock.ExitReadLock();
      }

      return ret;
    }