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(); }
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(); }