Esempio n. 1
0
        /// <summary>
        /// Основной метод, рассчитыввающий статистику
        /// </summary>
        public Dictionary <int, AccountPerformanceRaw> GetPerformanceStatistic(BackgroundWorker worker)
        {
            var       accountPerformance = new Dictionary <int, AccountPerformanceRaw>();
            const int ProgressForQuotes  = 50;
            const int ProgressForDeals   = 50;

            try
            {
                var dicQuote        = new Dictionary <string, List <QuoteData> >();
                var symbolsUsed     = DalSpot.Instance.GetTickerNames();
                var progressCounter = 0;
                foreach (var smb in symbolsUsed)
                {
                    if (worker.CancellationPending)
                    {
                        return(accountPerformance);
                    }
                    dicQuote.Add(smb, LoadTickerQuotesFromFile(smb).Select(q => new QuoteData(q.b, q.b, q.a)).ToList());
                    var progress = (++progressCounter) * 100 / symbolsUsed.Length * ProgressForQuotes / 100;
                    worker.ReportProgress(progress);
                }
                var quoteArc = new QuoteArchive(dicQuote);

                AccountDealContainer.SymbolsUsed = symbolsUsed;
                var containers = DealFileNames.Select(x => new AccountDealContainer(x)).ToList();

                progressCounter = 0;
                foreach (var container in containers)
                {
                    if (worker.CancellationPending)
                    {
                        return(accountPerformance);
                    }
                    accountPerformance.Add(container.Id,
                                           equityCurveCalculator.CalculateEquityCurve(
                                               container.Deals,
                                               DepoCurrency,
                                               quoteArc,
                                               container.Transactions,
                                               container.TimeStart,
                                               container.TimeEnd)
                                           );
                    var progress = ProgressForQuotes + (++progressCounter) * 100 / containers.Count * ProgressForDeals / 100;
                    worker.ReportProgress(progress);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetStat()", ex);
            }
            return(accountPerformance);
        }
        public void CalculateEquityCurve()
        {
            var deals = new List <MarketOrder>();

            var dealsOpen  = TestDataGenerator.GetOpenPosition().Select(LinqToEntity.DecorateOrder).ToList();
            var dealsClose = TestDataGenerator.GetClosePosition().Select(LinqToEntity.DecorateOrder).ToList();

            deals.AddRange(dealsOpen);
            deals.AddRange(dealsClose);

            var transfers           = TestDataGenerator.GetBalanceChange().Select(LinqToEntity.DecorateBalanceChange).ToList();
            var firstDealOpenedTime = deals.Min(d => d.TimeEnter);

            transfers.Insert(0, new BalanceChange
            {
                AccountID          = deals[0].AccountID,
                ValueDate          = firstDealOpenedTime.AddHours(-1),
                CurrencyToDepoRate = 1,
                ChangeType         = BalanceChangeType.Deposit,
                Amount             = 500000
            });

            var dicQuote = new Dictionary <string, List <QuoteData> >();

            foreach (var smb in DalSpot.Instance.GetTickerNames())
            {
                dicQuote.Add(smb, dailyQuoteStorage.GetQuotes(smb).Select(q => new QuoteData(q.b, q.b, q.a)).ToList());
            }

            var quoteArc = new QuoteArchive(dicQuote);
            var res      = curveCalculator.CalculateEquityCurve(deals, DepoCurrency, quoteArc, transfers);

            // сверить точку кривой доходности
            CheckEquityCurvePoint(res, transfers, dealsOpen, dealsClose, quoteArc, dicQuote, 0);
            CheckEquityCurvePoint(res, transfers, dealsOpen, dealsClose, quoteArc, dicQuote, 10);
            CheckEquityCurvePoint(res, transfers, dealsOpen, dealsClose, quoteArc, dicQuote, 40);
        }