Пример #1
0
        public void LimitCloseLongProfitTest()
        {
            double       initial_cash        = 1000;
            double       commission_per_unit = 0.01;
            List <Price> prices = new List <Price>();

            prices.Add(new Price(new DateTimeUTC(2000, 0, 0, 0, 0, 0), 1.0, 1.1));
            prices.Add(new Price(new DateTimeUTC(2000, 0, 0, 0, 0, 1), 1.4, 1.5));
            prices.Add(new Price(new DateTimeUTC(2000, 0, 0, 0, 0, 2), 2.0, 2.1));
            PriceSet price_set           = new PriceSet(ToolsPrice.DefaultSymbolGBPUSD, prices.AsReadOnly());
            MarketModelSimulation market = new MarketModelSimulation(initial_cash, commission_per_unit, price_set);

            market.ProcessOrderCommand(new TradingOrderCommand(TradingOrderType.Long, 1.0, 1.0, 0.0, 0.9, 1.6));

            market.StepSecond();
            List <int> open_orders_0 = new List <int>(market.OpenOrders.Keys);

            Assert.AreEqual(1, open_orders_0.Count);
            market.StepSecond();
            List <int> open_orders_1 = new List <int>(market.OpenOrders.Keys);

            Assert.AreEqual(0, open_orders_1.Count);

            Assert.AreEqual(1000.49, market.Cash);
        }
Пример #2
0
        public void TestStep()
        {
            List <Price> prices = new List <Price>();

            prices.Add(new Price(new DateTimeUTC(2000, 1, 1, 0, 0, 0), 1.0, 1.1));
            prices.Add(new Price(new DateTimeUTC(2000, 1, 1, 0, 0, 1), 0.9, 1.0));
            prices.Add(new Price(new DateTimeUTC(2000, 1, 1, 0, 0, 2), 1.1, 1.2));
            PriceSet price_set           = new PriceSet(ToolsPrice.DefaultSymbolGBPUSD, prices.AsReadOnly());
            MarketModelSimulation market = new MarketModelSimulation(1000, price_set);

            Assert.AreEqual(1.0, market.CurrentBid, 0.0000001);
            Assert.AreEqual(1.1, market.CurrentAsk, 0.0000001);
            market.StepSecond();
            Assert.AreEqual(0.9, market.CurrentBid, 0.0000001);
            Assert.AreEqual(1.0, market.CurrentAsk, 0.0000001);
            market.StepSecond();
            Assert.AreEqual(1.1, market.CurrentBid, 0.0000001);
            Assert.AreEqual(1.2, market.CurrentAsk, 0.0000001);
        }
Пример #3
0
        public static DataSet <double, double> CreateDataSet(MarketModelSimulation market, IIndicator feature_indicator, IIndicator label_indicator)
        {
            IList <double[]> feature_data = new List <double[]>();
            IList <bool[]>   missing_data = new List <bool[]>();
            IList <double[]> label_data   = new List <double[]>();

            AddIndicators(market, feature_indicator, label_indicator, feature_data, missing_data, label_data);
            while (market.Second1.FutureCount != 0)
            {
                market.StepSecond();
                AddIndicators(market, feature_indicator, label_indicator, feature_data, missing_data, label_data);
            }

            IDataContext data_context_labeled = new DataContext(DataLevel.INTERVAL, feature_indicator.SubIndicatorNames, DataLevel.INTERVAL, label_indicator.SubIndicatorNames);

            return(new DataSet <double, double>(data_context_labeled, feature_data, missing_data, label_data));
        }
Пример #4
0
        public void ManualCloseLongTest()
        {
            double       initial_cash        = 1000;
            double       commission_per_unit = 0.01;
            List <Price> prices = new List <Price>();

            prices.Add(new Price(new DateTimeUTC(2000, 0, 0, 0, 0, 0), 1.0, 1.1));
            prices.Add(new Price(new DateTimeUTC(2000, 0, 0, 0, 0, 1), 2.0, 2.1));
            PriceSet price_set           = new PriceSet(ToolsPrice.DefaultSymbolGBPUSD, prices.AsReadOnly());
            MarketModelSimulation market = new MarketModelSimulation(initial_cash, commission_per_unit, price_set);

            market.ProcessOrderCommand(new TradingOrderCommand(TradingOrderType.Long, 1.0, 1.0, 0.0));
            market.StepSecond();

            List <int> open_orders = new List <int>(market.OpenOrders.Keys);

            foreach (int open_order in open_orders)
            {
                market.CloseOrder(open_order);
            }
            Assert.AreEqual(1000.89, market.Cash);
        }