Пример #1
0
        public void TestTradesToday()
        {
            //string filename = "today_trades.txt";
            string fileSummary        = "summary.xls";
            string fileVariability    = "variability.txt";
            string fileBrutto         = "brutto.txt";
            string fileBruttoFiltr    = "brutto_filtr.txt";
            string fileBruttoFiltrPro = "brutto_filtr_pro.txt";
            string fileTrades         = "trades.txt";

            MarketTradesRepository   mTR = new MarketTradesRepository();
            TradesBolingerRepository tBR = new TradesBolingerRepository();

            mTR = (MarketTradesRepository)StaticService.Deserializes(mTR.GetType().ToString(), mTR);
            tBR = (TradesBolingerRepository)StaticService.Deserializes("09.11.2016_070008", tBR);

            //for (int i = 3; i <= 3; i++)
            //{
            //    CalculationExtremumPrice(mTR, i, filename);
            //}

            StaticService.DeleteFile(fileSummary);
            StaticService.DeleteFile(fileVariability);
            StaticService.DeleteFile(fileTrades);
            StaticService.DeleteFile(fileBruttoFiltr);
            StaticService.DeleteFile(fileBruttoFiltrPro);
            StaticService.LogFileWriteNotDateTime("Profit sett\tProfit\tCount profit\tCount loss\tCount all", fileSummary, true);

            // оптимизация по профиту
            for (int i = 5; i <= 5; i++)
            {
                CalculationExtremumProfit(mTR, tBR, 5, i, fileSummary, fileTrades, fileVariability, fileBrutto, fileBruttoFiltr, fileBruttoFiltrPro);
            }
        }
Пример #2
0
        /// <summary>
        /// Запуск расчета Болинжера по множеству параметров
        /// </summary>
        private async Task TaskMultiParametrBB(string _path, SettingsClass _sc)
        {
            MarketTradesRepository _marketTrad = (MarketTradesRepository)StaticService.Deserializes(_path);
            List <Task>            tasks       = new List <Task>();

            int    countPeriod = _sc.CountPeriodBB_Start;
            double k_stddev;
            string _fileNameInp = Path.GetFileNameWithoutExtension(_path) + "_";

            for (int i = 0; i < _sc.CountStepPeriod; i++)
            {
                k_stddev = _sc.CountStdDevBB_Start;

                for (int ii = 0; ii < _sc.CountStepStdDev; ii++)
                {
                    Task theTask = CreateRepositoryBolinger(_marketTrad, countPeriod, k_stddev, _fileNameInp);
                    tasks.Add(theTask);

                    k_stddev += _sc.StdDevBBStep;
                }
                countPeriod += _sc.PeriodBBStep;
            }

            await Task.WhenAll(tasks);
        }
Пример #3
0
        /// <summary>
        /// Возвращает данные для графика(прибыли по сделкам). Десериализация сохраненного файла
        /// </summary>
        public TradesProfitCharts GetDataForCharts(string _path)
        {
            TradesProfitCharts   result       = new TradesProfitCharts();
            TestTradesCollection _testTradCol = (TestTradesCollection)StaticService.Deserializes(Directory.GetCurrentDirectory() + _path);

            foreach (ParametrTestTrades _testTrd in _testTradCol)
            {
                result.AddInDictionary(_testTrd.DateTimeTestTrad, _testTrd.ProfitPortfolio);
            }

            return(result);
        }
Пример #4
0
        public async Task TestTradesTodayAsync()
        {
            string _result_test = String.Empty;

            TimeSpan _runTime;
            DateTime _startRun = DateTime.Now;

            decimal otkat    = 30;
            decimal distance = 30;
            decimal profit   = 30;

            List <Task <string> > tasks = new List <Task <string> >();

            MarketTradesRepository mTR = new MarketTradesRepository();

            mTR = (MarketTradesRepository)StaticService.Deserializes(mTR.GetType().ToString(), mTR);

            StaticService.DeleteFile("trade_log.txt");
            StaticService.DeleteFile("equ.txt");

            StaticService.LogFileWriteNotDateTime("EqCurrent\tCountTrades\tCountProfit\tCountLoss\tDrawdown\t_otkat\t_distance\t_profit", "equ.txt", true);

            for (int i = (int)otkat; i <= 200; i += 10)
            {
                for (int ii = i; ii <= 200; ii += 10)
                {
                    for (int iii = i; iii <= 200; iii += 10)
                    {
                        //ExtremumPrice _extPrice2 = new ExtremumPrice();
                        //CalculationExtremumPrice1(mTR, _extPrice2, i, ii, iii, false);

                        Task <string> theTask = TaskCalculation(mTR, i, ii, iii);
                        tasks.Add(theTask);
                    }
                }
            }

            await Task <string> .WhenAll(tasks);

            foreach (Task <string> item in tasks)
            {
                _result_test += item.Result;
            }


            _runTime = DateTime.Now - _startRun;
            StaticService.LogFileWriteNotDateTime(String.Format("{0:00}:{1:00}:{2:00}.{3:000}", _runTime.Hours, _runTime.Minutes, _runTime.Seconds, _runTime.Milliseconds), "runtime.txt", true);

            StaticService.LogFileWriteNotDateTime(_result_test, "equ.txt", true);
        }
