private static ConstructGen<double> expandToFullUniverse(ConstructGen<double> input_)
    {
      if (input_.ArrayLength == Singleton<FXIDs>.Instance.Count)
        return input_;

      System.Diagnostics.Debug.Assert(input_.ColumnHeadings != null, "Column Headings not set on ConstructGen<double> wts, therefore can't ascertain securities");

      ConstructGen<double> ret = new ConstructGen<double>(Singleton<FXIDs>.Instance.Count);
      ret.ColumnHeadings = Singleton<FXIDs>.Instance.ColumnHeadings;

      for (int i = 0; i < input_.ArrayLength; ++i)
      {
        Currency c = Singleton<FXIDs>.Instance[input_.ColumnHeadings[i]];

        ret.SetColumnValues(c.ArrayIndex, input_.Dates.ToArray<DateTime>(), input_.GetColumnValues(i));
      }
      return ret;
    }
Example #2
0
    protected override SI.ReturnsEval.DataSeriesEvaluator doPnl(TraderArgs args_, ConstructGen<double> wts_)
    {
      ConstructGen<double> allCcys = new ConstructGen<double>(Singleton<FXIDs>.Instance.ColumnHeadings);

      for (int i = 0; i < args_.Products.Count; ++i)
      {
        ProductFX prod = (ProductFX)args_.Products[i];
        allCcys.SetColumnValues(prod.CoreProduct.ArrayIndex, wts_.Dates.ToArray(), wts_.GetColumnValues(i));
      }

      var result = ReturnsFromFXWeights.DoIt_DailyWeights(allCcys);
      var eval = new ReturnsEval.DataSeriesEvaluator("FX pnl", ReturnsEval.DataSeriesType.Returns);

      if (args_.WtIndicators.Any())
        eval.Name = string.Format("FX : {0}", args_.WtIndicators[0].ToString());
      
      eval.AddInnerSeries(result.CombinedPnl.Dates.ToArray(), result.CombinedPnl.ToArray(), result.CombinedPnl.ColumnHeadings);

      return eval;
    }
    public override void Create(ConstructGen<double> wts_, ConstructGen<double> c2v_, ConstructGen<double> perf_)
    {
      var indicies =
        Singleton<FXIDs>.Instance.Where<Currency>(x => x.IsGroup(FX_Group))
          .Select<Currency, int>(x => x.ArrayIndex)
          .ToArray();


      var wtsForGroup = wts_.GetColumnValues(indicies);
      var c2vForGroup = c2v_.GetColumnValues(indicies);
      var perfForGroup = perf_.GetColumnValues(indicies);

      base.Create(wtsForGroup, c2vForGroup, perf_);

      double[] ctvDaily = new double[c2vForGroup.Dates.Count];
      for (int i = 0; i < c2vForGroup.Dates.Count; ++i)
        ctvDaily[i] = Statistics.Sum(c2vForGroup.GetValues(c2vForGroup.Dates[i]));
      C2V = new DataEncapsValue(new DatedDataCollectionGen<double>(c2vForGroup.Dates.ToArray(), ctvDaily),"C2V");

      double[] perfDaily = new double[perfForGroup.Dates.Count];
      for (int i = 0; i < perfForGroup.Dates.Count; ++i)
        perfDaily[i] = Statistics.Sum(perfForGroup.GetValues(perfForGroup.Dates[i]));
      Return = new DataEncapsValue(new DatedDataCollectionGen<double>(perfForGroup.Dates.ToArray(), perfDaily), DataEncapsDispValueType.Sum, "Return");
    }
Example #4
0
    public void Create(ConstructGen<double> con_)
    {
      setupDataTable();

      double cumulative = 0d;

      Side lastSide = Side.None;

      foreach (var date in con_.Dates)
      {
        var values = con_.GetValues(date);

        var wt = values[(int)Headings.Weight];
        var dailyPnl = values[(int)Headings.Pnl];
        var ccyrate = values[(int)Headings.Spot];

        cumulative += dailyPnl;

        dt.LoadDataRow(new object[] { date, cumulative, ccyrate, wt }, true);

        if (wt > 0d)
        {
          if (lastSide != Side.Long)
          {
            dtLongPoints.LoadDataRow(new object[] { date, ccyrate }, true);
            lastSide = Side.Long;
          }
        }
        else if (wt < 0d)
        {
          if (lastSide != Side.Short)
          {
            dtShortPoints.LoadDataRow(new object[] { date, ccyrate }, true);
            lastSide = Side.Short;
          }
        }
        else
        {
          if (lastSide != Side.Flat)
          {
            dtFlatPoints.LoadDataRow(new object[] { date, ccyrate }, true);
            lastSide = Side.Flat;
          }
        }
      }

      {
        var ccyAxix = ultraChart.CompositeChart.ChartAreas[0].Axes.FromKey("y_axis_ccyRate");

        ccyAxix.RangeType = AxisRangeType.Custom;
        var ccyValues = con_.GetColumnValues((int)Headings.Spot);
        ccyAxix.RangeMin = ccyValues.Min();
        ccyAxix.RangeMax = ccyValues.Max();
      }

      m_con = con_;
    }
