Beispiel #1
0
        private void UpdatePrcdtl(PriceSet prcset)
        {
            DataRow[] found;
            DataRow   nrow;
            DateTime  date    = Convert.ToDateTime(prcset.prcdate);
            DateTime  current = DateTime.Now;

            foreach (PriceDtl itm in prcset.items)
            {
                found = dt.Select("prodid='" + itm.prodid.ToString() + "'");
                if (found.Length == 0)
                {
                    nrow            = dt.NewRow();
                    nrow["prodid"]  = itm.prodid;
                    nrow["prcdate"] = date;
                    nrow["prcid"]   = prcset.prcid;
                }
                else
                {
                    nrow = found[0];
                }
                nrow["unitprice"]    = itm.unitprice;
                nrow["lastuser"]     = prcset.lastuser;
                nrow["modifieddate"] = current;

                if (found.Length == 0)
                {
                    dt.Rows.Add(nrow);
                }
            }
        }
Beispiel #2
0
        public static void PlotPriceBid(string path, PriceSet price_set)
        {
            PlotLine2D line_plot_2d = new PlotLine2D();

            AddBid(line_plot_2d, price_set);
            ToolsPlotting.WriteToFile(path, line_plot_2d, SIZE_X, SIZE_Y);
        }
 public EvaluatorSingle(IPolicyTemplate policy_template, double initial_cash, PriceSet price_set)
 {
     this.PolicyTemplate = policy_template;
     this.initial_cash   = initial_cash;
     this.price_set      = price_set;
     this.results        = new Dictionary <ParameterSet, double>();
 }
        public void TestCreateSmall()
        {
            //Prices 1.0  0.9, 1.1, 1.2
            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));
            prices.Add(new Price(new DateTimeUTC(2000, 1, 1, 0, 0, 3), 1.2, 1.3));
            PriceSet price_set = new PriceSet(ToolsPrice.DefaultSymbolGBPUSD, prices.AsReadOnly());

            List <IIndicator> indicators_features = new List <IIndicator>();

            indicators_features.Add(new IndicatorRunningAverage(0));
            indicators_features.Add(new IndicatorRunningAverage(1));
            List <IIndicator> indicators_labels = new List <IIndicator>();

            indicators_labels.Add(new IndicatorMagicProfit(0));
            indicators_labels.Add(new IndicatorMagicProfit(1));
            MarketModelSimulation     market  = new MarketModelSimulation(1000, price_set);
            IDataSet <double, double> dataset = ToolsTradingDataSet.CreateDataSet(market, new IndicatorFusion(indicators_features), new IndicatorFusion(indicators_labels));

            Assert.AreEqual(0.90, dataset.FeatureData[0][0], 0.0000001);
            Assert.AreEqual(0.95, dataset.FeatureData[0][1], 0.0000001);
            Assert.AreEqual(1.10, dataset.FeatureData[1][0], 0.0000001);
            Assert.AreEqual(1.00, dataset.FeatureData[1][1], 0.0000001);
            Assert.AreEqual(-0.1, dataset.LabelData[0][0], 0.0000001);
            Assert.AreEqual(-0.1, dataset.LabelData[0][1], 0.0000001);
            Assert.AreEqual(0.10, dataset.LabelData[0][2], 0.0000001);
            Assert.AreEqual(-0.1, dataset.LabelData[0][3], 0.0000001);
            Assert.AreEqual(-0.1, dataset.LabelData[1][0], 0.0000001);
            Assert.AreEqual(-0.1, dataset.LabelData[1][1], 0.0000001);
            Assert.AreEqual(0.0, dataset.LabelData[1][2], 0.0000001);
            Assert.AreEqual(0.0, dataset.LabelData[1][3], 0.0000001);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public PriceSet GetPrices(TradingSymbol symbol, int year, int month)
        {
            int    price_set_index     = GetPriceSetIndex(year, month);
            string price_set_file_path = GetPriceSetFilePath(symbol, year, month);

            if (!data_loaded.ContainsKey(symbol))
            {
                data_loaded[symbol] = new Dictionary <int, PriceSet>();
            }

            if (data_loaded[symbol].ContainsKey(price_set_index))
            {
                return(data_loaded[symbol][price_set_index]);
            }
            else
            {
                if (File.Exists(price_set_file_path))
                {
                    data_loaded[symbol][price_set_index] = PriceSet.Read(new BinaryReader(File.Open(price_set_file_path, FileMode.Open)));
                }
                else
                {
                    data_loaded[symbol][price_set_index] = new PriceSet(symbol, new DateTimeUTC(year, month, 1), new DateTimeUTC(year, month + 1, 1));
                }


                return(data_loaded[symbol][price_set_index]);
            }
        }
