Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        public void CalculateFixedCostWithOneTrade()
        {
            var series = GenerateTimeSeries.From(100, 95, 100, 80, 85, 70);
            var trade  = new Trade();
            IAnalysisCriterion transactionCost = new LinearTransactionCostCriterion(1000, 0, 0.75d);

            Assert.AreEqual(0, (int)transactionCost.Calculate(series, trade));

            trade.Operate(1);
            Assert.AreEqual(0.75d, transactionCost.Calculate(series, trade), TaTestsUtils.TaOffset);

            trade.Operate(3);
            Assert.AreEqual(1.5d, transactionCost.Calculate(series, trade), TaTestsUtils.TaOffset);

            trade.Operate(4);
            Assert.AreEqual(1.5d, transactionCost.Calculate(series, trade), TaTestsUtils.TaOffset);
        }