public static ConstructGen<double> GetSmoothCurvesColumnsAreValueDates(DateTime valueDate_, uint curveCount_, BondMarket market_, BondField field_, SI.Data.BondCurves curve_, string close_ = "MLP", string source_ = "MLP")
    {
      var tempDict = new SortedDictionary<DateTime, RateCurve>();

      var date = valueDate_;

      for (int i = 0; i < curveCount_; ++i)
      {
        var curve = GetSmoothCurve(date, market_, field_, curve_, close_, source_);

        if (curve == null) continue;

        tempDict.Add(date, curve);

        date = MyCalendar.PrevWeekDay(date);
      }

      var keys = tempDict.Keys.ToArray();

      var con = new ConstructGen<double>(keys.Select(x => x.ToString("dd MMM")).ToArray());

      for (int i = 0; i < keys.Length; ++i)
      {
        var curve = tempDict[keys[i]];

        foreach (var node in curve.GetNodes())
        {
          var time = valueDate_.AddDays(Convert.ToDouble(node)*365.25).Date;

          con.SetValue(time, i, curve.GetValue(node).Value*100d);
        }
      }

      return con;
    }
    public SmoothCurveAndSettingsGroup(FitPhases phases_, CountryBondSource source_, BondField timeToMaturity_, Focus focus_, BondField minusField_, BondField minusFieldFitted_, int recalcNumber_, bool fitOnEvent_ = true)
      : this(phases_, source_, timeToMaturity_, focus_, recalcNumber_, fitOnEvent_)
    {
      // explanation of logic of last 2 arguments
      // false => don't want to continually recalc on the recalc cycle, but only once
      // true => if the MinusOffset changes, we want to recalculate


      DateTime thirtyYearsTime = DateTime.Today.AddYears(30);

      MinusCMT = new CMTLine(source_.Market,focus_);


      MinusCalculator = new SmoothCurveCalculator(
        cml_: MinusCMT,
        cmlStartTenor_: 1,
        cmlEndTenor_: 34,
        list_: source_.Lines.Where(x => x.Maturity <= thirtyYearsTime).ToList(),
        timeToMaturityField_: timeToMaturity_,
        valueField_: minusField_,
        fittedValueField_: minusFieldFitted_,
        recalcNumber_: recalcNumber_,
        updateOnCalcEvent_: false,
        updateOnMinusOffsetChange_: true,
        settings_: Settings);
    }
    public static ConstructGen<double> GetSmoothCurvesColumnsAreCurvePoints(DateTime valueDate_, uint curveCount_, BondMarket market_, BondField field_, SI.Data.BondCurves curve_, string close_ = "MLP", string source_ = "MLP")
    {
      DateTime date = valueDate_;

      var points = new List<decimal>();

      for (decimal d = 1M; d < 30M; d = d + 0.25M)
        points.Add(d);

      var con = new ConstructGen<double>(points.Select(x => x.ToString()).ToArray());

      for (int i = 0; i < curveCount_; ++i)
      {
        var curve = GetSmoothCurve(date, market_, field_, curve_, close_, source_);
        if (curve == null) continue;

        foreach (var node in curve.GetNodes())
        {
          int index = points.IndexOf(node);

          if (index == -1) continue;

          var point = curve.GetValue(node);

          if(point.HasValue)
            con.SetValue(date, index, point.Value);
        }

        date = MyCalendar.PrevWeekDay(date);
      }

      con.SortKeys();

      return con;
    }
 public BondFieldMappingAttribute(BondField field_, Focus focus_=Focus.None, FieldType fieldType_=FieldType.None, CellColourScheme colourScheme_=CellColourScheme.None)
 {
   Field = field_;
   Focus = focus_;
   FieldType = fieldType_;
   ColourScheme = colourScheme_;
 }
    public void Create(IList<BondAnalysisLine> lines_, BondField field_, TimePeriod period_)
    {
      setupStuff();

      BoxSetSeries series = (BoxSetSeries)ultraChart1.CompositeChart.Series[0];

      series.BoxSets.Clear();
      m_lineData_dt.Rows.Clear();

      foreach (var bondstats in lines_)
      {
        var fieldValues = bondstats.GetHistoricValuesForField(field_, period_);
        if (fieldValues == null || fieldValues.Length==0)
          continue;

        var last = fieldValues.Data.Last();

        QuickSort.Sort(fieldValues.Data);

        series.BoxSets.Add(new BoxSet()
        {
          Label = bondstats.Bond,
          Min = fieldValues.Data[0],
          Max = fieldValues.Data.Last(),
          Q1 = fieldValues.Data[(int) fieldValues.Length/4],
          Q2 = fieldValues.Data.Average(),
          Q3 = fieldValues.Data[(int) fieldValues.Length/4*3]
        });

        m_lineData_dt.LoadDataRow(new object[] {bondstats.Bond, last},true);
      }


    }