Beispiel #7
0
        public static void PlotIndicatorResult(string path, PriceSet price_set, IIndicator indicator, IList <Color> color_list, IList <int> selected_subindicators, bool plot_bid = true)
        {
            PlotLine2D line_plot_2d = new PlotLine2D();

            AddIndicatorResult(line_plot_2d, price_set, indicator, color_list, selected_subindicators);
            if (plot_bid)
            {
                AddBid(line_plot_2d, price_set);
            }
            ToolsPlotting.WriteToFile(path, line_plot_2d, SIZE_X, SIZE_Y);
        }
Beispiel #8
0
 public static void AddPrice(PlotLine2D line_plot_2d, PriceSet price_set, TimeScale time_scale, PriceType price_type, Color color)
 {
     if (time_scale == TimeScale.Spot)
     {
         AddPriceSpot(line_plot_2d, price_set, price_type, color);
     }
     else
     {
         AddPriceCandle(line_plot_2d, price_set, time_scale, price_type, color);
     }
 }
Beispiel #9
0
        public PriceSet GetPrices(TradingSymbol symbol, DateTimeUTC lower_inclusive, DateTimeUTC upper_exclusive)
        {
            List <PriceSet> month_price_set_list = new List <PriceSet>();
            //Move through months
            DateTimeUTC initial_month = new DateTimeUTC(lower_inclusive.Year, lower_inclusive.Month, 1);
            int         year          = 0;
            int         month         = 0;
            PriceSet    price_set     = GetPrices(symbol, year, month);

            return(new PriceSet(month_price_set_list));// new PriceSet(List<PriceSet> month_price_set_list)
        }
Beispiel #10
0
        public static void AddPriceCandle(PlotLine2D line_plot_2d, PriceSet price_set, TimeScale time_scale, PriceType price_type, Color color)
        {
            IReadOnlyList <PriceCandle> candles = price_set.GetCandles(time_scale);
            IReadOnlyList <double>      time    = price_set.Ticks;

            double[] signal = new double[candles.Count];
            Parallel.For(0, candles.Count, index =>
            {
                signal[index] = candles[index].GetPrice(price_type);
            });
            AddSignal(line_plot_2d, time, signal, color);
        }
Beispiel #11
0
        public static void AddPriceSpot(PlotLine2D line_plot_2d, PriceSet price_set, PriceType price_type, Color color)
        {
            IReadOnlyList <Price>  prices = price_set.Prices;
            IReadOnlyList <double> time   = price_set.Ticks;

            double[] signal = new double[prices.Count];
            Parallel.For(0, prices.Count, index =>
            {
                signal[index] = prices[index].GetPrice(price_type);
            });
            AddSignal(line_plot_2d, time, signal, color);
        }
Beispiel #12
0
        public static void PlotIndicatorResult(string path, PriceSet price_set, IIndicator indicator)
        {
            IList <Color> color_list = new List <Color>();

            IList <int> indicator_list = new List <int>();

            for (int index = 0; index < indicator.SubIndicatorCount; index++)
            {
                color_list.Add(Color.Black);
                indicator_list.Add(index);
            }
            PlotIndicatorResult(path, price_set, indicator, color_list, indicator_list);
        }
