コード例 #1
0
        public void Operate()
        {
            var record = new TradingRecord();

            record.Operate(1);
            Assert.IsTrue(record.CurrentTrade.Opened);
            Assert.AreEqual(0, record.TradeCount);
            Assert.IsNull(record.LastTrade);
            Assert.AreEqual(Order.BuyAt(1), record.LastOrder);
            Assert.AreEqual(Order.BuyAt(1), record.GetLastOrder(OrderType.Buy));
            Assert.IsNull(record.GetLastOrder(OrderType.Sell));
            Assert.AreEqual(Order.BuyAt(1), record.LastEntry);
            Assert.IsNull(record.LastExit);

            record.Operate(3);
            Assert.IsTrue(record.CurrentTrade.New);
            Assert.AreEqual(1, record.TradeCount);
            Assert.AreEqual(new Trade(Order.BuyAt(1), Order.SellAt(3)), record.LastTrade);
            Assert.AreEqual(Order.SellAt(3), record.LastOrder);
            Assert.AreEqual(Order.BuyAt(1), record.GetLastOrder(OrderType.Buy));
            Assert.AreEqual(Order.SellAt(3), record.GetLastOrder(OrderType.Sell));
            Assert.AreEqual(Order.BuyAt(1), record.LastEntry);
            Assert.AreEqual(Order.SellAt(3), record.LastExit);

            record.Operate(5);
            Assert.IsTrue(record.CurrentTrade.Opened);
            Assert.AreEqual(1, record.TradeCount);
            Assert.AreEqual(new Trade(Order.BuyAt(1), Order.SellAt(3)), record.LastTrade);
            Assert.AreEqual(Order.BuyAt(5), record.LastOrder);
            Assert.AreEqual(Order.BuyAt(5), record.GetLastOrder(OrderType.Buy));
            Assert.AreEqual(Order.SellAt(3), record.GetLastOrder(OrderType.Sell));
            Assert.AreEqual(Order.BuyAt(5), record.LastEntry);
            Assert.AreEqual(Order.SellAt(3), record.LastExit);
        }
コード例 #2
0
        public void CalculateFixedCost()
        {
            var series = GenerateTimeSeries.From(100, 105, 110, 100, 95, 105);
            IAnalysisCriterion transactionCost = new LinearTransactionCostCriterion(1000, 0, 1.3d);

            var tradingRecord = new TradingRecord(Order.BuyAt(0), Order.SellAt(1));

            Assert.AreEqual(2.6d, transactionCost.Calculate(series, tradingRecord), TaTestsUtils.TaOffset);

            tradingRecord.Operate(2);
            tradingRecord.Operate(3);
            Assert.AreEqual(5.2d, transactionCost.Calculate(series, tradingRecord), TaTestsUtils.TaOffset);

            tradingRecord.Operate(0);
            Assert.AreEqual(6.5d, transactionCost.Calculate(series, tradingRecord), TaTestsUtils.TaOffset);
        }
コード例 #3
0
        public void CalculateLinearCost()
        {
            var series = GenerateTimeSeries.From(100, 150, 200, 100, 50, 100);
            IAnalysisCriterion transactionCost = new LinearTransactionCostCriterion(1000, 0.005, 0.2);

            var tradingRecord = new TradingRecord(Order.BuyAt(0), Order.SellAt(1));

            Assert.AreEqual(12.861, transactionCost.Calculate(series, tradingRecord), TaTestsUtils.TaOffset);

            tradingRecord.Operate(2);
            tradingRecord.Operate(3);
            Assert.AreEqual(24.3473, transactionCost.Calculate(series, tradingRecord), TaTestsUtils.TaOffset);

            tradingRecord.Operate(5);
            Assert.AreEqual(28.2204, transactionCost.Calculate(series, tradingRecord), TaTestsUtils.TaOffset);
        }