public IntraCountryFlyMenuItem(string[] folderPath_, string text_, BondMarket market_, FlyWeightingMethod method_, int historyWinLength_) : base(folderPath_,text_) { Market = market_; WeightingMethod = method_; HistoryWindowLength = historyWinLength_; }
public CrossMarketFlyMenuItem(string[] folderPath_, string text_, int tenor_, int historyLength_, BondMarket[] markets_, FlyWeightingMethod method_) : base(folderPath_, text_) { Tenor = tenor_; Markets = markets_; WeightingMethod = method_; HistoryLength = historyLength_; }
public static double[] GetFlyWeightings(BondAnalysisLine A_, BondAnalysisLine B_, BondAnalysisLine C_, FlyWeightingMethod method_ = FlyWeightingMethod.Standard, int history_ = 100) { switch (method_) { case FlyWeightingMethod.Standard: { return new[] {Bfly_Wing, Bfly_Belly, Bfly_Wing}; } case FlyWeightingMethod.Value: { var Avals = A_.GetHistoricValuesForField(BondField.YieldLive) .GetEndValues(history_ + 1) .GetSubValues<double>(excludeFunction_: double.IsNaN); var Bvals = B_.GetHistoricValuesForField(BondField.YieldLive) .GetEndValues(history_ + 1) .GetSubValues(excludeFunction_: double.IsNaN); var Cvals = C_.GetHistoricValuesForField(BondField.YieldLive) .GetEndValues(history_ + 1) .GetSubValues(excludeFunction_: double.IsNaN); var CminusB = Cvals.Minus(Bvals).ToDifferences().Stdev(); var BminusA = Bvals.Minus(Avals).ToDifferences().Stdev(); var ratio = CminusB/BminusA; return new double[] { ratio/(ratio+1d), 1d, 1d/(ratio+1d) }; } case FlyWeightingMethod.PCAyield: case FlyWeightingMethod.PCAasw: { var Avals = A_.GetHistoricValuesForField(method_==FlyWeightingMethod.PCAyield ? BondField.YieldLive : BondField.ASWLive) .GetEndValues(history_ + 1) .GetSubValues<double>(excludeFunction_: double.IsNaN); var Bvals = B_.GetHistoricValuesForField(method_ == FlyWeightingMethod.PCAyield ? BondField.YieldLive : BondField.ASWLive) .GetEndValues(history_ + 1) .GetSubValues(excludeFunction_: double.IsNaN); var Cvals = C_.GetHistoricValuesForField(method_ == FlyWeightingMethod.PCAyield ? BondField.YieldLive : BondField.ASWLive) .GetEndValues(history_ + 1) .GetSubValues(excludeFunction_: double.IsNaN); var inlineDates = new[] {Avals, Bvals, Cvals}.IntersectDatesKeepSeparate(); var dblArr = new double[inlineDates[0].Length, 3]; for(int i=0;i<inlineDates[0].Length;++i) for (int j = 0; j < 3; ++j) dblArr[i, j] = inlineDates[j].Data[i]; var pcaWeights = Symmetry.Analytics.PCA.CalculateOptimalHedgeRatios(dblArr, false, 3, new double?[] {null, 1d, null}); return pcaWeights; } } return null; }
public static async void CreateIntraCountryOTRFlies(string[] folderPath_, BondMarket market_, FlyWeightingMethod method_, int historyWinLength_) { BondAnalysisLine a, b, c; var definitions = new List<BondStructureDefinition>(); foreach (var flySet in StructureConfigs.IntraCountryButterflies) { var aOTR = CountryBondSource.GetInstance(market_).OTRCache.GetTenor(flySet[0]); if (aOTR == null || (a = aOTR.Instantiation) == null) continue; var bOTR = CountryBondSource.GetInstance(market_).OTRCache.GetTenor(flySet[1]); if (bOTR == null || (b = bOTR.Instantiation) == null) continue; var cOTR = CountryBondSource.GetInstance(market_).OTRCache.GetTenor(flySet[2]); if (cOTR == null || (c = cOTR.Instantiation) == null) continue; var wts = StructureWeightings.GetFlyWeightings(a, b, c, method_, historyWinLength_); string suffix = string.Empty; switch (method_) { case FlyWeightingMethod.PCAyield: suffix = " PCAy"; break; case FlyWeightingMethod.PCAasw: suffix = " PCAa"; break; case FlyWeightingMethod.Value: suffix = " Value"; break; } definitions.Add(new BondStructureDefinition() { FolderTree = folderPath_, Items = new System.ComponentModel.BindingList<BondStructureDefinitionItem>(new[] { BondStructureDefinitionItem.GetDefinition(a,wts[0]), BondStructureDefinitionItem.GetDefinition(b,wts[1]), BondStructureDefinitionItem.GetDefinition(c,wts[2]), }), Name = string.Format("{0} [{1}] [{2}] [{3}]{4}", market_, string.Format("{0} {1}", wts[0].ToString("##0.0#"), a.Maturity.ToString("MM-yy")), string.Format("{0} {1}", wts[1].ToString("##0.0#"), b.Maturity.ToString("MM-yy")), string.Format("{0} {1}", wts[2].ToString("##0.0#"), c.Maturity.ToString("MM-yy")), suffix), Owner = SymmetryEnvironment.UserName }); } await Singleton<BondStructureDefinitionCache>.Instance.AddOrUpdateDefinitions(definitions); }