protected ATMVolsRankGroup(FXGroup group_) { var currencies = Singleton<FXIDs>.Instance.Where(x => x.IsGroup(group_)).ToArray(); var oneWeek = new ConstructGen<double>(currencies.Select(x => x.Code).ToArray()); var oneMonth = new ConstructGen<double>(currencies.Select(x => x.Code).ToArray()); for (int i = 0; i < currencies.Length; ++i) { { var vols = BbgTalk.HistoryRequester.GetHistory(DataConstants.DATA_START, currencies[i].AtTheMoneyVolTicker_1W, "PX_LAST", false); oneWeek.SetColumnValues(i, vols); } { var vols = BbgTalk.HistoryRequester.GetHistory(DataConstants.DATA_START, currencies[i].AtTheMoneyVolTicker_1M, "PX_LAST", false); oneMonth.SetColumnValues(i, vols); } } { oneWeek.SortKeys(); var avg1W = oneWeek.AvgRows(); ATM_1W_Avg = avg1W; ATM_1W_o6M = avg1W.ToPercentileRanked(126); ATM_1W_o1Y = avg1W.ToPercentileRanked(252); } { oneMonth.SortKeys(); var avg1M = oneMonth.AvgRows(); ATM_1M_Avg = avg1M; ATM_1M_o6M = avg1M.ToPercentileRanked(126); ATM_1M_o1Y = avg1M.ToPercentileRanked(252); } }
public static DatedDataCollectionGen<double> GetIndicator(IndicType type_) { DatedDataCollectionGen<double> ret = null; switch (type_) { case IndicType.ATM1WVol_actual: ret = Singleton<ATMVolsRank>.Instance.ATM_1W_Avg; break; case IndicType.ATM1WVols_pr126: ret = Singleton<ATMVolsRank>.Instance.ATM_1W_o6M; break; case IndicType.ATM1WVols_pr252: ret = Singleton<ATMVolsRank>.Instance.ATM_1W_o1Y; break; case IndicType.ATM1WVol_actual_vol21: ret = HelperMethods.GetRollingStdev(Singleton<ATMVolsRank>.Instance.ATM_1W_o1Y, 21); break; case IndicType.ATM1MVol_actual: ret = Singleton<ATMVolsRank>.Instance.ATM_1M_Avg; break; case IndicType.ATM1MVols_pr126: ret = Singleton<ATMVolsRank>.Instance.ATM_1M_o6M; break; case IndicType.ATM1MVols_pr252: ret = Singleton<ATMVolsRank>.Instance.ATM_1M_o1Y; break; case IndicType.ATMDelivs1MVols_pr252: ret = Singleton<ATMVolsRankDelivs>.Instance.ATM_1M_o1Y; break; case IndicType.ATM_EMs_1MVols_actual_pr252: ret = Singleton<ATMVolsRankEMs>.Instance.ATM_1M_o1Y; break; case IndicType.EWMA_Vol_pr252: { ret = new SI.Data.FXEWMAVariances(0.94, 252).Values.SumRows() .ToPercentileRanked(252); } break; case IndicType.CommodsMultiUniverse: { ret = Singleton<MultiCommodsIndicator.CommodsUniverseScore_21>.Instance.Pxs; } break; case IndicType.CommodsMultiAgs: ret = Singleton<MultiCommodsIndicator.CommodsGrainsScore_21>.Instance.Pxs; break; case IndicType.CommodsMultiBase: ret = Singleton<MultiCommodsIndicator.CommodsBaseScore_21>.Instance.Pxs; break; case IndicType.CcyMultiUniverse: ret = Singleton<MultiCcyIndicator.CurrencyUniverseScore_21>.Instance.Pxs; break; case IndicType.CcyMultAsiaIncG10: ret = Singleton<MultiCcyIndicator.CurrencyAsiaIncG10_21>.Instance.Pxs; break; case IndicType.CcyMultCEEMEA: ret = Singleton<MultiCcyIndicator.CurrencyCEEMEAScore_21>.Instance.Pxs; break; case IndicType.CcyMultAmericas: ret = Singleton<MultiCcyIndicator.CurrencyAmericasScore_21>.Instance.Pxs; break; case IndicType.CcyMultiG10: ret = Singleton<MultiCcyIndicator.CurrencyG10Score_21>.Instance.Pxs; break; case IndicType.FI_Futures: ret = Singleton<Futures.Breakout.FutChainOptArgs>.Instance.Index; break; case IndicType.CcyMultiEM: ret = Singleton<MultiCcyIndicator.CurrencyEMScore_21>.Instance.Pxs; break; case IndicType.DXY_sc21: ret = Singleton<DXYScore_21>.Instance.Scores; break; case IndicType.DXY_sc21_contextMA252: { var rawScores = (DatedDataCollectionGen<double>)Singleton<DXYScore_21>.Instance.Scores.Clone(); var pxsSeries = Singleton<DXYScore_21>.Instance.Pxs; var maSeries = HelperMethods.GetMA(pxsSeries, 252); for (int i = 0; i < maSeries.Length; ++i) { var date = maSeries.Dates[i]; var px = pxsSeries.ValueOnExactDate(date); var ma = maSeries.Data[i]; var score = rawScores.ValueOnExactDate(date); if (score > 0d && px < ma) { rawScores.Data[rawScores.IndexOf(date)] = 0d; } else if (score < 0d && px > ma) { rawScores.Data[rawScores.IndexOf(date)] = 0d; } } return rawScores; } case IndicType.DXY_sc42_contextMA252: { var pxsSeries = Singleton<DXYScore_21>.Instance.Pxs; var rawScores = HelperMethods.CalculateStdevFromMean(pxsSeries, 42, 42); var maSeries = HelperMethods.GetMA(pxsSeries, 252); for (int i = 0; i < maSeries.Length; ++i) { var date = maSeries.Dates[i]; var px = pxsSeries.ValueOnExactDate(date); var ma = maSeries.Data[i]; var score = rawScores.ValueOnExactDate(date); if (score > 0d && px < ma) { rawScores.Data[rawScores.IndexOf(date)] = 0d; } else if (score < 0d && px > ma) { rawScores.Data[rawScores.IndexOf(date)] = 0d; } } return rawScores; } case IndicType.DXY_sc63_contextMA252: { var pxsSeries = Singleton<DXYScore_21>.Instance.Pxs; var rawScores = HelperMethods.CalculateStdevFromMean(pxsSeries, 63, 63); var maSeries = HelperMethods.GetMA(pxsSeries, 252); for (int i = 0; i < maSeries.Length; ++i) { var date = maSeries.Dates[i]; var px = pxsSeries.ValueOnExactDate(date); var ma = maSeries.Data[i]; var score = rawScores.ValueOnExactDate(date); if (score > 0d && px < ma) { rawScores.Data[rawScores.IndexOf(date)] = 0d; } else if (score < 0d && px > ma) { rawScores.Data[rawScores.IndexOf(date)] = 0d; } } return rawScores; } //case IndicType.CustomDXY_sc21: ret = Singleton<CurrencyUniverseScore_21>.Instance.Scores; break; case IndicType.MoveIndex_pr252: ret = Singleton<MOVEScore_21>.Instance.Pxs.ToPercentileRanked(252); break; case IndicType.MoveIndex_pr100: ret = Singleton<MOVEScore_21>.Instance.Pxs.ToPercentileRanked(100); break; case IndicType.VIX_sc: ret = Singleton<VIXScore_21>.Instance.Scores; break; case IndicType.VIX_actual: { DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, "VIX INDEX", "PX_LAST", true); ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data); } break; //case IndicType.AllVsDow_actual: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".ALLVSDOW INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data); // } // break; case IndicType.DXY_actual: { DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, "DXY CURNCY", "PX_LAST", true); ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data); } break; case IndicType.VIX_pr20: { DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, "VIX INDEX", "PX_LAST", true); ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(20); } break; case IndicType.VIX_pr252: { DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, "VIX INDEX", "PX_LAST", true); ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(126); } break; //case IndicType.GoldCopper_pr20: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".GLDCOP INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(20); // } // break; //case IndicType.GoldCopper_pr126: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".GLDCOP INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(126); // } // break; //case IndicType.GoldCopper_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".GLDCOP INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.GoldGoldEqu_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".GLDGLDEQ INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.SPXRUSS_pr20: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".SPXRTY INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(20); // } // break; //case IndicType.SPXRUSS_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".SPXRTY INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.TEDSpread_pr: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".TED INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.VIXVDAX_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".VV INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.CVIXVIX_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".VCV INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.LIBORoisSpread_pr20: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".LOISS INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(20); // } // break; //case IndicType.LIBORoisSpread_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".LOISS INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.IGCS_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".IGCS INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.FSR_pr20: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".FSRE INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(20); // } // break; //case IndicType.FSR_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".FSRE INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; //case IndicType.VolSlope_pr252: // { // DatedDataCollectionGen<double> dd = BbgTalk.Core.Instance.GetHistory(Environment.UserName, DataConstants.DATA_START, ".VSL INDEX", "PX_LAST", true); // ret = new DatedDataCollectionGen<double>(dd.Dates, dd.Data).ToPercentileRanked(252); // } // break; case IndicType.AvgCarry_actual: { var spots = Singleton<FXSpots>.Instance.GetData(DataConstants.DATA_START, DateTime.Today, true); var fwds = Singleton<FXForwards1Wk>.Instance.GetData(DataConstants.DATA_START, DateTime.Today, true); Currency[] ccys = Singleton<FXIDs>.Instance.ToArray(); ConstructGen<double> con = new ConstructGen<double>(ccys.Select(x=>x.Code).ToArray()); for (int d = 0; d < spots.Dates.Count; ++d) { DateTime date = spots.Dates[d]; double ccyCarry = 0d; for (int c = 0; c < ccys.Length; ++c) { if (ccys[c].IsValid(date) == false) continue; if (ccys[c].Convention == 1) ccyCarry = ((spots.GetValue(date, c) / fwds.GetValue(date, c)) - 1d) * (252d / 5d); else ccyCarry = ((fwds.GetValue(date, c) / spots.GetValue(date, c)) - 1d) * (252d / 5d); con.SetValue(date, c, ccyCarry); } } ret = con.AvgRows(); for (int i = 1; i < ret.Length; ++i) { if (double.IsInfinity(ret.Data[i])) ret.Data[i] = ret.Data[i - 1]; ret.Data[i] = Math.Max(ret.Data[i], -0.01); } } break; //case IndicType.sigNumRebals21: // { // DateTime[] allDates = Singleton<FXSpots>.Instance.GetData(DataConstants.DATA_START, DateTime.Today, true).Dates; // double[] rebalInd = new double[allDates.Length]; // for (int i = 0; i < allDates.Length; ++i) // if (sigWeights_.Dates.Contains(allDates[i])) // rebalInd[i] = 1d; // ret = new DatedDataCollectionGen<double>(allDates, rebalInd).ToRollingSum(21); // } // break; //case IndicType.sigTurnover21: // { // List<DateTime> allDates = new List<DateTime>(Singleton<FXSpots>.Instance.GetData(DataConstants.DATA_START, DateTime.Today, true).Dates); // double[] tOver = new double[allDates.Count]; // double[] prevweights = sigWeights_.GetValues(sigWeights_.Dates[0]); // for (int i = 0; i < sigWeights_.Dates.Count; ++i) // { // DateTime date = sigWeights_.Dates[i]; // int index = allDates.IndexOf(date); // if (index == -1) // continue; // double[] todayWts = sigWeights_.GetValues(date); // double totalTurnover = 0d; // for (int j = 0; j < todayWts.Length; ++j) // { // double diff = todayWts[j] - prevweights[j]; // if (diff == 0d) continue; // if (prevweights[j] == 0d) continue; // totalTurnover += (Math.Abs(diff) / Math.Abs(prevweights[j])); // } // tOver[index] = totalTurnover; // } // ret = new DatedDataCollectionGen<double>(allDates.ToArray(), tOver).ToRollingSum(21); // } // break; //case IndicType.sigReturn21: // { // ret = sigDailyReturns_.ToRollingSum(21); // } // break; //case IndicType.sigTOverReturn21: // { // ret = GetIndicator(IndicType.sigReturn21, sigWeights_, sigDailyReturns_).MultiplyBy(GetIndicator(IndicType.sigTurnover21, sigWeights_, sigDailyReturns_)); // } // break; //case IndicType.sigPnlVsMA100: // { // ret = GetDiffVsMA(sigDailyReturns_, 100); // } // break; //case IndicType.sigPnlVsMA50: // { // ret = GetDiffVsMA(sigDailyReturns_, 50); // } // break; case IndicType.ccyRankPers21to5: { ret = getPersistenceOfCurrencyReturns(42, 5, FXGroup.EM); } break; case IndicType.EmVolAvg21_actual: { ret = getRollingAvgVol(FXGroup.EM, 21); } break; case IndicType.G10VolAvg21_actual: { ret = getRollingAvgVol(FXGroup.G10, 21); } break; case IndicType.EMVolAvg21_pr126: { ret = getRollingAvgVol(FXGroup.EM, 21).ToPercentileRanked(126); } break; //case IndicType.G4SwpSprd_actual: // { // ret = Singleton<GXSwapRates>.Instance.G4; // } // break; //case IndicType.G4SwpSprd_pr20: // { // ret = Singleton<GXSwapRates>.Instance.G4.ToPercentileRanked(20); // } // break; //case IndicType.G4SwpSprd_pr252: // { // ret = Singleton<GXSwapRates>.Instance.G4.ToPercentileRanked(252); // } // break; //case IndicType.G10SwpSprd_actual: // { // ret = Singleton<GXSwapRates>.Instance.G10; // } // break; //case IndicType.G10SwpSprd_pr20: // { // ret = Singleton<GXSwapRates>.Instance.G10.ToPercentileRanked(20); // } // break; //case IndicType.G10SwpSprd_pr126: // { // ret = Singleton<GXSwapRates>.Instance.G10.ToPercentileRanked(126); // } // break; //case IndicType.G10SwpSprd_pr252: // { // ret = Singleton<GXSwapRates>.Instance.G10.ToPercentileRanked(252); // } // break; case IndicType.RVOL_sc21: { ret = FXStrat.BacktestHelper.getWE(FXStrat.Strat.RVOL).Value.Daily.ToStdevFromMean(21, 21); } break; } return ret; }