Esempio n. 1
0
        private void loadFromToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _table.Clear();

            using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
            {
                DialogResult result = folderBrowserDialog.ShowDialog();

                if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath))
                {
                    string[] filePaths = Directory.GetFiles(folderBrowserDialog.SelectedPath);

                    foreach (string path in filePaths)
                    {
                        TradeHistory tradeHistory = ProcessFile(path);

                        AssetSummary assetSummary = tradeHistory.GetSummary();

                        object[] rowData =
                        {
                            assetSummary.Asset,
                            assetSummary.NumberOfTrades,
                            assetSummary.AverageWinPercentage,
                            assetSummary.NumberOfTradesOverTenPercent,
                            assetSummary.AveragePercentGainOverTenPercent,
                            assetSummary.NumberOfWins,
                            assetSummary.NumberOfLosses,
                            assetSummary.AverageLosingPercent
                        };

                        object[] row = new object[rowData.Length + assetSummary.NumberInMonth.Length];
                        rowData.CopyTo(row, 0);
                        assetSummary.NumberInMonth.CopyTo(row, rowData.Length);

                        _table.Rows.Add(row);
                    }
                }
            }
        }
Esempio n. 2
0
        public AssetSummary GetSummary()
        {
            AssetSummary summary = new AssetSummary();

            summary.Asset          = Asset;
            summary.NumberOfTrades = _closedTrades.Count;

            IEnumerable <ClosedTrade> winningTrades      = _closedTrades.Where(x => x.Percentage > 0).ToList();
            IEnumerable <ClosedTrade> losingTrades       = _closedTrades.Where(x => x.Percentage < 0).ToList();
            IEnumerable <ClosedTrade> winsOverTenPercent = _closedTrades.Where(x => x.Percentage >= 10).ToList();

            summary.AverageWinPercentage             = !winningTrades.Any() ? 0 : winningTrades.Average(x => x.Percentage);
            summary.AverageLosingPercent             = !losingTrades.Any() ? 0 : losingTrades.Average(x => x.Percentage);
            summary.NumberOfLosses                   = losingTrades.Count();
            summary.NumberOfWins                     = winningTrades.Count();
            summary.AveragePercentGainOverTenPercent = !winsOverTenPercent.Any() ? 0 : winsOverTenPercent.Average(x => x.Percentage);
            summary.NumberOfTradesOverTenPercent     = winsOverTenPercent.Count();

            summary.AverageWinPercentage             = Math.Round(summary.AverageWinPercentage, 2);
            summary.AverageLosingPercent             = Math.Round(summary.AverageLosingPercent, 2);
            summary.AveragePercentGainOverTenPercent = Math.Round(summary.AveragePercentGainOverTenPercent, 2);

            summary.NumberInMonth = new int[12];

            TimeSpan      oneYear = new TimeSpan(365, 0, 0, 0);
            MonthIterator months  = new MonthIterator(DateTime.Now.Subtract(oneYear));

            int i = 0;

            foreach (DateTime dateTime in months)
            {
                int count = _closedTrades.Count(x =>
                                                x.DateOpened.Month == dateTime.Month && x.DateOpened.Year == dateTime.Year);
                summary.NumberInMonth[i] = count;
                i++;
            }

            return(summary);
        }