Esempio n. 1
0
        private void CalcMaxPosition(PricePairList positionValues)
        {
            var max = new PricePair();

            foreach (var value in positionValues)
            {
                max = PricePair.Max(max, value);
            }
            _marketMaxPosition = max.Market;
            _bookMaxPosition   = max.Book;
        }
Esempio n. 2
0
// ReSharper disable ParameterTypeCanBeEnumerable.Local
        private void CalcDrowdown(PricePairList profits)
// ReSharper restore ParameterTypeCanBeEnumerable.Local
        {
            var maxProfit   = new PricePair();
            var maxDrowdown = new PricePair();

            foreach (var profit in profits)
            {
                maxProfit   = PricePair.Max(maxProfit, profit);
                maxDrowdown = PricePair.Min(maxDrowdown, profit - maxProfit);
            }
            _marketMaxDrowDown = maxDrowdown.Market;
            _bookMaxDrowDown   = maxDrowdown.Book;
        }
Esempio n. 3
0
        private void EvaluateTrade(bool isLong, int term, float totalBuy, float totalSell, DateTime date, PricePair dailyprofit)
        {
            var year  = date.Year;
            var month = date.Month;

            _allTrades++;
            var ratio = isLong ? totalSell / totalBuy - 1 : 1 - totalBuy / totalSell; // 空売りは売りポジションが分母

            _allProfitRatio += ratio;
            _allTerm        += term;
            var profit = totalSell - totalBuy;

            _totalProfit += profit;
            // 年度別のトータル資金
            if (_totalProfitYear.ContainsKey(year) == true)
            {
                _totalProfitYear[year] += profit;
                _totalProfitMonth[T(year, month - 1)] += profit;
                _allTradesYear[year]++;
                _allTradesMonth[T(year, month - 1)]++;
                if (profit >= 0)
                {
                    _totalWinTradesYear[year]++;
                    _totalWinTradesMonth[T(year, month - 1)]++;
                    _totalWinMaxProfitYear[year] += profit;
                    _totalWinMaxProfitMonth[T(year, month - 1)] += profit;
                }
                else
                {
                    _totalLoseMaxProfitYear[year] += profit;
                    _totalLoseMaxProfitMonth[T(year, month - 1)] += profit;
                }
                if (totalSell < totalBuy) // 負け
                {
                    _totalMaxDrowDownYear[year] = Math.Min(_totalMaxDrowDownYear[year], ratio);
                    if (_totalMaxBookDrowDownYear[year] > totalSell - totalBuy)
                    {
                        _totalMaxBookDrowDownYear[year] = totalSell - totalBuy;
                        _maxBookDrowDawnDate[year]      = date;
                    }
                    _totalMaxDrowDownMonth[T(year, month - 1)] = Math.Min(_totalMaxDrowDownMonth[T(year, month - 1)], ratio);
                }
                if (_totalMaxMarketDrowDownYear[year] > dailyprofit.Market)
                {
                    _totalMaxMarketDrowDownYear[year] = dailyprofit.Market;
                    _maxMarketDrowDawnDate[year]      = date;
                }
            }
            else
            {
                _totalProfitYear.Add(year, profit);
                for (int i = 0; i < 12; i++)
                {
                    _totalProfitMonth.Add(T(year, i), 0);
                    _allTradesMonth.Add(T(year, i), 0);
                    _totalWinTradesMonth.Add(T(year, i), 0);
                    _totalMaxDrowDownMonth.Add(T(year, i), 0);
                    _totalWinMaxProfitMonth.Add(T(year, i), 0);
                    _totalLoseMaxProfitMonth.Add(T(year, i), 0);
                }
                _totalProfitMonth[T(year, month - 1)] = profit;
                _allTradesYear.Add(year, 1);
                _allTradesMonth[T(year, month - 1)]++;
                if (profit >= 0)
                {
                    _totalWinTradesYear.Add(year, 1);
                    _totalWinTradesMonth[T(year, month - 1)] = 1;
                    _totalWinMaxProfitYear.Add(year, profit);
                    _totalWinMaxProfitMonth[T(year, month - 1)] = profit;
                    _totalLoseMaxProfitYear.Add(year, 0);
                }
                else
                {
                    _totalWinTradesYear.Add(year, 0);
                    _totalWinMaxProfitYear.Add(year, 0);
                    _totalLoseMaxProfitYear.Add(year, profit);
                    _totalLoseMaxProfitMonth[T(year, month - 1)] = profit;
                }
                if (totalSell < totalBuy) // 負け
                {
                    _totalMaxDrowDownYear.Add(year, ratio);
                    _totalMaxDrowDownMonth[T(year, month - 1)] = ratio;
                    _totalMaxBookDrowDownYear.Add(year, dailyprofit.Market);
                    _maxBookDrowDawnDate[year] = date;
                    _totalMaxMarketDrowDownYear.Add(year, dailyprofit.Market);
                    _maxMarketDrowDawnDate[year] = date;
                }
                else
                {
                    _totalMaxDrowDownYear.Add(year, 0);
                    _totalMaxBookDrowDownYear.Add(year, 0);
                    _totalMaxMarketDrowDownYear.Add(year, 0);
                    _maxBookDrowDawnDate[year]   = date;
                    _maxMarketDrowDawnDate[year] = date;
                }
            }
            if (totalSell > totalBuy) // 勝ち
            {
                _winTrades++;
                if (_consecutiveWin >= 0)
                {
                    _consecutiveWin++;
                }
                else
                {
                    _consecutiveWin = 1;
                }
                _maxwinCount       = Math.Max(_maxwinCount, _consecutiveWin);
                _winProfitRatio   += ratio;
                _winMaxProfitRatio = Math.Max(_winMaxProfitRatio, ratio);
                _winMaxProfit      = Math.Max(_winMaxProfit, profit);
                _winTotalProfit   += profit;
                _winTerm          += term;
            }
            else // 負け
            {
                if (0 > _consecutiveWin)
                {
                    _consecutiveWin--;
                }
                else
                {
                    _consecutiveWin = -1;
                }
                _maxloseCount     = Math.Max(_maxloseCount, -1 * _consecutiveWin);
                _loseMaxLossRatio = Math.Min(_loseMaxLossRatio, ratio);
                _loseMaxLoss      = Math.Min(_loseMaxLoss, profit);
            }
        }