示例#1
0
        public void RealizedProfitsWithUpdateBetweenTradesCalculatedCorrectly()
        {
            var pos = new CurrencyPosition(_currency);

            decimal fxRate   = 1.35m;
            int     quantity = 1000;

            var transaction1 = new FXTransaction
            {
                Quantity   = quantity,
                Proceeds   = fxRate * quantity,
                Cost       = -fxRate * quantity,
                FXCurrency = _currency
            };

            pos.AddFXTransaction(transaction1);

            decimal newFxRate = 1.36m;

            pos.Update(newFxRate);

            Assert.AreEqual(quantity * (newFxRate - fxRate), pos.TotalPnL);

            int     newQuantity = -1000;
            decimal newFxRate2  = 1.37m;

            var transaction2 = new FXTransaction
            {
                Quantity   = newQuantity,
                Proceeds   = newFxRate2 * newQuantity,
                Cost       = -newFxRate2 * newQuantity,
                FXCurrency = _currency
            };

            pos.AddFXTransaction(transaction2);

            Assert.AreEqual(-newQuantity * (newFxRate2 - fxRate), pos.RealizedPnL);
        }
示例#2
0
        public void ProfitCorrectlyCalculatedAfterSimpleEntryAndExit()
        {
            var pos = new CurrencyPosition(_currency);

            decimal fxRate   = 1.35m;
            int     quantity = 1000;

            var transaction1 = new FXTransaction
            {
                Quantity   = quantity,
                Proceeds   = fxRate * quantity,
                Cost       = -fxRate * quantity,
                FXCurrency = _currency
            };

            pos.AddFXTransaction(transaction1);

            decimal newFxRate = 1.36m;

            quantity = -quantity;
            var transaction2 = new FXTransaction
            {
                Quantity   = quantity,
                Proceeds   = newFxRate * quantity,
                Cost       = -newFxRate * quantity,
                FXCurrency = _currency
            };

            pos.AddFXTransaction(transaction2);

            Assert.AreEqual(-quantity * (newFxRate - fxRate), pos.RealizedPnL);

            pos.Update(newFxRate);

            Assert.AreEqual(-quantity * (newFxRate - fxRate), pos.TotalPnL);
        }