Example #5
0
    public void Create(ConstructGen<double> con_)
    {
      setupDataTable();

      double cumulative = 0d;

      double? prevWt=null;

      foreach (var date in con_.Dates)
      {
        var values = con_.GetValues(date);

        var wt = values[(int)Headings.Weight];
        var dailyPnl = values[(int)Headings.Pnl];
        var ccyrate = values[(int)Headings.Spot];

        cumulative += dailyPnl;

        var objArr = new object[dt.Columns.Count];

        objArr[0] = date;
        objArr[1] = cumulative;

        var indexForWt = getIndexForWt(wt);
        objArr[indexForWt] = ccyrate;

        if (prevWt.HasValue)
        {
          var indexForPrevWt = getIndexForWt(prevWt.Value);

          if (indexForWt != indexForPrevWt)
            objArr[indexForPrevWt] = ccyrate;
        }


        objArr[5] = wt > 0d ? wt : 0d;
        objArr[6] = wt < 0d ? wt : 0d;

        dt.LoadDataRow(objArr, true);

        prevWt = wt;
      }

      {
        var ccyAxix = ultraChart.CompositeChart.ChartAreas[0].Axes.FromKey("y_axis_ccyRate");

        ccyAxix.RangeType = AxisRangeType.Custom;
        var ccyValues = con_.GetColumnValues((int)Headings.Spot);
        ccyAxix.RangeMin = ccyValues.Min();
        ccyAxix.RangeMax = ccyValues.Max();
      }

      m_con = con_;
    }
Example #6
0
    public static ConstructGen<double> GetSumFlow(ConstructGen<double> fxWts_)
    {
      var ret = new ConstructGen<double>(fxWts_.ColumnHeadings);

      for (int i = 0; i < fxWts_.ArrayLength; ++i)
      {
        ret.SetValue(DateTime.Today, i, fxWts_.GetColumnValues(i).ToDiffs().ToAbs().Sum());
      }

      return ret;
    }
        public Tuple<double[], double[]> ComputeAvgsAndProb(ConstructGen<double> con, Tuple<ConstructGen<double>, int, DateTime> conForProbability, int EventDayShift)
        {
            double[] avgs = new double[con.ArrayLength];
            var Probs = new double[conForProbability.Item1.ArrayLength];
            for (int i = 0; i < avgs.Length; ++i)
            {
                var validNumberSeries = con.GetColumnValues(i).Where(x => double.IsNaN(x) == false);

                if (!validNumberSeries.Any()) continue;

                avgs[i] = validNumberSeries.ToArray().Average();

                var alldiffs = conForProbability.Item1.GetColumnValues(i).Where(x => double.IsNaN(x) == false).ToList();
                Probs[i] = ProbabilityCalc.CalcProb(alldiffs, ProbCalcMethod);
            }
            EventReturns[con.Name] = new Tuple<double[], int>(avgs, EventDayShift);
            return new Tuple<double[], double[]>(avgs, Probs);
        }
Example #8
0
    public static void Build(BindingList<PnlPosRow> structure_, ReturnsEval.DataSeriesEvaluator parentEval_, ConstructGen<double> wts_, string[] wtsKeys_)
    {
      structure_.Clear();

      if (parentEval_.InnerSeries.Count != wts_.ArrayLength)
        return;

      List<DateTime> pnlDates = new List<DateTime>(parentEval_.Daily.Dates);

      for(int i=0;i<parentEval_.InnerSeries.Count;++i)
      {
        ReturnsEval.DataSeriesEvaluator eval = parentEval_.InnerSeries[i];

        PnlPosRow row = new PnlPosRow(eval.Name);

        int indexInWts = -1;
        for(int j=0;j<wtsKeys_.Length;++j)
          if (string.Compare(eval.Name, wtsKeys_[j]) == 0)
          {
            indexInWts = j;
            break;
          }

        if (indexInWts == -1)
          continue;

        double[] wtsColumn = wts_.GetColumnValues(indexInWts);

        DateTime startOfPeriod = wts_.Dates[0];

        for (int j = 1; j < wts_.Dates.Count; ++j)
        {
          // has weight flipped
          if (Statistics.AreSameSign(wtsColumn[j], wtsColumn[j - 1]) == false)
          {
            DateTime endOfPeriod = wts_.Dates[j];

            int indexOfStart = (startOfPeriod==wts_.Dates[0]) ? 0 : pnlDates.IndexOf(startOfPeriod);
            int indexOfEnd = pnlDates.IndexOf(endOfPeriod);

            double pnlOverPeriod = eval.Daily.CumulativeReturnSeries[indexOfEnd] - eval.Daily.CumulativeReturnSeries[indexOfStart];

            row.Add(new PnlPosPeriodRow(
              getSide(wtsColumn[j-1]),
              pnlDates[indexOfStart],
              pnlDates[indexOfEnd],
              pnlOverPeriod), false);

            startOfPeriod = endOfPeriod;
          }
        }

        int indStart = pnlDates.IndexOf(startOfPeriod);
        int indEnd = pnlDates.Count-1;

        // need to add int last item
        row.Add(new PnlPosPeriodRow(
          getSide(wtsColumn[wtsColumn.Length - 1]),
          pnlDates[indStart],
          pnlDates[indEnd],
          eval.Daily.CumulativeReturnSeries[indEnd] - eval.Daily.CumulativeReturnSeries[indStart]), true);

        structure_.Add(row);
      }
    }