Beispiel #13
0
        public void DoExperiment()
        {
            PriceSet       price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolUSDEUR);
            List <IPolicy> policies  = new List <IPolicy>();

            for (int index_0 = 2; index_0 < 10; index_0++)
            {
                policies.Add(new PolicyRunLength(index_0, 300));
            }

            ExperimentPolicies experiment = new ExperimentPolicies(price_set, policies);

            experiment.DoExperiment();
        }
        public static void TestSpeed(double initial_cash, PriceSet price_set, int count)
        {
            List <PolicyJaapBands> policies = new List <PolicyJaapBands>();

            for (int i = 0; i < count; i++)
            {
                policies.Add(new PolicyJaapBands(300, 0.85, 50, 0.015, 150, 130));
            }
            MarketResult[] market_results = new MarketResult[policies.Count];
            Parallel.For(0, policies.Count, index =>
            {
                MarketManagerSimulation exchange = new MarketManagerSimulation(10000, price_set);
                market_results[index]            = exchange.Run(policies[index]);
            });
            Assert.AreEqual(10230.0, market_results[0].EndCash, 0.0000001);
        }
Beispiel #15
0
        public void DoExperiment()
        {
            PriceSet           price_set       = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD).SubSet(new DateTimeUTC(2016, 10, 17), new DateTimeUTC(2016, 10, 20));
            IPolicyTemplate    policy_template = new PolicyTemplateRunningAverageDual();
            double             initial_cash    = 10000;
            IEvaluator         evaluator       = new EvaluatorSingle(policy_template, initial_cash, price_set);
            ParameterSpaceGrid search_grid     = new ParameterSpaceGrid(
                policy_template.DefaultParameters,
                new double[] { 10, 5 * TradingConstants.POINT, 10, 5 * TradingConstants.POINT },
                new int[] { 1, 1, 1, 1 },
                new int[] { 1, 1, 1, 1 }
                );
            IOptimizer         optimizer = new OptimizerExaustive(search_grid, evaluator);
            OptimizationResult result    = optimizer.Optimize(policy_template.DefaultParameters);

            Console.WriteLine(result.OptimalResult);
        }
        public void DoExperiment()
        {
            IPolicyTemplate    policy_template = new PolicyTemplateJaapBands();
            double             initial_cash    = 10000;
            PriceSet           price_set       = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD);
            IEvaluator         evaluator       = new EvaluatorSingle(policy_template, initial_cash, price_set);
            ParameterSpaceGrid search_grid     = new ParameterSpaceGrid(
                policy_template.DefaultParameters,
                new double[] { },
                new int[] { },
                new int[] { }
                );
            IOptimizer         optimizer = new OptimizerExaustive(search_grid, evaluator);
            OptimizationResult result    = optimizer.Optimize(policy_template.DefaultParameters);

            Console.WriteLine(result.OptimalResult);
        }
