Beispiel #1
0
        /// <summary>
        /// Группировка по Дате TestResultRepositiry только для OPT
        /// </summary>
        private TestResultRepositiry GroupDateTestResult(TestResultRepositiry _testResults, int _countBest = 1)
        {
            TestResultRepositiry result = new TestResultRepositiry();
            int counter;

            var _groupRes = from res in _testResults
                            where res.Profit > 0 & StaticService.GetComment(res.Key, Patern3) == "OPT"
                            orderby res.Profit descending
                            group res by res.DateRes into _dateGroup
                            orderby _dateGroup.Key
                            select _dateGroup;

            foreach (var testresults in _groupRes)
            {
                counter = 0;

                if (testresults != null)
                {
                    foreach (ParametrTestResult res in testresults)
                    {
                        result.Add(res);

                        counter++;

                        if (counter >= _countBest)
                        {
                            break;
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Фильтр по SettingsBolinger только для ОПТ
        /// </summary>
        private TestResultRepositiry FiltrBySettingsBB(TestResultRepositiry _testResRepo, string _setBB, out bool _error)
        {
            TestResultRepositiry result = new TestResultRepositiry();

            _error = false;

            try
            {
                foreach (ParametrTestResult item in _testResRepo)
                {
                    if (item != null)
                    {
                        string OPT        = StaticService.GetComment(item.Key, Patern3);
                        string settingsBB = item.SettingsBolinger;

                        if (settingsBB == _setBB && !String.IsNullOrEmpty(OPT))
                        {
                            result.Add(item);
                        }
                    }
                    else
                    {
                        _error = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException + ex.Message);
                return(result);
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Фильтр по ОРТ
        /// </summary>
        private TestResultRepositiry FiltrTestResult(TestResultRepositiry _testResRepo, DateTime _fromDate, DateTime _toDate, out bool _error, bool _opt = true)
        {
            TestResultRepositiry result = new TestResultRepositiry();

            _error = false;

            try
            {
                foreach (ParametrTestResult item in _testResRepo)
                {
                    if (item != null)
                    {
                        string   OPT     = StaticService.GetComment(item.Key, Patern3);
                        DateTime dateRes = Convert.ToDateTime(item.DateRes);

                        if (dateRes >= _fromDate && dateRes <= _toDate)
                        {
                            if (_opt)
                            {
                                if (!String.IsNullOrEmpty(OPT))
                                {
                                    result.Add(item);
                                }
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(OPT))
                                {
                                    result.Add(item);
                                }
                            }
                        }
                    }
                    else
                    {
                        _error = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException + ex.Message);
                return(result);
            }

            return(result);
        }
        /// <summary>
        /// График по SettingsBolinger(X) и CountProfitIndex(Y)
        /// </summary>
        public DataUniversalCharts GetSettingsBBForCharts(TestResultRepositiry _testResRepo)
        {
            DataUniversalCharts result = new DataUniversalCharts();

            var _groupRes = from res in _testResRepo
                            where !String.IsNullOrEmpty(StaticService.GetComment(res.Key, Patern3))
                            group res by res.SettingsBolinger into _paramRes
                            orderby _paramRes.Key
                            select _paramRes;

            foreach (var item in _groupRes)
            {
                string keyX = item.Key;
                double avgY = item.Average(x => x.CountProfitIndex);
                result.Add(keyX, avgY);
            }

            return(result);
        }
Beispiel #5
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);
            }));
        }