public override void Run() { //creo il file per l'esecuzione corrente var filename = string.Format(@"log\{0}_{1}.txt", "Test2", DateTime.Now.ToString("ddMMyyyy_hhmm")); // System.IO.File.Create(filename); //apro lo stream writer // using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"..\..\log\mtgoxcandlesMonth-15m", true)) { //lettura delle configurazioni var configuration = new ConfigurationHoldAndBuy() { Gain = (decimal)0.05, // 1% //HeartBeat = (decimal)0.001, // 1m MaxBubbles = 1, //(j+1), MaxCoinsPerBubble = (decimal)(0.6), MinimumCoinsPerBubble = (decimal)0.01, //MaxMoney = 100, //Tick = 1, //w+1, //TickDynamic = false }; //parametri MACD var arr = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var param = from i in arr from j in arr from k in arr select new { i, j, k }; //iterazione lungo i parametri param.ToList().ForEach(p => { //generazione del market var market = new CMarketSimulator(); //(15, 17, 12 + p.i, 20 + p.j, 5 + p.k); //istanzio il manager var manager = new Manager.CManagerHoldBuy() { ConfigurationHoldAndBuy = configuration, Market = market };//(configuration, market, true); //lancio il test // salvo il risultato var test = new TestUnit() { Bubbles = configuration.MaxBubbles, Coins = market.TotCoins, Money = market.TotMoney, Gain = configuration.Gain, Maxcoinsperbubble = configuration.MaxCoinsPerBubble, Coinvalue = market.Bid, //Ticks = configuration.Tick, Value = market.TotValue, Average = market.Average, i = p.i, j = p.j, //w=w, k = p.k }; //stampo il test CUtility.Log("*** TEST"); // test.PrintOnFile(sw); //test.PrintOnConsole(); test.Print(); }); } }
public override void Run() { var tests = new List <TestUnit>(); var testResultFileName = @"data\output\results" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".csv"; //TODO: caricare da configurazioni var testLoad = GetTestData(); //List<TestParam> testLoad = null; if (testLoad == null || testLoad.Count == 0) { testLoad = new List <TestParam>() { new TestParam(0, 0, 0, 0) }; } var e = Evaluations.EvaluationManager.Instance; foreach (var testParam in testLoad) { e.Clear(); /******************************************************************** * CONFIGURAZIONE *******************************************************************/ //MainConfiguration.Configuration = new Configuration(); //configuration; // MainConfiguration.Configuration = Configuration.BuildFromFile("global.json", "personal.json"); MainConfiguration.Configuration = Configuration.BuildFromDirectory(@"data/configuration"); MainConfiguration.Configuration.Init(); Configuration.SaveToFile(MainConfiguration.Configuration, @"data/configuration/serialized.result.json"); // chiama la configurazione Customize(testParam); /******************************************************************** * MANAGER *******************************************************************/ var manager = Manager.Builder.Create(MainConfiguration.Configuration.ManagerClass); if (manager == null) { throw new Exception("manager not configured"); } manager.Start(); if (MainConfiguration.Configuration.RealTimeHeartBeat && testLoad.Count == 1) { break; } System.Console.WriteLine(manager.Market.UniqueName); // salvo il risultato var test = new TestUnit() { Coins = manager.Market.TotCoins, Money = manager.Market.TotMoney, Coinvalue = manager.Market.Buy, Value = manager.Market.TotValue, Average = manager.Market.Average, MaxCoins = manager.Market.MaxCoins, MaxMoney = manager.Market.MaxMoney, MaxValue = manager.Market.MaxValue, Bids = manager.Market.TotBids, Ask = manager.Market.TotAsks, Gain = manager.Statistics.Gain, i = testParam.I, j = testParam.J, w = testParam.W, k = testParam.K }; /******************************************************************** * VISUALIZZAZIONE *******************************************************************/ // stampa il risultato test.Print(); if (test.Average > MainConfiguration.Configuration.StartWalletMoney) // deve esserci stato almeno un trade { if (test.Value > MainConfiguration.Configuration.StartWalletMoney) // devo aver guadagnato piu' di quanto ho investito { // salva il risultato se ci sono stati risultati incoraggianti CUtility.Log("*** GOOD"); tests.Add(test); /* * // scrive il risultato su csv * using (var log = new StreamWriter(testResultFileName, true)) * { * test.Print(log); * log.Flush(); * log.Close(); * } * */ // scrive il risultato con codice using (var log = new StreamWriter(testResultFileName + ".txt", true)) { test.PrintCode(log); log.Flush(); log.Close(); } // salvo la migliore configurazione var best = tests.OrderByDescending(o => o.Coins * o.Coinvalue + o.Money).FirstOrDefault(); if (best != null) { Configuration.SaveToFile(MainConfiguration.Configuration, @"data/configuration/best.result.json"); } var bestAvg = tests.OrderByDescending(o => o.Average).FirstOrDefault(); if (bestAvg != null) { Configuration.SaveToFile(MainConfiguration.Configuration, @"data/configuration/bestavg.result.json"); } } } AnalyticsTools.Print(); e.Finalize(); } /******************************************************************** * RISULTATI *******************************************************************/ if (MainConfiguration.Configuration.RealTimeHeartBeat && testLoad.Count == 1) { } else { // mostro la performance migliore CUtility.Log("*** BEST VALUE"); var firstOrDefault = tests.OrderByDescending(o => o.Coins * o.Coinvalue + o.Money).FirstOrDefault(); if (firstOrDefault != null) { firstOrDefault.Print(); } CUtility.Log("*** BEST AVERAGE"); var orDefault = tests.OrderByDescending(o => o.Average).FirstOrDefault(); if (orDefault != null) { orDefault.Print(); } } }