Exemplo n.º 1
0
        /// <summary>
        /// Через какое количество последовательных прибылей/убытков происходит смена
        /// </summary>
        private void VariablityCalc(decimal _brutto, string _filename, ref int _variability)
        {
            if (Math.Sign(_brutto) != Math.Sign(_variability) & _variability != 0)
            {
                StaticService.LogFileWriteNotDateTime(_variability.ToString(), _filename, true);
                if (_brutto > 0)
                {
                    _variability = 1;
                    return;
                }
                else
                {
                    _variability = -1;
                    return;
                }
            }

            if ((_brutto > 0 && _variability > 0) | (_brutto > 0 && _variability == 0))
            {
                _variability++;
                return;
            }
            if ((_brutto < 0 && _variability < 0) | (_brutto < 0 && _variability == 0))
            {
                _variability--;
                return;
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        // Просто по экстремумам
        private void CalculationExtremumPrice(MarketTradesRepository _mTR, decimal _otkat, string _filename)
        {
            ExtremumPrice extPrice = new ExtremumPrice();

            decimal exchange_fee         = 0.47m; // биржевой сбор SBRF 0.47
            decimal brokerage_commission = 0.59m; // комиссия брокера 0.59
            decimal spred = 3m;

            // находим екстремумы
            extPrice.CreateExtrem(_mTR, _otkat);
            //StaticService.LogFileWrite("----------------Extremums--------------------", _filename, true);
            //foreach (var item in extPrice.Extremums)
            //{
            //    StaticService.LogFileWriteNotDateTime(item.Date_Time + "\t" + item.PriceHigh + "\t" + item.PriceLow, _filename, true);
            //}

            // считаем между ними дельту
            //StaticService.LogFileWrite("\n", filename, true);
            //StaticService.LogFileWriteNotDateTime("----------------считаем между ними дельту--------------------", _filename, true);
            extPrice.DeltaExtr();
            foreach (var item in extPrice.DeltaExtremums)
            {
                StaticService.LogFileWriteNotDateTime(Math.Abs(item).ToString(), "delta_log.txt", true);
            }

            StaticService.LogFileWriteNotDateTime("****************ОТКАТ <" + _otkat + ">****************", _filename, true);

            //&??????????????????
            for (decimal i = _otkat * 2; i <= _otkat * 8; i++)
            {
                decimal criticalSum = 0;

                // фильтруeм дельты
                StaticService.LogFileWriteNotDateTime("----------------фильтруeм дельты <" + i + ">--------------------", _filename, true);
                extPrice.FiltrDelta(i);
                foreach (var item in extPrice.FiltrDeltas)
                {
                    StaticService.LogFileWriteNotDateTime(Math.Abs(item).ToString(), _filename, true);

                    criticalSum += Math.Abs(item) - (_otkat * 2 + TransactionCosts(exchange_fee, brokerage_commission, spred) * 2);
                }
                StaticService.LogFileWriteNotDateTime(criticalSum.ToString(), _filename, true);
            }
        }
Exemplo n.º 5
0
        //-------------------------------------------


        //
        private void CalculationExtremumProfit(MarketTradesRepository _mTR, TradesBolingerRepository _tBR, decimal _otkat, decimal _profit, string _fileSummary, string _fileTrades, string _filevariability, string _fileBrutto, string _fileBruttoFiltr, string _fileBruttoFiltrPro)
        {
            ExtremumProfit  extPrice  = new ExtremumProfit();
            Queue <decimal> BruttoQue = new Queue <decimal>();

            decimal exchange_fee         = 0.47m; // биржевой сбор SBRF 0.47
            decimal brokerage_commission = 0.59m; // комиссия брокера 0.59
            decimal spred = 3m;

            // --одновременно можно только один
            //extPrice.CreateExtrem(_mTR, _otkat, _profit);
            extPrice.CreateExtrem(_tBR, _otkat, _profit);
            //-------

            //----
            decimal _buyMany      = 0;
            decimal _selMany      = 0;
            decimal _bruttoGlobal = 0;
            int     _countProfit  = 0;
            int     _countLoss    = 0;
            int     _countAll     = 0;
            int     _variability  = 0;

            StaticService.LogFileWriteNotDateTime("Profit setting <" + _profit + ">", _fileTrades, true);
            StaticService.LogFileWriteNotDateTime("Profit setting <" + _profit + ">", _filevariability, true);
            StaticService.LogFileWriteNotDateTime("Profit setting <" + _profit + ">", _fileBrutto, true);
            StaticService.LogFileWriteNotDateTime("Profit setting <" + _profit + ">", _fileBruttoFiltr, true);
            StaticService.LogFileWriteNotDateTime("Profit setting <" + _profit + ">", _fileBruttoFiltrPro, true);

            foreach (var item in extPrice.TradesQueue)
            {
                StaticService.LogFileWriteNotDateTime(item.ToString(), _fileTrades, true);

                double    _num    = item.NumberTrades;
                Operation _oper   = item.Operation;
                decimal   _price  = item.PriceTrades;
                decimal   _brutto = 0;

                if (_oper == Operation.Buuy)
                {
                    _buyMany = _price;
                }
                else
                {
                    _selMany = _price;
                }

                if (_buyMany != 0 && _selMany != 0)
                {
                    _brutto        = _selMany - _buyMany;
                    _bruttoGlobal += _brutto;
                    _buyMany       = 0;
                    _selMany       = 0;

                    if (_brutto > 0)
                    {
                        _countProfit++;
                    }
                    else
                    {
                        _countLoss++;
                    }

                    _countAll++;

                    BruttoQue.Enqueue(_brutto);
                    StaticService.LogFileWriteNotDateTime(_brutto.ToString(), _fileBrutto, true);

                    //
                    VariablityCalc(_brutto, _filevariability, ref _variability);
                    //-----
                }
            }

            // фильтрация pro
            for (int i = 1; i <= 10; i++)
            {
                Queue <decimal> resultPositive = extPrice.FiltrBruttoPro(BruttoQue, i, 0);
                Queue <decimal> resultNegative = extPrice.FiltrBruttoPro(BruttoQue, 0, i);

                decimal _sum = 0;

                foreach (decimal item in resultPositive)
                {
                    _sum += item;
                }

                StaticService.LogFileWriteNotDateTime("FILTR_PRO + <" + i + "> = " + _sum.ToString(), _fileBruttoFiltrPro, true);

                _sum = 0;

                foreach (decimal item in resultNegative)
                {
                    _sum += item;
                }

                StaticService.LogFileWriteNotDateTime("FILTR_PRO - <" + i + "> = " + _sum.ToString(), _fileBruttoFiltrPro, true);
            }


            // циклическая фильтрация
            StaticService.LogFileWriteNotDateTime("SUMMARY_INP = " + _bruttoGlobal.ToString(), _fileBruttoFiltr, true);
            Queue <decimal> _filtr_result = extPrice.FiltrBrutto(BruttoQue);

            for (int i = 0; i < 5; i++)
            {
                decimal _sum = 0;

                foreach (decimal item in _filtr_result)
                {
                    _sum += item;
                }
                StaticService.LogFileWriteNotDateTime("SUMMARY_" + i + " = " + _sum.ToString(), _fileBruttoFiltr, true);

                _filtr_result = extPrice.FiltrBrutto(_filtr_result);
            }

            /*
             * // фильтруем brutto и выводим в файл
             * Queue<decimal> _filtrBrut_I = extPrice.FiltrBrutto(BruttoQue);
             * foreach (decimal item in _filtrBrut_I)
             * {
             *  StaticService.LogFileWriteNotDateTime(item.ToString(), _fileBruttoFiltr, true);
             * }
             *
             * // фильтруем _filtrBrut и выводим в файл
             * StaticService.LogFileWriteNotDateTime("--------LEVEL II", _fileBruttoFiltr, true);
             * Queue<decimal> _filtrBrut_II = extPrice.FiltrBrutto(_filtrBrut_I);
             * foreach (decimal item in _filtrBrut_II)
             * {
             *  StaticService.LogFileWriteNotDateTime(item.ToString(), _fileBruttoFiltr, true);
             * }
             *
             * // summary brutto_filtr
             * decimal _sum_brut_filtr = 0;
             * foreach (decimal item in _filtrBrut_I)
             * {
             *  _sum_brut_filtr += item;
             * }
             * StaticService.LogFileWriteNotDateTime("SUMMARY_I = " + _sum_brut_filtr.ToString(), _fileBruttoFiltr, true);
             *
             * _sum_brut_filtr = 0;
             * foreach (decimal item in _filtrBrut_II)
             * {
             *  _sum_brut_filtr += item;
             * }
             * StaticService.LogFileWriteNotDateTime("SUMMARY_II = " + _sum_brut_filtr.ToString(), _fileBruttoFiltr, true);
             * //---------------------------
             */
            //StaticService.LogFileWriteNotDateTime(_bruttoGlobal + " <" + _profit + ">", _filename, true);
            StaticService.LogFileWriteNotDateTime(_profit + "\t" + _bruttoGlobal + "\t" + _countProfit + "\t" + _countLoss + "\t" + _countAll, _fileSummary, true);
        }