Exemplo n.º 6
0
    public static SI.Data.SpreadType GetDataSpreadType(BondField field_)
    {
      switch (field_)
      {
        case BondField.YieldMinus:
          return Data.SpreadType.Yield;
        case BondField.CASLive:
          return Data.SpreadType.TrueSpread;
        case BondField.ASWLive:
          return Data.SpreadType.Spread;
      }

      return Data.SpreadType.Yield; // never gets here
    }
    private static RateCurve GetSmoothCurve(DateTime valueDate_, BondMarket market_, BondField field_, SI.Data.BondCurves curve_, string close_ = "MLP", string source_ = "MLP")
    {
      var moniker = RateCurve.CreateBondSeriesCurveMoniker(
        valueDate: valueDate_,
        curveType: GetDBCurveTypeNameFromField(field_),
        country: convertMarketCode(market_),
        series: 1,
        close: close_,
        source: source_,
        curveName: EnumDescriptionAttribute.GetDescription(curve_)
        );

      var curve = SObjectManager.Instance().LoadSObject<RateCurve>(moniker);

      return curve;
    }
    public SmoothCurveAndSettingsGroup(FitPhases phases_, CountryBondSource source_, BondField timeToMaturity_, Focus focus_, int recalcNumber_, bool fitOnEvent_=true)
    {
      m_settings = new SmoothCurveSettings(phases_);

      LiveCMT = new CMTLine(source_.Market,focus_);

      DateTime thirtyYearsTime = DateTime.Today.AddYears(34);

      LiveCalculator = new SmoothCurveCalculator(
        cml_: LiveCMT,
        cmlStartTenor_: 1,
        cmlEndTenor_: 34,
        list_: source_.Lines.Where(x => x.Maturity <= thirtyYearsTime).ToList(),
        timeToMaturityField_: timeToMaturity_,
        valueField_: BondAnalysisLineHelper.GetFieldForFocusAndType(focus_,FieldType.Live),
        fittedValueField_: BondAnalysisLineHelper.GetFieldForFocusAndType(focus_,FieldType.FittedLive),
        recalcNumber_: recalcNumber_,
        updateOnCalcEvent_: fitOnEvent_,
        settings_: Settings);
    }
Exemplo n.º 9
0
 private void calculateValue(StatLineField targetValue_, BondField sourceValue_, double mult_=1d, bool fireUpdate_=true)
 {
   SetValue(targetValue_, mult_ * m_listOfComponents.Aggregate(0d, (sum, x) => sum + x.GetValue(sourceValue_)),fireUpdate_);
 }
Exemplo n.º 10
0
 public CellClickedArgs(BondAnalysisLine line_, BondField field_, MouseButtons buttons_)
 {
   Line = line_;
   Field = field_;
   Buttons = buttons_;
 }
Exemplo n.º 11
0
    public SmoothCurveCalculator(
      CMTLine cml_,
      int cmlStartTenor_,
      int cmlEndTenor_,
      IList<BondAnalysisLine> list_, 
      BondField timeToMaturityField_, 
      BondField valueField_, 
      BondField fittedValueField_, 
      SmoothCurveSettings settings_, 
      int recalcNumber_,
      bool updateOnCalcEvent_=true, 
      bool updateOnMinusOffsetChange_=false)
    {
      m_bondList = list_;
      m_timeToMaturityField = timeToMaturityField_;
      m_valueField = valueField_;
      m_fittedValueField = fittedValueField_;
      m_settings = settings_;
      m_cmlStartTenor = cmlStartTenor_;
      m_cmlEndTenor = cmlEndTenor_;
      m_fitter = new Symmetry.Analytics.NelsonSiegelFunctions();

      m_cml = cml_;

      //m_settings.PropertyChanged += (a, b) => RebuildCurve(reReadSetup_: true);

      reReadSetup();

      m_applyCycleNumber = recalcNumber_;

#if DEBUG
      Logger.Debug(string.Format("{0} fit will be generated on cycle {1}", m_cml.Market, m_applyCycleNumber), typeof(SmoothCurveCalculator));
#endif 

      m_updateOnCalcEvent = updateOnCalcEvent_;
      subscribeToCentralEvent();

      // if the curve build settings change then want to recalc everything
      settings_.PropertyChanged += (a, b) =>
      {
        Logger.Debug(string.Format("Args changed - recalcing {0} fit", m_valueField), typeof (SmoothCurveCalculator));
        RebuildCurveAndApplyResults();
      };

      if (updateOnMinusOffsetChange_)
      {
        m_updateOnMinusOffsetChange = true;
        GlobalSettings.Instance().PropertyChanged += (a, b) =>
        {
          if (String.Compare(b.PropertyName, "MinusOffset", StringComparison.OrdinalIgnoreCase) == 0)
          {
            // this will mean this will get updated on the next cycle
            subscribeToCentralEvent(true);
          }
        };
      }

      foreach (var bond in m_bondList)
        bond.PropertyChanged += (x, y) =>
        {
          if (String.Compare("IncludeInFit", y.PropertyName, StringComparison.OrdinalIgnoreCase) == 0)
          {
            RebuildCurve(reReadSetup_: true);
            ApplyBuildResults();
          }
        };
      ;
    }
Exemplo n.º 12
0
 public bool SetValuesForLineAndFocus(BondAnalysisLine line_, BondField field_)
 {
   m_allValues = line_.GetHistoricValuesForField(field_);
   m_seriesName= BondAnalysisLineHelper.FindColumnNameForField(field_);
   return reloadInstrumentHistory();
 }
 public static string GetDBCurveTypeNameFromField(BondField field_)
 {
   switch (field_)
   {
     case BondField.YieldMinus:
       return "yield";
     case BondField.CASLive:
       return "truespread";
     case BondField.ASWLive:
       return "spread";
     default:
       throw new Exception("Field not implemented - invalid");
   }
 }
    public static Focus GetFocusFromField(BondField field_)
    {
      var f = fieldMappings.FirstOrDefault(x => x.Value.Field == field_);

      return f.Value == null ? Focus.None : f.Value.Focus;
    }
    public static string FindColumnNameForField(BondField field_)
    {
      var f = fieldMappings.FirstOrDefault(x => x.Value.Field == field_);

      return f.Key ?? null;
    }
Exemplo n.º 16
0
 public void Create(CountryBondSource analyser_, BondField field_, TimePeriod period_)
 {
   Create(analyser_.Lines, field_, period_);
 }