Beispiel #17
0
        public JsonResult SavePriceSet([FromBody] PriceSet prcset)
        {
            string msg = "";

            if (!CSys.OpenCon(ref con))
            {
                JsonResult errjson = Json(new
                {
                    ok    = "no",
                    Error = "connection error."
                });
                return(errjson);
            }


            // BaseADOPG.ExceuteSql("Delete from from prcdtl where where prcdate='" + prcset.prcdate + "' and prcid='" + prcset.prcid + "'", con, sqlTrans);
            dt = BaseADOPG.GetData("Select * from prcdtl where prcdate='" + prcset.prcdate + "' and prcid='" + prcset.prcid + "'");

            UpdatePrcdtl(prcset);
            bool success = false;
            NpgsqlTransaction sqlTrans;

            sqlTrans = con.BeginTransaction();
            CAdapter.GeneratePrcDtlCommand(ref da);
            if (UpdateTable(ref dt, sqlTrans))
            {
                sqlTrans.Commit();
                success = true;
                msg     = "Saved successfully";
            }
            else
            {
                sqlTrans.Rollback();
                msg = _err;
            }

            JsonResult restultJson = Json(new
            {
                ok    = (success) ? "yes" : "no",
                Error = msg
            });

            con.Close();
            return(restultJson);
        }
        public void TestCreateMedium()
        {
            PriceSet          price_set           = new PriceSet(ToolsPrice.DefaultSymbolGBPUSD, ToolsCollection.Select(ToolsPrice.GetPriceList(ToolsPrice.DefaultSymbolGBPUSD), 0, 40));
            List <IIndicator> indicators_features = new List <IIndicator>();

            indicators_features.Add(new IndicatorRunningAverage(0));
            indicators_features.Add(new IndicatorRunningAverage(1));
            List <IIndicator> indicators_labels = new List <IIndicator>();

            indicators_labels.Add(new IndicatorMagicProfit(0));
            indicators_labels.Add(new IndicatorMagicProfit(1));
            MarketModelSimulation     market  = new MarketModelSimulation(1000, price_set);
            IDataSet <double, double> dataset = ToolsTradingDataSet.CreateDataSet(market, new IndicatorFusion(indicators_features), new IndicatorFusion(indicators_labels));

            Assert.AreEqual(39, dataset.InstanceCount);
            Assert.AreEqual(2, dataset.FeatureCount);
            Assert.AreEqual(4, dataset.LabelCount);
        }
Beispiel #19
0
        public static void AddIndicatorResult(PlotLine2D line_plot_2d, PriceSet price_set, IIndicator indicator, IList <Color> color_list, IList <int> selected_subindicators)
        {
            MarketModelSimulation market = new MarketModelSimulation(10000, price_set);

            double[] time = new double[price_set.Prices.Count];
            for (int price_index = 0; price_index < price_set.Prices.Count; price_index++)
            {
                time[price_index] = price_set.Prices[price_index].Time.Ticks;
            }
            Tuple <double[, ], bool[]> tuple      = indicator.ComputeAll(market, price_set.Second1.Count);
            List <IList <int> >        selections = CreateSections(tuple.Item2);

            for (int index = 0; index < selected_subindicators.Count; index++)
            {
                double[] signal = tuple.Item1.Select1DIndex1(selected_subindicators[index]);
                AddSignal(line_plot_2d, time, signal, selections, color_list[index]);
            }
        }
Beispiel #20
0
        public static PriceSet GetPriceSet(TradingSymbol trading_symbol)
        {
            string data_path = Path.Combine(binary_data_root_path, trading_symbol.Broker, trading_symbol.Account, trading_symbol.Symbol);

            if (!Directory.Exists(data_path))
            {
                throw new Exception("No data for trading symbol: " + trading_symbol);
            }
            string[] files = Directory.GetFiles(data_path);
            if (files.Length != 1)
            {
                throw new Exception("No unique data for trading symbol: " + trading_symbol);
            }

            using (BinaryReader reader = new BinaryReader(new FileStream(files[0], FileMode.Open)))
            {
                return(PriceSet.Read(reader));
            }
        }
Beispiel #21
0
        public void DoExperiment()
        {
            PriceSet       price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolUSDEUR);
            List <IPolicy> policies  = new List <IPolicy>();

            for (int index_0 = 1; index_0 < 10; index_0++)
            {
                for (int index_1 = 1; index_1 < 10; index_1++)
                {
                    policies.Add(new PolicyRunningAverageDual(
                                     index_0 * 30, index_1 * 5 * TradingConstants.POINT,
                                     index_0 * 30, index_1 * -5 * TradingConstants.POINT));
                }
            }

            ExperimentPolicies experiment = new ExperimentPolicies(price_set, policies);

            experiment.DoExperiment();
        }
Beispiel #22
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);
        }
