public void DoExperiment() { List <PriceCandle> all_data = ToolsPrice.GetPriceCandles(); // new DateTime(2016, 9, 3) PlotLine2D line_plot_2d = new PlotLine2D(); for (int month_index = 1; month_index < 9; month_index++) { DateTimeUTC nfp_date = null;// ToolsTradingCalendarEvent.GetNFPDatetime(2016, month_index); DateTimeUTC nfp_date_begin = nfp_date.AddMinutes(-100); DateTimeUTC nfp_date_end = nfp_date.AddMinutes(100); List <double> nfp_time = new List <double>(); List <double> nfp_bid = new List <double>(); double candle_time = 0; double subtract = 0; foreach (PriceCandle candle in all_data) { if ((nfp_date_begin <= candle.OpenTime) && (candle.OpenTime < nfp_date_end)) { if (candle_time == 0) { subtract = candle.OpenBid; } nfp_time.Add(candle_time); nfp_time.Add(candle_time); nfp_time.Add(candle_time); nfp_time.Add(candle_time); nfp_bid.Add(candle.OpenBid); nfp_bid.Add(candle.LowBid); nfp_bid.Add(candle.HighBid); nfp_bid.Add(candle.CloseBid); candle_time++; } } line_plot_2d.AddSeries(nfp_time, nfp_bid, Color.Black); } ToolsPlotting.WriteToFile(ToolsTradingDataSet.GetPath() + "nfp.png", line_plot_2d, 800, 800); }
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); }
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); }
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)); }
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); } }
private static void CreateEventCSV() { // read CSV string[,] source = ToolsIOCSV.ReadCSVFile(ToolsTradingDataSet.GetPath() + "events.csv", Delimiter.SemiColon); //Allocate new array List <string[]> result_list = new List <string[]>(); string[] exclusion = new string[] { "day", "Day", "Data" }; //For each other column for (int index_0 = 0; index_0 < source.GetLength(0); index_0++) { if (!ExtensionsString.ContainsAny(source[index_0, 2], exclusion)) { string[] result = new string[3]; // Date symbol impact //Find dat DateTime week_start = DateTime.Parse(source[index_0, 0]); int year = week_start.Year; int month = ToolsForexFactory.MonthToInt(source[index_0, 1].Split(' ')[0]); int day = int.Parse(source[index_0, 1].Split(' ')[1]); if ((week_start.Month == 12) && (month == 1)) { year++; } int hour = int.Parse(source[index_0, 2].Split(':')[0]); int minute = int.Parse(source[index_0, 2].Split(':')[1].Substring(0, 2)); if (source[index_0, 2].Contains("pm")) { hour = hour + 12; } if (hour == 24) { hour = 0; DateTime date_time = new DateTime(year, month, day, hour, minute, 0); date_time = date_time.AddDays(1); result[0] = ToolsTime.DateTimeToUnixTimestampInt32(date_time).ToString(); } else { DateTime date_time = new DateTime(year, month, day, hour, minute, 0); result[0] = ToolsTime.DateTimeToUnixTimestampInt32(date_time).ToString(); } result[1] = source[index_0, 3]; switch (source[index_0, 4]) { case "Non-Economic": result[2] = "0"; // Impacs break; case "Low Impact Expected": result[2] = "1"; // Impacs break; case "Medium Impact Expected": result[2] = "2"; // Impacs break; case "High Impact Expected": result[2] = "3"; // Impacs break; default: throw new Exception("Unknown impact"); } result_list.Add(result); } } ToolsIOCSV.WriteCSVFile(ToolsTradingDataSet.GetPath() + "events_small.csv", ToolsCollection.ConvertToArray2D(result_list)); }