Пример #5
0
        /// <summary>
        /// Прогон по единичным параметрам
        /// </summary>
        public ExtremumPrice TestTradesToday1()
        {
            decimal otkat    = 80;
            decimal distance = 190;
            decimal profit   = 170;

            MarketTradesRepository mTR = new MarketTradesRepository();

            mTR = (MarketTradesRepository)StaticService.Deserializes(mTR.GetType().ToString(), mTR);

            StaticService.DeleteFile("trade_log.txt");
            StaticService.DeleteFile("equ.txt");

            return(CalculationExtremumPrice1(mTR, otkat, distance, profit, true));
        }
Пример #6
0
        /// <summary>
        /// Открываем лонги, если цена выше самой верхней линии.
        /// Открываем шорты, если цена ниже самой нижней линии.
        /// Закрытие: переворачиваемся.
        /// </summary>
        private Task TrendAlgoritmTest(string _path)
        {
            return(Task.Run(() =>
            {
                TradesBolingerRepository _trdBRepo = null;
                string file_name = "test_result.txt";
                try
                {
                    _trdBRepo = (TradesBolingerRepository)StaticService.Deserializes(_path);
                }
                catch (Exception)
                {
                    StaticService.LogFileWrite(_path, "error_log.txt", true);
                }

                string _key = Path.GetFileNameWithoutExtension(_path);
                string _dateRes = StaticService.GetComment(_key, SettingsClass.PaternDate1);
                string _settBB = StaticService.GetComment(_key, SettingsClass.Patern);

                TestTradesCollection testTradColl = new TestTradesCollection();
                TestTradesCollection testTradCollOPT = new TestTradesCollection();

                int tp = 0;
                double profitPortfolio = 0; // прибыль портфеля на каждую сделку
                int countTrades = 0;
                double maxProfit = 0;
                double minProfit = 0;
                int countProfitTrades = 0;
                int countLossTrades = 0;

                // OPT
                double profitPortfolioOpt = 0;
                int countTradesOpt = 0;
                double maxProfitOpt = 0;
                double minProfitOpt = 0;
                int countProfitTradesOpt = 0;
                int countLossTradesOpt = 0;
                // end opt

                StaticService.LogFileWrite("\n         ---------" + _key + "---------", file_name, true);

                if (_trdBRepo != null)
                {
                    foreach (ParametrTradesBolinger pcT in _trdBRepo)
                    {
                        //StaticClassService.LogFileWrite(pcT.DateTimeTrades + "\t" + pcT.NumberTrades + "\t" + pcT.PriceTrades + "\t" + pcT.SeccodeTrades + "\t" + pcT.LineUp + "\t" + pcT.LineDown + "\t" + pcT.LineMidl, file_name, true);

                        DateTime dateTimeTrade = pcT.DateTimeTrades;

                        if (dateTimeTrade.TimeOfDay < new TimeSpan(19, 0, 0))
                        {
                            double price = (double)pcT.PriceTrades;

                            //---Здесь вызываем Класс нужного алгоритма---
                            Algoritms.BollingerCrossing.Algoritm(pcT, testTradColl, testTradCollOPT, file_name, price, dateTimeTrade, ref tp, ref countTrades, ref countTradesOpt, ref profitPortfolio, ref profitPortfolioOpt, ref maxProfit, ref maxProfitOpt, ref minProfit, ref minProfitOpt, ref countProfitTrades, ref countProfitTradesOpt, ref countLossTrades, ref countLossTradesOpt);
                            //--------------------------------------------
                        }
                    }
                }

                // save result
                testResultRepo.Add(new ParametrTestResult(_key, _dateRes, _settBB, profitPortfolio, countTrades, maxProfit, minProfit, countProfitTrades, countLossTrades));
                testResultRepo.Add(new ParametrTestResult(_key + "OPT", _dateRes, _settBB, profitPortfolioOpt, countTradesOpt, maxProfitOpt, minProfitOpt, countProfitTradesOpt, countLossTradesOpt)); // Opt

                // serialize TestTradesCollection end TestTradesCollection'OPT'
                StaticService.Serializes(testTradColl, folderOutTestTradesSimple + _key);
                StaticService.Serializes(testTradCollOPT, folderOutTestTradesOPT + _key);
            }));
        }
Пример #7
0
 /// <summary>
 /// Десериализация сохраненных объектов
 /// </summary>
 private void DeserializesObject()
 {
     settingsClass        = (SettingsClass)StaticService.Deserializes(settingsClass.GetType().ToString(), settingsClass);
     testResultRepository = (TestResultRepositiry)StaticService.Deserializes(StaticService.RelativePatchCreate(SettingsClass.TestResult + SettingsClass.FolderSBRF) + "!_actul_result", new TestResultRepositiry());
 }