示例#1
0
 public FXQuoteTest()
 {
     this.fxAUD_USD = new FXQuote(baseCurrency: "AUD", counterCurrency: "USD", bidRate: 1.00275d, offerPlusPip: 5);
     this.fxGBP_USD = new FXQuote(baseCurrency: "GBP", counterCurrency: "USD", bidRate: 1.56788d, offerPlusPip: 5);
     this.fxUSD_CHF = new FXQuote(baseCurrency: "USD", counterCurrency: "CHF", bidRate: 0.92866d, offerPlusPip: 5);
     this.fxUSD_EUR = new FXQuote(baseCurrency: "USD", counterCurrency: "EUR", bidRate: 0.76257d, offerPlusPip: 5);
 }
示例#2
0
        public void TestCalculateDifferentQuote()
        {
            var fxGBP_EUR = FXQuote.CalculateCrossCurrencyQuote(this.fxGBP_USD, this.fxUSD_EUR);

            Assert.AreEqual(1.1956182516d, fxGBP_EUR.BidRate, Mathematics.Error, "Bid rate wrong for A/B, B/C => A/C");
            Assert.AreEqual(1.1967837266d, fxGBP_EUR.OfferRate, Mathematics.Error, "Offer rate wrong for A/B, B/C => A/C");

            var fxEUR_AUD = FXQuote.CalculateCrossCurrencyQuote(this.fxUSD_EUR, this.fxAUD_USD);

            Assert.AreEqual(1.3062504465947817d, fxEUR_AUD.BidRate, Mathematics.Error, "Bid rate wrong for A/B, C/A => B/C");
            Assert.AreEqual(1.3077586867568349d, fxEUR_AUD.OfferRate, Mathematics.Error, "Offer rate wrong for A/B, C/A => B/C");
        }
示例#3
0
        public void TestCalculateSameQuote()
        {
            var fxCHF_EUR = FXQuote.CalculateCrossCurrencyQuote(this.fxUSD_CHF, this.fxUSD_EUR);

            Assert.AreEqual(0.82070902750871755d, fxCHF_EUR.BidRate, Mathematics.Error, "Bid rate wrong for A/B, A/C => B/C");
            Assert.AreEqual(0.82168931578834d, fxCHF_EUR.OfferRate, Mathematics.Error, "Offer rate wrong for A/B, A/C => B/C");

            var fxAUD_GBP = FXQuote.CalculateCrossCurrencyQuote(this.fxAUD_USD, this.fxGBP_USD);

            Assert.AreEqual(0.63935398309083269d, fxAUD_GBP.BidRate, Mathematics.Error, "Bid rate wrong for A/B, C/B => A/C");
            Assert.AreEqual(0.63987677628389927d, fxAUD_GBP.OfferRate, Mathematics.Error, "Offer rate wrong for A/B, C/B => A/C");
        }
示例#4
0
		public static FXQuote CalculateCrossCurrencyQuote(FXQuote firstQuote, FXQuote secondQuote)
		{
			var commonCurrency = FindCommonCurrency(firstQuote, secondQuote);

			if (firstQuote.BaseCurrency == commonCurrency)
			{
				return firstQuote.BaseCurrency == secondQuote.BaseCurrency ?
					CalculateSameQuote(commonCurrency, firstQuote, secondQuote) :
					CalculateDifferentQuote(commonCurrency, firstQuote, secondQuote);
			}

			return firstQuote.CounterCurrency == secondQuote.CounterCurrency ?
				CalculateSameQuote(commonCurrency, firstQuote, secondQuote) :
				CalculateDifferentQuote(commonCurrency, firstQuote, secondQuote);
		}
示例#5
0
		private static string FindCommonCurrency(FXQuote firstQuote, FXQuote secondQuote)
		{
			if (firstQuote.BaseCurrency == secondQuote.BaseCurrency)
				return firstQuote.BaseCurrency;

			if (firstQuote.BaseCurrency == secondQuote.CounterCurrency)
				return firstQuote.BaseCurrency;

			if (firstQuote.CounterCurrency == secondQuote.BaseCurrency)
				return firstQuote.CounterCurrency;

			if (firstQuote.CounterCurrency == secondQuote.CounterCurrency)
				return firstQuote.CounterCurrency;

			throw new FinancialException("No common currency between FXQuote objects");
		}
示例#6
0
		private static FXQuote CalculateDifferentQuote(string commonCurrency, FXQuote firstQuote, FXQuote secondQuote)
		{
			var fxQuote = new FXQuote();

			if (firstQuote.BaseCurrency == commonCurrency)
			{
				fxQuote.BaseCurrency = firstQuote.CounterCurrency;
				fxQuote.CounterCurrency = secondQuote.BaseCurrency;
				fxQuote.BidRate = 1 / (firstQuote.OfferRate * secondQuote.OfferRate);
				fxQuote.OfferRate = 1 / (firstQuote.BidRate * secondQuote.BidRate);
			}
			else
			{
				fxQuote.BaseCurrency = firstQuote.BaseCurrency;
				fxQuote.CounterCurrency = secondQuote.CounterCurrency;
				fxQuote.BidRate = firstQuote.BidRate * secondQuote.BidRate;
				fxQuote.OfferRate = firstQuote.OfferRate * secondQuote.OfferRate;
			}

			return fxQuote;
		}
示例#7
0
        static void Main()
        {
            var cashflowPricer = new CashflowPricer();

            cashflowPricer.Calculate();
            Console.WriteLine(cashflowPricer);

            var bondPricer = new BondPricer();

            bondPricer.Calculate();
            Console.WriteLine(bondPricer);

            var yieldCurve = new YieldCurve();

            yieldCurve.BootstrapSpotYields();
            Console.WriteLine(yieldCurve);

            var depositCertificate = new CertificateDeposit();

            depositCertificate.Calculate();
            Console.WriteLine(depositCertificate);

            var discountPaper = new DiscountPaper();

            discountPaper.Calculate();
            Console.WriteLine(discountPaper);

            var fixedDeposit = new FixedDeposit();

            fixedDeposit.Calculate();
            Console.WriteLine(fixedDeposit);

            var fxQuote = new FXQuote();

            Console.WriteLine(fxQuote);

            Console.ReadKey();
        }