Beispiel #23
0
        internal void DoExperiment()
        {
            ToolsPrice.ComposeBinary(ToolsPrice.DefaultSymbolGBPUSD);
            PriceSet price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD).SubSet(new DateTimeUTC(2016, 10, 17), new DateTimeUTC(2016, 10, 20));

            //PlotLine2D line_plot_2d_0 = new PlotLine2D();
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Spot, PriceType.Bid, Color.Blue);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Spot, PriceType.Mean, Color.Green);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Spot, PriceType.Ask, Color.Red);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Day1, PriceType.Bid, Color.Black);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Day1, PriceType.Mean, Color.Green);
            //ToolsTradingPlotting.AddPrice(line_plot_2d_0, price_set, TimeScale.Day1, PriceType.Ask, Color.Red);
            //ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot0.png", line_plot_2d_0);

            IIndicator indicator      = new IndicatorMagicProfit(60);
            PlotLine2D line_plot_2d_1 = new PlotLine2D();

            ToolsTradingPlotting.AddIndicatorResult(line_plot_2d_1, price_set, indicator, new Color[] { Color.Red, Color.Green }, new int[] { 0, 1 });
            ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot3.png", line_plot_2d_1);



            //ToolsTradingPlotting.PlotPriceBid(ToolsTradingDataSet.GetPath() + "prices.png", prices);
            //ToolsTradingPlotting.PlotIndicatorResult(ToolsTradingDataSet.GetPath() + "indicator_0.png", prices, indicator_0, color_list, index_list, true);
            //ToolsTradingPlotting.PlotIndicatorResult(ToolsTradingDataSet.GetPath() + "indicator_1.png", prices, indicator_1, color_list, index_list, true);


            //IPolicyTemplate policy = new PolicyTemplateJaapBands();
            //MarketManagerSimulation exchange = new MarketManagerSimulation(10000, price_set);
            //MarketResult market_result = exchange.Run(policy.Instance());
            //Console.WriteLine(market_result.EndCash + " in: " + market_result.Market.ClosedOrders.Count);

            //PlotLine2D line_plot_2d_0 = new PlotLine2D();
            //ToolsTradingPlotting.AddBidAskTrades(line_plot_2d_0, market_result);
            //ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot0.png", line_plot_2d_0);


            //PlotLine2D line_plot_2d_1 = new PlotLine2D();
            //ToolsTradingPlotting.AddCashEquity(line_plot_2d_1, market_result);
            //ToolsTradingPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "TestPlot1.png", line_plot_2d_1);
        }
Beispiel #24
0
        public void ManualCloseShortTest()
        {
            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.Short, 1.0, 1.0, 0.0));
            List <int> open_orders = new List <int>(market.OpenOrders.Keys);

            foreach (int open_order in open_orders)
            {
                market.CloseOrder(open_order);
            }
            Assert.AreEqual(998.89, market.Cash);
        }
