Exemple #1
0
        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.SpotRates[foreignCcy];
            }
            else if (foreignCcy == FxMatrix.BaseCurrency)
            {
                spot = 1.0 / FxMatrix.SpotRates[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.SettlementCalendar, fxPair.SpotLag);
            var dfDom    = Curves[FxMatrix.DiscountCurveMap[domesticCcy]].GetDf(spotDate, settlementDate);
            var dfFor    = Curves[FxMatrix.DiscountCurveMap[foreignCcy]].GetDf(spotDate, settlementDate);

            return(spot * dfDom / dfFor);
        }
Exemple #2
0
 public void SetupFx(FxMatrix fxMatrix) => FxMatrix = fxMatrix;