Exemplo n.º 1
0
        public void AddingCashTransactionInForeignCurrencyResultsInFxPositionAddition()
        {
            var trade = new Trade();
            var date = new DateTime(2000, 1, 1);
            var eur = new Currency { ID = 2, Name = "EUR" };
            var ct = new CashTransaction { InstrumentID = 1, Currency = eur, CurrencyID = 2, Amount = 50, FXRateToBase = 1.5m, Instrument = _inst, TransactionDate = date, AssetCategory = AssetClass.Stock };
            trade.CashTransactions = new List<CashTransaction> { ct };
            var tracker = new TradeTracker(trade, 1);
            foreach (CashTransaction c in trade.CashTransactions)
            {
                tracker.AddCashTransaction(c);
            }

            Assert.IsTrue(tracker.CurrencyPositions.ContainsKey(2));
            Assert.IsTrue(tracker.CurrencyPositions[2].Quantity == 50);
            Assert.IsTrue(tracker.CurrencyPositions[2].CostBasis == 1.5m);
        }
Exemplo n.º 2
0
        public void PnLIsDeferredForROACCalculationsIfNoCapitalIsUsed()
        {
            var pos = new Position(_instrument);
            var c = new CashTransaction
            {
                Amount = 10,
                Instrument = _instrument,
                FXRateToBase = 1
            };
            pos.AddCashTransaction(c);

            pos.GetPnL(10, 1);

            var o = new Order
            {
                Quantity = 100,
                Price = 10,
                Instrument = _instrument,
                FXRateToBase = 1
            };
            pos.AddOrder(o);

            pos.GetPnL(10, 1);

            Assert.AreEqual(1 + (10d / (10 * 100)), pos.ROAC);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a cash transaction to this position.
        /// </summary>
        public void AddCashTransaction(CashTransaction ct)
        {
            if (Currency == null)
            {
                Currency = ct.Currency;
            }

            decimal amt = ct.Amount * ct.FXRateToBase;
            if (Quantity < 0)
            {
                _unrecognizedPnLShort += amt;
                RealizedPnLShort += amt;
            }
            else
            {
                _unrecognizedPnLLong += amt;
                RealizedPnLLong += amt;
            }
        }
Exemplo n.º 4
0
        public void ROACValueIsCorrectWithCashTransactions()
        {
            var pos = new Position(_instrument);
            var o = new Order
            {
                Quantity = 100,
                Price = 10,
                Instrument = _instrument,
                FXRateToBase = 1
            };
            pos.AddOrder(o);

            var c = new CashTransaction
            {
                Amount = 10,
                Instrument = _instrument,
                FXRateToBase = 1
            };
            pos.AddCashTransaction(c);

            pos.GetPnL(10, 1);

            Assert.AreEqual(1.01, pos.ROAC);
        }
Exemplo n.º 5
0
        public void AddCashTransaction(CashTransaction ct)
        {
            Open = true;

            if (ct.InstrumentID.HasValue)
            {
                if (Positions.ContainsKey(ct.Instrument.ID))
                    Positions[ct.Instrument.ID].AddCashTransaction(ct);
            }
            else
            {
                //InstrumentID is null. This happens frequently 
                //as many cash transactions are not related to a particular instrument
                Positions[NullInstrumentId].AddCashTransaction(ct);
            }

            if(ct.CurrencyID > 1)
            {
                var ft = new FXTransaction
                {
                    FXCurrency = ct.Currency,
                    FXCurrencyID = ct.CurrencyID,
                    Quantity = ct.Amount,
                    Proceeds = ct.Amount * ct.FXRateToBase,
                    Cost = -ct.Amount * ct.FXRateToBase,
                    DateTime = ct.TransactionDate
                };
                AddFXTransaction(ft);
            }

            _cashTransactionsRemaining--;
        }