예제 #1
0
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      double posSum;
      double negSum;
      int posCount;
      int negCount;

      foreach (DateTime date in wts_.Dates)
      {
        posSum=0.0;
        negSum=0.0;
        posCount=0;
        negCount=0;

        for (int i = 0; i < wts_.ArrayLength; ++i)
        {
          double val = signalResults_.GetValue(date, i);

          if (val == 0)
            continue;

          if (val > 0)
          {
            posSum+=val;
            ++posCount;
          }
          else
          {
            negSum+=val;
            ++negCount;
          }
        }

        double negAv = negSum / negCount;
        double posAv = posSum / posCount;

        for (int i = 0; i < wts_.ArrayLength; ++i)
        {
          double val = signalResults_.GetValue(date, i);

          if (val == 0)
          {
            wts_.MultValue(date, i, 0.0, false);
          }
          else if (val > 0)
          {
            double mult = val / posAv;
            double wt = 1.0 - (1.0 - (1.0 / mult));
            wts_.MultValue(date, i, wt,false);
          }
          else
          {
            double mult = val / negAv;
            double wt = 1.0 - (1.0 - (1.0 / mult));
            wts_.MultValue(date, i, wt,false);
          }
        }
      }
    }
예제 #2
0
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      List<SortHelpClass> list = new List<SortHelpClass>();

      foreach (DateTime date in signalResults_.Dates)
      {
        //wts_.MultValue(date, i, val, val < 0);

        list.Clear();

        for (int i = 0; i < signalResults_.ArrayLength; ++i)
        {
          double val = signalResults_.GetValue(date, i);

          if (double.IsNaN(val) == false)
            list.Add(new SortHelpClass(val, i, m_abs,false,false));
        }

        QuickSort.Sort<SortHelpClass>(list);



        for (int i = 0; i < wts_.ArrayLength && i < list.Count; ++i)
        {
          wts_.MultValue(date, list[i].ArrayIndex, list[i].Value, list[i].Value < 0);
        }

      }

    }
예제 #3
0
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      for (int i = 0; i < products_.Count; ++i)
      {
        double avg = 0;
        for (int j = 0; j < signalResults_.Dates.Count; ++j)
        {
          if(j<WindowLength)
          {
            wts_.SetValue(signalResults_.Dates[j],i,0);
            continue;
          }

          // if the product is not valid on this date then the weight is zero.
          if (double.IsNaN(filters_.GetValue(signalResults_.Dates[j],i)))
          {
            wts_.SetValue(signalResults_.Dates[j], i, 0.0);
          }
          else
          {
            for (int y = 0; y < WindowLength; ++y)
              avg += signalResults_.GetValue(signalResults_.Dates[j - y], i);
            avg /= WindowLength;

            double val = signalResults_.GetValue(signalResults_.Dates[j], i) / avg;

            wts_.MultValue(signalResults_.Dates[j], i, val, false);
          }
        }
      }
    }
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      double[] sigToday = new double[products_.Count];

      foreach (DateTime date in signalResults_.Dates)
      {
        double[] filterToday = filters_.GetValues(date);
        int productValidCount = 0;
        double sum = 0;

        for (int i = 0; i < sigToday.Length; ++i)
        {
          sigToday[i] = signalResults_.GetValue(date, i);
          if (double.IsNaN(filterToday[i]) == false && double.IsNaN(sigToday[i]) == false)
          {
            ++productValidCount;
            sum += sigToday[i];
          }
        }

        var avg = sum / Convert.ToDouble(productValidCount);

        for (int i = 0; i < sigToday.Length; ++i)
        {
          if (double.IsNaN(filterToday[i]) == false && double.IsNaN(sigToday[i]) == false)
            wts_.MultValue(date, i, sigToday[i] - avg);
        }
      }
    }
예제 #5
0
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      // go through each rebal date
      foreach (DateTime date in wts_.Dates)
      {
        for (int i = 0; i < wts_.ArrayLength; ++i)
        {
          if (products_[i].IsValid(date))
          {
            wts_.MultValue(date, i, signalResults_.GetValue(date, i) / Math.Pow(products_[i].GetVol(date, m_volType, m_windowLength), m_power), false);
          }
        }
      }

    }
예제 #6
0
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      foreach (DateTime date in signalResults_.Dates)
      {
        for (int i = 0; i < signalResults_.ArrayLength; ++i)
        {
          double val = signalResults_.GetValue(date, i);

          if (val < 0 && GoShort == false)
            wts_.SetValue(date, i, 0.0);
          else if (val > 0 && GoLong == false)
            wts_.SetValue(date, i, 0.0);
          else
            wts_.MultValue(date, i, val, false);
        }
      }
    }
예제 #7
0
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      double[] sigToday = new double[products_.Count];
      double sum;

      foreach (DateTime date in signalResults_.Dates)
      {
        double[] filterToday = filters_.GetValues(date);
        sum = 0;

        for (int i = 0; i < sigToday.Length; ++i)
          if(double.IsNaN(filterToday[i])==false)
            sum += signalResults_.GetValue(date, i);

        for (int i = 0; i < sigToday.Length; ++i)
          if(double.IsNaN(filterToday[i])==false)
            wts_.MultValue(date, i, signalResults_.GetValue(date, i) / sum, false);
      }

    }
예제 #8
0
    public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
    {
      foreach (DateTime date in signalResults_.Dates)
        for (int i = 0; i < products_.Count; ++i)
        {
          double v = signalResults_.GetValue(date, i);

          v = (v == 0) ? 0.0 : (v < 0) ? -1.0 : 1.0;
          v = (m_reverse) ? -v : v;

          if (m_scaleSignDifferently && v != 0)
          {
            v = (v < 0) ? (v * m_negScale) : (v * m_posScale);

            wts_.MultValue(date, i, v, v < 0);
          }
          else
          {
            wts_.SetValue(date, i, v);
            //wts_.SetToSign(date, i, v);
          }
        }
    }