Example #1
0
        public void LastPriceFxDataIsInvertedWhenNecessary()
        {
            var inst = new Instrument {
                Symbol = "USD.CAD", ID = 1, AssetCategory = AssetClass.Cash
            };
            var startDate = new DateTime(2000, 1, 1);

            var fxrSetStub = new DbSetStub <FXRate>();

            fxrSetStub.Add(new FXRate {
                FromCurrencyID = 2, ToCurrencyID = 1, Date = startDate, Rate = 1.1m
            });

            var currencySetStub = new DbSetStub <Currency>();

            currencySetStub.Add(new Currency {
                ID = 2, Name = "CAD"
            });

            _contextMock.Setup(x => x.Currencies).Returns(currencySetStub);
            _contextMock.Setup(x => x.FXRates).Returns(fxrSetStub);

            decimal fxRate;
            var     price = _datasourcer.GetLastPrice(inst, out fxRate);

            Assert.AreEqual(1m / 1.1m, price);
        }
Example #2
0
        public async void CashInstrumentLocalRequestsUseFxRates()
        {
            DateTime startDate = new DateTime(2000, 1, 1);
            DateTime endDate   = new DateTime(2000, 1, 3);
            var      inst      = new Instrument {
                ID = 1, Symbol = "EUR.USD", AssetCategory = AssetClass.Cash, QDMSInstrumentID = 2
            };

            var fxrSetStub = new DbSetStub <FXRate>();

            var currencySetStub = new DbSetStub <Currency>();

            currencySetStub.Add(new Currency {
                ID = 2, Name = "EUR"
            });

            _contextMock.Setup(x => x.Currencies).Returns(currencySetStub);
            _contextMock.Setup(x => x.FXRates).Returns(fxrSetStub);

            _externalSourceMock.Setup(
                x => x.GetData(It.IsAny <Instrument>(),
                               It.IsAny <DateTime>(),
                               It.IsAny <DateTime>(),
                               It.IsAny <BarSize>()))
            .ReturnsAsync(new List <OHLCBar>());

            await _datasourcer.GetData(inst, startDate, endDate).ConfigureAwait(true);

            _contextMock.Verify(x => x.FXRates);
        }
Example #3
0
        public async void FxDataIsInvertedWhenNecessary()
        {
            var inst = new Instrument {
                Symbol = "USD.CAD", ID = 1, AssetCategory = AssetClass.Cash
            };
            var startDate = new DateTime(2000, 1, 1);
            var endDate   = new DateTime(2000, 1, 1);

            var fxrSetStub = new DbSetStub <FXRate>();

            fxrSetStub.Add(new FXRate {
                FromCurrencyID = 2, ToCurrencyID = 1, Date = startDate, Rate = 1.1m
            });

            var currencySetStub = new DbSetStub <Currency>();

            currencySetStub.Add(new Currency {
                ID = 2, Name = "CAD"
            });

            _contextMock.Setup(x => x.Currencies).Returns(currencySetStub);
            _contextMock.Setup(x => x.FXRates).Returns(fxrSetStub);

            var data = await _datasourcer.GetData(inst, startDate, endDate).ConfigureAwait(true);

            Assert.AreEqual(1m / 1.1m, data[0].Close);
        }
Example #4
0
        public void CashTransactionsAreCorrectlyIncludedInPnL()
        {
            _t.Orders.Add(new Order {
                Quantity = 10, Instrument = _inst, Price = 100, FXRateToBase = 1, BuySell = "BUY", TradeDate = new DateTime(2000, 1, 1)
            });
            _t.CashTransactions.Add(new CashTransaction {
                Instrument = _inst, InstrumentID = 1, FXRateToBase = 1, Amount = 5, TransactionDate = new DateTime(2000, 1, 2)
            });

            _dbSetStub.Add(new EquitySummary
            {
                Date  = new DateTime(2000, 1, 2),
                Total = 10000
            });

            _repository.UpdateStats(_t, true);

            Assert.AreEqual(5, _t.ResultDollars);
            Assert.AreEqual(5, _t.ResultDollarsLong);
            Assert.AreEqual(0, _t.ResultDollarsShort);
        }