Beispiel #25
0
        public static void ComposeBinary(TradingSymbol trading_symbol)
        {
            string source_data_path = Path.Combine(source_data_root_path, trading_symbol.Broker, trading_symbol.Account, trading_symbol.Symbol);
            string target_data_path = Path.Combine(binary_data_root_path, trading_symbol.Broker, trading_symbol.Account, trading_symbol.Symbol);

            if (!Directory.Exists(source_data_path))
            {
                throw new Exception("No data for trading symbol: " + trading_symbol);
            }
            string[] files = Directory.GetFiles(source_data_path);
            if (files.Length == 0)
            {
                throw new Exception("No data for trading symbol: " + trading_symbol);
            }
            Array.Sort(files);

            List <Price> price_list = new List <Price>();

            foreach (string file in files)
            {
                AddFileToPriceList(price_list, file);
            }
            PriceSet    price_set       = new PriceSet(ToolsPrice.DefaultSymbolGBPUSD, price_list);
            DateTimeUTC date_time_first = price_set.OpenDateTime;
            DateTimeUTC date_time_last  = price_set.CloseDateTime;

            target_data_path = Path.Combine(target_data_path, date_time_first.ToString("yyyyMMddHHmmss") + "_" + date_time_last.ToString("yyyyMMddHHmmss") + ".blb");

            string target_data_path_dir = Path.GetDirectoryName(target_data_path);

            if (!Directory.Exists(target_data_path_dir))
            {
                Directory.CreateDirectory(target_data_path_dir);
            }

            using (BinaryWriter writer = new BinaryWriter(new FileStream(target_data_path, FileMode.Create)))
            {
                price_set.Write(writer);
            }
        }
        public void DoExperiment()
        {
            PriceSet          price_set  = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD);
            List <IIndicator> indicators = new List <IIndicator>();

            indicators.Add(new IndicatorRunningAverage(4));
            indicators.Add(new IndicatorRunningAverage(6));
            indicators.Add(new IndicatorRunningAverage(8));
            indicators.Add(new IndicatorRunningAverage(10));
            indicators.Add(new IndicatorRunningAverage(12));
            IIndicator feature_indicator = new IndicatorFusion(indicators);
            IIndicator label_indicator   = new IndicatorMagicProfit(60);



            MarketModelSimulation                market   = new MarketModelSimulation(1000, price_set);
            DataSet <double, double>             dataset  = ToolsTradingDataSet.CreateDataSet(market, feature_indicator, label_indicator);
            ITemplateModelLabel <double, double> template = null;//new TemplateModelLibSVMCSVC();
            IModelLabel <double, double>         model    = template.GenerateModel(dataset);

            //TODO change everyting into templates
            List <IIndicator> indicators_2 = new List <IIndicator>();

            indicators_2.Add(new IndicatorRunningAverage(4));
            indicators_2.Add(new IndicatorRunningAverage(6));
            indicators_2.Add(new IndicatorRunningAverage(8));
            indicators_2.Add(new IndicatorRunningAverage(10));
            indicators_2.Add(new IndicatorRunningAverage(12));
            IIndicator feature_indicator_2 = new IndicatorFusion(indicators_2);

            //Build actual incator

            IIndicator    indicator_0 = new IndicatorMagicProfit(60);
            IIndicator    indicator_1 = new IndicatorMachineLearning(feature_indicator_2, model, "Profit_long_ml");
            IList <Color> color_list  = new Color[] { Color.Black };
            IList <int>   index_list  = new int[] { 0 };

            ToolsTradingPlotting.PlotIndicatorResult(ToolsTradingDataSet.GetPath() + "indicator_0.png", price_set, indicator_0, color_list, index_list, false);
            ToolsTradingPlotting.PlotIndicatorResult(ToolsTradingDataSet.GetPath() + "indicator_1.png", price_set, indicator_1, color_list, index_list, false);
        }
Beispiel #27
0
        private void UpdateSecondData()
        {
            string[] dump_directories = Directory.GetDirectories(dump_path);
            //foreach (string dump_directory in dump_directories)
            //{


            //Dictionary<TradingSymbol, List<PriceSet>> data_read = new Dictionary<TradingSymbol, List<PriceSet>>();
            foreach (string dump_directory_name in dump_directories)
            {
                string[] dump_file_names = Directory.GetFiles(dump_directory_name);
                foreach (string dump_file_name in dump_file_names)
                {
                    if (!dump_file_name.Equals("desktop.ini"))
                    {
                        string symbol = Path.GetFileName(dump_file_name).Substring(0, 6);
                        if (symbol.Equals("EURUSD"))
                        {
                            Console.WriteLine("Reading" + dump_file_name);
                            PriceSet new_prices_set = ImportSecondData(dump_file_name);
                            Console.WriteLine("prices_set" + new_prices_set);


                            //TODO for each month in price set
                            IList <DateTimeUTC> month_date_list = CreateMonthRange(new_prices_set.OpenDateTime, new_prices_set.CloseDateTime);
                            foreach (DateTimeUTC month_date in month_date_list)
                            {
                                int year  = new_prices_set.OpenDateTime.Year;
                                int month = new_prices_set.OpenDateTime.Month;

                                PriceSet prices_set = GetPrices(new_prices_set.Symbol, year, month);
                                prices_set.UpdatePrices(new_prices_set);
                            }
                        }
                    }
                }
            }
            SaveAllPrices();
        }
