コード例 #1
0
ファイル: CashFlowTest.cs プロジェクト: jasonmnemonic/TA4N
        public void DynamicAddTrade()
        {
            var data = new double[] { 2, 1, 3, 5, 6, 3, 20, 20, 3 };

            // We will rely on this being correct as it duplicates tests above...
            TimeSeries confirmedSeries        = GenerateTimeSeries.From(data);
            var        confirmedTradingRecord = new TradingRecord(Order.BuyAt(0), Order.SellAt(2), Order.BuyAt(3), Order.SellAt(4), Order.BuyAt(5), Order.SellAt(6), Order.BuyAt(7), Order.SellAt(8));
            // use these results to check against the dynamically added Trades
            var confirmedCashFlow = new CashFlow(confirmedSeries, confirmedTradingRecord);

            TimeSeries sampleTimeSeries = new TimeSeries();
            var        tradingRecord    = new TradingRecord();
            var        cashFlow         = new CashFlow(sampleTimeSeries, tradingRecord);

            for (var i = 0; i < data.Length; i++)
            {
                sampleTimeSeries.AddTick(GenerateTick.From((new LocalDateTime()).WithMillisOfSecond(i), data[i]));
                switch (i)
                {
                case 0:     // buy
                case 3:     // buy
                case 5:     // buy
                case 7:     // buy
                    tradingRecord.Enter(i);
                    break;

                case 2:     // sell
                case 4:     // sell
                case 6:     // sell
                case 8:     // sell
                    tradingRecord.Exit(i);
                    cashFlow.AddTrade(tradingRecord.LastTrade);
                    break;

                default:
                    // don't do anything
                    break;
                }
            }

            // Check all the data off...
            Assert.Multiple(() =>
            {
                for (var i = 0; i < data.Length; i++)
                {
                    TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(i), confirmedCashFlow.GetValue(i).ToDouble());
                }
            });
        }