public double GetFxRate(DateTime settlementDate, Currency domesticCcy, Currency foreignCcy) { //domestic-per-foreign if (foreignCcy == domesticCcy) { return(1.0); } double spot; if (domesticCcy == FxMatrix.BaseCurrency) { spot = FxMatrix.GetSpotRate(foreignCcy); } else if (foreignCcy == FxMatrix.BaseCurrency) { spot = 1.0 / FxMatrix.GetSpotRate(domesticCcy); } else { var forToBase = GetFxRate(settlementDate, FxMatrix.BaseCurrency, foreignCcy); var domToBase = GetFxRate(settlementDate, FxMatrix.BaseCurrency, domesticCcy); return(forToBase / domToBase); } var fxPair = FxMatrix.GetFxPair(domesticCcy, foreignCcy); var spotDate = BuildDate.AddPeriod(RollType.F, fxPair.PrimaryCalendar, fxPair.SpotLag); var dfDom = GetDf(domesticCcy, spotDate, settlementDate); var dfFor = GetDf(foreignCcy, spotDate, settlementDate); return(spot * dfDom / dfFor); }
public double[] GetFxRates(DateTime[] fixingDates, Currency domesticCcy, Currency foreignCcy) { if (foreignCcy == domesticCcy) { return(Enumerable.Repeat(1.0, fixingDates.Length).ToArray()); } else { var pair = FxMatrix.GetFxPair(domesticCcy, foreignCcy); var settleDates = fixingDates.Select(x => x.AddPeriod(RollType.F, pair.PrimaryCalendar, pair.SpotLag)); var rates = settleDates.Select(d => GetFxRate(d, domesticCcy, foreignCcy)).ToArray(); return(rates); } }