public static void Go(ComID[] commodities_, bool dispBW_=false) { var wts = CalculateWeights(commodities_); //wts.DisplayInGrid("weightings"); var pnl = DoPnl(commodities_, wts); //pnl.DisplayInGrid("pnl"); //return; var eval = new ReturnsEval.DataSeriesEvaluator("blah", ReturnsEval.DataSeriesType.Returns); var weightedBW = !dispBW_ ? null : DoBW(commodities_, wts); for (int i = 0; i < pnl.ArrayLength; ++i) { var comPnl = pnl.GetColumnValuesAsDDC(i); eval.AddInnerSeries(comPnl.Dates, comPnl.Data, pnl.ColumnHeadings[i]); if (weightedBW != null) { var chart = new SI.Controls.LineChartDataDisplay(); chart.AddSeries( dates_: comPnl.Dates, values_: comPnl.ToCumulative().Data, desc_: "pnl", yAxisExtent_: 40, yLabelFormat_: "##0.0#%", yAxisLeft_: true); var com = weightedBW.GetColumnValuesAsDDC(i); com = new DatedDataCollectionGen<double>(wts.Dates.ToArray(), wts.Dates.Select(x => com.ValueOnDate(x)).ToArray()); chart.AddSeries( dates_: com.Dates, values_: com.Data, desc_: "bw", yAxisExtent_: 40, yLabelFormat_: "##0.0###%", yAxisLeft_: false); chart.DisplayInShowForm(commodities_[i].Mnemonic); } } eval.Evaluate(); eval.Display(); }
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; }
protected override ReturnsEval.DataSeriesEvaluator doPnl(TraderArgs args_, ConstructGen<double> wts_) { var priceReturns = args_.AllProductPrices(fillInGapsWithPrevious_: true) .ToReturns(args_.Products.Select(x => x.Convention).ToArray()); var stratReturns = new ConstructGen<double>(priceReturns.ColumnHeadings); double[] appliedWeights = null; for (int i = 0; i < priceReturns.Dates.Count; ++i) { var date = priceReturns.Dates[i]; var priceReturnsArr = priceReturns.GetValues(date); if (appliedWeights != null) { for (int j = 0; j < priceReturnsArr.Length; ++j) stratReturns.SetValue(date, j, appliedWeights[j]*priceReturnsArr[j]); } if (wts_.Dates.Contains(date)) { appliedWeights = wts_.GetValues(date); } } var eval = new ReturnsEval.DataSeriesEvaluator("Gen pnl from weights", ReturnsEval.DataSeriesType.Returns); eval.AddInnerSeries(stratReturns.Dates.ToArray(), stratReturns.ToArray(), stratReturns.ColumnHeadings); return eval; }
protected override void OnClick(EventArgs e) { ReturnsEval.DataSeriesEvaluator eval = new ReturnsEval.DataSeriesEvaluator(m_analyzer.Name, ReturnsEval.DataSeriesType.Returns); eval.AddInnerSeries(m_analyzer.Performance.Dates.ToArray<DateTime>(), m_analyzer.Performance.ToArray(), m_analyzer.SourceWts.ColumnHeadings); ReturnsEvalDisplay.ReturnsDisplay rd = new ReturnsEvalDisplay.ReturnsDisplay(); rd.RebalDates = m_analyzer.SourceWts.Dates; rd.Bind(eval); SI.Controls.ShowForm.Show(rd, eval.Name); }
public static void Test() { const int lookback = 5; const WeightGeneratorType genType = WeightGeneratorType.LongestZScoreOverThreshold; SpreadWeightGenerator[] arr = new[] { new SpreadWeightGenerator( new WeightGeneratorArgs() { Lookback = lookback, WeightGenerationType = genType, MinWindowLength = 50, ZScoreThreshold = 1.3d }, new SpreadDefinition( new MonthYearOffset(ComIDs.Sugar, 0, MonthCode.V), new MonthYearOffset(ComIDs.Sugar, 1, MonthCode.K), false)), //new SpreadWeightGenerator( // new WeightGeneratorArgs() // { // Lookback = lookback, // WeightGenerationType = genType, // MinWindowLength = 40, // ZScoreThreshold = 1d // }, // new SpreadDefinition( // new MonthYearOffset(ComIDs.Sugar, 0, MonthCode.V), // new MonthYearOffset(ComIDs.Sugar, 1, MonthCode.K), // false)), //new SpreadWeightGenerator( // new WeightGeneratorArgs() // { // Lookback = lookback, // WeightGenerationType = genType, // MinWindowLength = 40, // ZScoreThreshold = 1.5d // }, // new SpreadDefinition( // new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.H), // new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.X), // false)), new SpreadWeightGenerator( new WeightGeneratorArgs() { Lookback = lookback, WeightGenerationType = genType, MinWindowLength = 60, ZScoreThreshold = 1.2d }, new SpreadDefinition( new MonthYearOffset(ComIDs.NymexGas, 0, MonthCode.H), new MonthYearOffset(ComIDs.NymexGas, 0, MonthCode.X), false)), //new SpreadWeightGenerator( // new WeightGeneratorArgs() // { // Lookback = lookback, // WeightGenerationType = genType, // MinWindowLength = 90, // ZScoreThreshold = 1.7d // }, // new SpreadDefinition( // new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.H), // new MonthYearOffset(ComIDs.NatGas, 0, MonthCode.X), // false)), //new SpreadWeightGenerator( // new WeightGeneratorArgs() // { // Lookback = lookback, // WeightGenerationType = genType, // MinWindowLength = 40, // ZScoreThreshold = 1.6d // }, // new SpreadDefinition( // new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U), // new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z), // false)), new SpreadWeightGenerator( new WeightGeneratorArgs() { Lookback = lookback, WeightGenerationType = genType, MinWindowLength = 60, ZScoreThreshold = 1.3d }, new SpreadDefinition( new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U), new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z), false)), //new SpreadWeightGenerator( // new WeightGeneratorArgs() // { // Lookback = lookback, // WeightGenerationType = genType, // MinWindowLength = 90, // ZScoreThreshold = 0.8d // }, // new SpreadDefinition( // new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U), // new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z), // false)), new SpreadWeightGenerator( new WeightGeneratorArgs() { Lookback = lookback, WeightGenerationType = genType, MinWindowLength = 40, ZScoreThreshold = 1.5d }, new SpreadDefinition( new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U), new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z), false)), //new SpreadWeightGenerator( // new WeightGeneratorArgs() // { // Lookback = lookback, // WeightGenerationType = genType, // MinWindowLength = 50, // ZScoreThreshold = 1.3d // }, // new SpreadDefinition( // new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U), // new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z), // false)), //new SpreadWeightGenerator( // new WeightGeneratorArgs() // { // Lookback = lookback, // WeightGenerationType = genType, // MinWindowLength = 70, // ZScoreThreshold = 1.1d // }, // new SpreadDefinition( // new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U), // new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z), // false)), new SpreadWeightGenerator( new WeightGeneratorArgs() { Lookback = lookback, WeightGenerationType = genType, MinWindowLength = 50, ZScoreThreshold = 1.6d }, new SpreadDefinition( new MonthYearOffset(ComIDs.RBOB, 0, MonthCode.J), new MonthYearOffset(ComIDs.RBOB, 0, MonthCode.U), false)), }; var comb = new SpreadWeightGeneratorCombiner(arr) {NumDaysForCovariance = 42, TargetVol = 0.06}; comb.Go(); { var combinedPnl = new ConstructGen<double>(arr.Length); combinedPnl.ColumnHeadings = arr.Select(x => string.Format("{0} / {1} / {2}", x.Spread, x.Args.MinWindowLength, x.Args.ZScoreThreshold)) .ToArray(); for (int i = 0; i < arr.Length; ++i) combinedPnl.SetColumnValues(i, arr[i].GetCombinedPnl()); if (combinedPnl.NeedsToSortKeys()) combinedPnl.SortKeys(); var eval = new ReturnsEval.DataSeriesEvaluator("Combined", ReturnsEval.DataSeriesType.Returns); eval.AddInnerSeries(combinedPnl.Dates.ToArray(), combinedPnl.ToArray(), combinedPnl.ColumnHeadings); eval.Display("Combined"); combinedPnl.SumRows().ToCumulative().DisplayLineChart("combined pnl of scaled weights"); } }
public static void EquityCTAEnviron() { //var copperIndex = Singleton<ComIDs>.Instance.First(x => x.Name.Equals("Copper")).ArrayIndex; //var index = // Singleton<ComIndexPrices>.Instance.GetData(DataConstants.DATA_START, DateTime.Today) // .GetColumnValuesAsDDC(copperIndex); //var index = EquityIndexOfSorts(); //var countries = new[] { "Germany", "US" }; //var instruments = // Singleton<DBFut_Chains>.Instance.Where( // x => x.AssetClass.Equals("Fixed Income") && countries.Any(y => y.Equals(x.Country))).ToArray(); var instruments= Singleton<DBFut_Chains>.Instance.Where( x => x.AssetClass.Equals("Equities")).ToArray(); foreach (var v in instruments) { var px = Singleton<DBFut_ChainGenericCache>.Instance.GetGenericSeries(v); showCombinedStdevFromMean(px, v.BbgTicker, new[] {21, 42, 63, 89, 100, 126, 150, 189, 252, 512}); } return; //var instruments = Singleton<DBFut_Chains>.Instance.Where(x => x.AssetClass.Equals("Equities")).ToArray(); var con = new ConstructGen<double>(instruments.Select(x => x.BbgTicker).ToArray()); for(int i=0;i<instruments.Length;++i) { var index = Singleton<DBFut_ChainGenericCache>.Instance.GetGenericSeries(instruments[i]); if (index == null || index.Length == 0) continue; var prop = getMADiffPercentiles(index, new PercDiffArgs[] { //new PercDiffArgs() {MA1 = 21, MA2 = 42, PercWindow = 126}, //new PercDiffArgs() {MA1 = 21, MA2 = 63, PercWindow = 126}, //new PercDiffArgs() {MA1 = 21, MA2 = 89, PercWindow = 126}, new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 126}, new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 126}, new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 126}, new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 126}, new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 126}, new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 126}, //new PercDiffArgs() {MA1 = 21, MA2 = 42, PercWindow = 252}, //new PercDiffArgs() {MA1 = 21, MA2 = 63, PercWindow = 252}, //new PercDiffArgs() {MA1 = 21, MA2 = 89, PercWindow = 252}, new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 252}, new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 252}, new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 252}, new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 252}, new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 252}, new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 252}, new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 504}, new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 504}, new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 504}, new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 504}, new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 504}, new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 504}, }); //var c = new SI.Controls.LineChartDataDisplay(); //c.AddSeries(index, "index", 40, "##0.0#"); //c.AddSeries(dates_: prop.Dates, // values_: prop.Data, // desc_: "prop", // yAxisExtent_: 40, // yLabelFormat_: "##0.0#", // color_: System.Drawing.Color.Orange, // yAxisLeft_: false); //c.DisplayInShowForm("blah"); con.SetColumnValues(i, index.ToReturns().MultiplyBy(prop)); } con.SortKeys(); var eval = new ReturnsEval.DataSeriesEvaluator("combined", DataSeriesType.Returns); eval.AddInnerSeries(con.Dates.ToArray(), con.ToArray(), con.ColumnHeadings); eval.Display(); }
public static ReturnsEval.DataSeriesEvaluator DoCommodsPnl(ConstructGen<double> wts_, string name_) { var returns = ReturnsFromComWeights.DoIt_DailyWeights(wts_); var eval = new ReturnsEval.DataSeriesEvaluator(name_, DataSeriesType.Returns); eval.AddInnerSeries(returns.CombinedPnl.Dates.ToArray(), returns.CombinedPnl.ToArray(), returns.CombinedPnl.ColumnHeadings); return eval; }
public static ReturnsEval.DataSeriesEvaluator DoFXPnl(ConstructGen<double> wts_, string name_,double mult_=1d) { var returns = ReturnsFromFXWeights.DoIt_DailyWeights(wts_); var combReturns = returns.CombinedPnl.MultiplyBy(mult_); var eval = new ReturnsEval.DataSeriesEvaluator(name_, ReturnsEval.DataSeriesType.Returns); eval.AddInnerSeries(combReturns.Dates.ToArray(), combReturns.ToArray(), combReturns.ColumnHeadings); return eval; }