当前位置: 首页>>代码示例>>C#>>正文


C# ConstructGen.AddValue方法代码示例

本文整理汇总了C#中ConstructGen.AddValue方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructGen.AddValue方法的具体用法?C# ConstructGen.AddValue怎么用?C# ConstructGen.AddValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConstructGen的用法示例。


在下文中一共展示了ConstructGen.AddValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWeights

    public ConstructGen<double> GetWeights(TraderArgs args_)
    {
      generateRawResults(args_);

      // generate all indicators
      List<DateTime> rebalDates = getRebalDates(args_);

      // save them so we can use them later
      args_.RebalDates = rebalDates;

      // get the filter construct first
      ConstructGen<double> filter = getFilters(args_, rebalDates, m_resultsFilter);

      //ConstructDisplay.Show(filter, args_.Products.ToArray(), "Filter Values");

      // get the wts 
      ConstructGen<double>[] wts = getWeights(args_, rebalDates, filter);

      if (wts.Length > 0 && args_.CombineWeightArgs != null)
      {
        // do we want to scale each signal before combining?
        if (args_.CombineWeightArgs.ScaleBeforeCombine)
          for (int i = 0; i < wts.Length; ++i)
            wts[i] = ScaleWeights(wts[i], args_.ScaleToThisVol, args_);

        // do we want to scale the allocation to each signal?
        if (args_.CombineWeightArgs.ScaleWeightSignalsEnabled)
        {
          double currAlloc = args_.CombineWeightArgs.StratWeightStartAlloc;

          for (int i = 0; i < wts.Length; ++i)
          {
            wts[i] = wts[i].MultiplyBy(currAlloc);

            currAlloc += args_.CombineWeightArgs.StratWeightAllocIncrement;
          }
        }
      }

      // combine the different signals
      ConstructGen<double> c = wts[0];
      if (args_.CombineWeightArgs != null && args_.CombineWeightArgs.CombineMethod == StratCombineMethod.MULT)
      {
        c = wts[0];
        for (int i = 1; i < wts.Length; ++i)
          c = multiply(c, wts[i], false);
      }
      else if (args_.CombineWeightArgs != null && args_.CombineWeightArgs.CombineMethod == StratCombineMethod.AGREE)
      {
        c = wts[0];
        for (int i = 1; i < wts.Length; ++i)
          c = agreeSign(c, wts[i]);
      }
      else if (args_.CombineWeightArgs != null && args_.CombineWeightArgs.CombineMethod == StratCombineMethod.ADD)
      {
        c = wts[0];
        for (int i = 1; i < wts.Length; ++i)
          c = c.Plus(wts[i]);
      }
      else if (args_.CombineWeightArgs != null && args_.CombineWeightArgs.CombineMethod == StratCombineMethod.LIST)
      {
        System.Diagnostics.Debug.Assert(args_.CombineWeightArgs.AllocList != null, "Combine method has been set to 'LIST' but no allocation list has been set");

        System.Diagnostics.Debug.Assert(args_.CombineWeightArgs.AllocList.ArrayLength == wts.Length, "Set of weights to combine doesn't match arraylength of ConstructGen<double> that has been set to express the allocations.");

        // get a list of common dates
        List<DateTime> commondates = new List<DateTime>();
        foreach (DateTime date in wts[0].Dates)
        {
          for (int i = 1; i < wts.Length; ++i)
            if (wts[i].Dates.Contains(date) == false)
              continue;

          commondates.Add(date);
        }

        ConstructGen<double> comb = new ConstructGen<double>(wts[0].ArrayLength);

        for (int i = 0; i < wts.Length; ++i)
        {
          foreach (DateTime date in commondates)
          {
            if(comb.Dates.Contains(date)==false)
              comb.SetValues(date,new double[comb.ArrayLength]);

            double alloc = args_.CombineWeightArgs.AllocList.GetValue(date, i);

            for (int j = 0; j < comb.ArrayLength; ++j)
              comb.AddValue(date, j, alloc * wts[i].GetValue(date, j));
          }
        }

        c = comb;

      }
      else if (args_.CombineWeightArgs == null && wts.Length > 1)
        throw new Exception("Don't know how to combine the signals into one.");
      else if (args_.CombineWeightArgs != null)
        throw new Exception("Strategy combine method not implemented");

//.........这里部分代码省略.........
开发者ID:heimanhon,项目名称:researchwork,代码行数:101,代码来源:Trader.cs


注:本文中的ConstructGen.AddValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。