Beispiel #28
0
        public void DoExperiment()
        {
            PriceSet price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD);

            List <IPolicy> policies        = new List <IPolicy>();
            double         long_threshold  = 10 * Math.Pow(10, -6);
            double         short_threshold = -10 * Math.Pow(10, -6);

            for (int index = 0; index < 1; index++)
            {
                policies.Add(new PolicyTemplateJaapBands().Instance());
            }

            MarketResult[] market_results = new MarketResult[policies.Count];

            Parallel.For(0, policies.Count, index =>
            {
                MarketManagerSimulation exchange = new MarketManagerSimulation(10000, price_set);
                market_results[index]            = exchange.Run(policies[index]);
            });

            List <Tuple <MarketResult, IPolicy> > accepted_policy = new List <Tuple <MarketResult, IPolicy> >();

            for (int index = 0; index < market_results.Length; index++)
            {
                //    if(market_results[index].Market.ClosedOrders.Count > 9 && market_results[index].EndCash > 10000)
                //    {
                accepted_policy.Add(new Tuple <MarketResult, IPolicy>(market_results[index], policies[index]));
                //    }
            }

            for (int index = 0; index < accepted_policy.Count; index++)
            {
                var xx = accepted_policy[index];
                Console.WriteLine(xx.Item1.EndCash + " in: " + xx.Item1.Market.ClosedOrders.Count);
                ToolsTradingPlotting.PlotMarketResult(ToolsTradingDataSet.GetPath() + "Trades" + index + ".png", xx.Item1);
            }
        }
        public void DoExperiment()
        {
            ToolsPrice.ComposeBinary(ToolsPrice.DefaultSymbolGBPUSD);
            PriceSet price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD).SubSet(new DateTimeUTC(2016, 10, 17), new DateTimeUTC(2016, 10, 20));


            IIndicator            indicator_feature = new IndicatorSuperBollinger();
            IIndicator            indicator_label   = new IndicatorMagicProfit(60);
            MarketModelSimulation market0           = new MarketModelSimulation(10000, price_set);
            MarketModelSimulation market1           = new MarketModelSimulation(10000, price_set);

            double[] time = new double[price_set.Prices.Count];
            for (int price_index = 0; price_index < price_set.Prices.Count; price_index++)
            {
                time[price_index] = price_set.Prices[price_index].Time.Ticks;
            }

            Tuple <double[, ], bool[]> tuple0 = indicator_feature.ComputeAll(market0, price_set.Second1.Count);
            Tuple <double[, ], bool[]> tuple1 = indicator_label.ComputeAll(market1, price_set.Second1.Count);

            List <string[]> list_string = new List <string[]>();

            for (int index_0 = 0; index_0 < tuple0.Item2.Length; index_0++)
            {
                if (tuple0.Item2[index_0] && tuple1.Item2[index_0])
                {
                    double[] array_double = ToolsCollection.Append(tuple0.Item1.Select1DIndex0(index_0), tuple1.Item1.Select1DIndex0(index_0));
                    string[] array_string = new string[array_double.Length];
                    for (int index_1 = 0; index_1 < array_double.Length; index_1++)
                    {
                        array_string[index_1] = array_double[index_1].ToString(CultureInfo.InvariantCulture);
                    }
                    list_string.Add(array_string);
                }
            }

            ToolsIOCSV.WriteCSVFile(ToolsTradingDataSet.GetPath() + "data.csv", ToolsCollection.ConvertToArray2D(list_string));
        }
Beispiel #30
0
        public void TestSim40()
        {
            PriceSet price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD);

            IMarketModelTest.TestSpeed(10000, price_set, 40);
        }