예제 #1
0
    public static void Go()
    {
      var fitter = new Symmetry.Analytics.NelsonSiegelFunctions();

      var dict = new SortedDictionary<double, double>()
      {
        {1.77686516084873, 7.02258439032354},
        {1.94661190965092, 5.55628594809711},
        {2.03148528405202, 13.4499348492539},
        {2.28336755646817, 20.8080886146473},
        {2.52703627652293, 26.708948176717},
        {2.77618069815195, 29.0304207558132},
        {3.03080082135524, 31.9613539334921},
        {3.52635181382615, 44.3648603406478},
        {3.77549623545517, 49.8256945309099},
        {4.03011635865845, 55.1820816816955},
        {4.28199863107461, 63.633515779337},
        {4.5284052019165, 72.5887030333266},
        {4.77754962354552, 79.1075346964096},
        {5.0321697467488, 82.0120316869707},
        {5.52772073921971, 94.2689492282797},
        {6.28336755646817, 110.992745133981},
        {7.28268309377139, 134.692483621496},
        {8.03011635865845, 148.438811164893},
        {8.28199863107461, 152.549894925683},
        {8.5284052019165, 159.612570569027},
        {9.0321697467488, 166.24430340512},
        {9.52772073921971, 169.028522966936},
        {9.77686516084873, 173.462367280208},
        {10.031485284052, 176.291486746032},
        {10.776180698152, 188.459931925669},
        {13.0321697467488, 215.431359347361},
        {13.284052019165, 215.593435793301},
        {14.776180698152, 229.360350538866},
        {16.7775496235455, 238.927110491854},
        {21.284052019165, 266.755305803095},
        {24.7775496235455, 276.636968109384},
        {25.7768651608487, 280.324496354856},
        {29.0321697467488, 285.581578349661},
      };

      fitter.NSFitLM(dict.Keys.ToArray(), dict.Values.ToArray());

      foreach( var tenor in dict.Keys)
      {
        Console.WriteLine(string.Format("{0} => {1} => {2}",
          tenor,
          dict[tenor],
          Symmetry.Analytics.NelsonSiegelFunctions.NSCalcYield(fitter.Result, tenor)
          ));
      }
    }
 public void Dispose()
 {
   subscribeToCentralEvent(false);
   m_fitter = null;
   m_bondList.Clear();
   m_bondsForFit = null;
 }
    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();
          }
        };
      ;
    }