Пример #1
0
 public void WriteStatsData(TradeStats stats, string type)
 {
     fwriter.WriteLine("<TR>");
     if (type == "Day")
     {
         type = "Daily";
     }
     else if (type == "Trade")
     {
         type = "Trades";
     }
     else if (type == "ComboTrades")
     {
         type = "ComboTrades";
     }
     else
     {
         type += "ly";
     }
     fwriter.WriteLine("<TD class=\"leftcol\">" + type + "</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.SortinoRatio, 2) + "</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.SharpeRatio, 2) + "</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.Volatility, 2) + "</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.MaxDownsideRisk * 100, 2) + "%</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.AnnualReturn * 100, 1) + "%</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.WinRate * 100, 1) + "%</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.ProfitFactor, 2) + "</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + stats.Count + "</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.WinRate * 100) + "%</TD>");
     fwriter.WriteLine("<TD class=\"data\">" + Math.Round(stats.Average, 2) + "</TD>");
     fwriter.WriteLine("</TR>");
 }
Пример #2
0
        private void FormatTradesStats(Action <string, Side> setAction, TradeStats trades)
        {
            if (trades == TradeStats.NULL)
            {
                return;
            }

            if (trades.BuysPerc >= trades.SellsPerc)
            {
                setAction($"{trades.BuysPerc:###}% buys{Environment.NewLine}{trades.TotalCount}", Side.Buy);
                return;
            }
            setAction($"{trades.SellsPerc:###}% sells{Environment.NewLine}{trades.TotalCount}", Side.Sell);
        }
Пример #3
0
 public void WriteTrades(TransactionPairs transactionPairs, TradeStats stats, bool combo)
 {
     if (transactionPairs != null && transactionPairs.Count > 0)
     {
         int    year           = 0;
         double currentBalance = stats.BeginningBalance;
         double yearBalance    = stats.BeginningBalance;
         double ytdProfitLoss  = 0;
         WriteTradeHeader();
         List <string> tableData = new List <string>();
         for (int i = 0; i < transactionPairs.Count; i++)
         {
             if (transactionPairs[i].EntryTime.Year != year)
             {
                 tableData.Add(WriteTradeTitles(year, combo));
                 yearBalance  += ytdProfitLoss;
                 ytdProfitLoss = 0;
                 year          = transactionPairs[i].EntryTime.Year;
             }
             double profitLoss = transactionPairs.CalcProfitLoss(i);
             string tableRow   = "<tr>";
             tableRow += "<td class=\"leftcol\">" + i + "</td>";
             tableRow += "<td class=\"data\">" + transactionPairs[i].EntryTime + "</td>";
             tableRow += "<td class=\"data\">" + transactionPairs[i].ExitTime + "</td>";
             tableRow += "<td class=\"data\">" + transactionPairs[i].EntryPrice.ToString(",0.000") + "</td>";
             tableRow += "<td class=\"data\">" + transactionPairs[i].EntryBar + "</td>";
             tableRow += "<td class=\"data\">" + transactionPairs[i].ExitPrice.ToString(",0.000") + "</td>";
             tableRow += "<td class=\"data\">" + transactionPairs[i].ExitBar + "</td>";
             tableRow += "<td class=\"data\">" + ((transactionPairs[i].Direction > 0)?"Long":"Short") + " " + Math.Round(Math.Abs(transactionPairs[i].Direction), 2) + "</td>";
             tableRow += "<td class=\"data\">" + Math.Round(transactionPairs.CalcMaxAdverse(i), 2) + "</td>";
             tableRow += "<td class=\"data\">" + Math.Round(transactionPairs.CalcMaxFavorable(i), 2) + "</td>";
             tableRow += "<td class=\"data\">" + Math.Round(profitLoss, 2) + "</td>";
             double monthlyReturn = ((currentBalance + profitLoss) / currentBalance) - 1;
             tableRow      += "<td class=\"data\">" + Math.Round(monthlyReturn * 100, 2) + "%</td>";
             ytdProfitLoss += profitLoss;
             double ytdReturn = ((yearBalance + ytdProfitLoss) / yearBalance) - 1;
             tableRow       += "<td class=\"data\">" + Math.Round(ytdReturn * 100, 2) + "%</td>";
             currentBalance += profitLoss;
             tableRow       += "<td class=\"data\">" + Math.Round(currentBalance, 2) + "</td>";
             tableRow       += "</tr>";
             tableData.Add(tableRow);
         }
         tableData.Add(WriteTradeTitles(year, combo));
         for (int i = 0; i < tableData.Count; i++)
         {
             fwriter.WriteLine(tableData[i]);
         }
         WriteTradeFooter();
     }
 }
Пример #4
0
        public void WriteChart(string folder, string strategyName, string chartName, TradeStats stats, TransactionPairs daily)
        {
            if (daily.Count == 0)
            {
                return;
            }
            GraphPane myPane = new GraphPane(new RectangleF(0, 0, 640, 480),
                                             chartName, "Date", "Price");

            PointPairList ppl = new PointPairList();
            double        y   = stats.BeginningBalance;

            ppl.Add(daily[0].EntryTime.ToOADate(), y);
            for (int i = 0; i < daily.Count; i++)
            {
                y += daily.CalcProfitLoss(i);
                ppl.Add(daily[i].ExitTime.ToOADate(), y);
            }

            if (trace)
            {
                log.Trace("Chart start = " + ppl[0].Y + ", end = " + ppl[ppl.Count - 1].Y);
            }

            LineItem myCurve = myPane.AddCurve("Profit/Loss Equity Curve", ppl, Color.Blue, SymbolType.None);

            myCurve.Line.Fill = new Fill(Color.Blue);

            // pretty it up a little
            myPane.Chart.Fill                = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
            myPane.Fill                      = new Fill(Color.White);
            myPane.Border.IsVisible          = false;
            myPane.Title.FontSpec.Size       = 20.0f;
            myPane.XAxis.Type                = AxisType.DateAsOrdinal;
            myPane.XAxis.Title.FontSpec.Size = 14.0f;
            myPane.XAxis.Scale.FontSpec.Size = 14.0f;
            myPane.XAxis.Title.IsOmitMag     = true;

            myPane.YAxis.Title.FontSpec.Size = 14.0f;
            myPane.YAxis.Scale.FontSpec.Size = 14.0f;
//		    myPane.YAxis.Title.IsOmitMag = true;
            myPane.Legend.IsVisible = false;

            myPane.AxisChange();

            string pathName = folder + strategyName + @"\Images\" + chartName + ".gif";

            Directory.CreateDirectory(Path.GetDirectoryName(pathName));
            myPane.GetImage().Save(pathName, ImageFormat.Gif);
        }
Пример #5
0
 public void WriteDays(TransactionPairs trades, TradeStats stats)
 {
     if (trades.Count > 0)
     {
         int    year           = 0;
         double currentBalance = stats.BeginningBalance;
         double yearBalance    = stats.BeginningBalance;
         double ytdProfitLoss  = 0;
         WriteYearHeader();
         List <string> tableData = new List <string>();
         for (int i = 0; i < trades.Count; i++)
         {
             if (trades[i].EntryTime.Year != year)
             {
                 tableData.Add(WriteYearTitles(year));
                 yearBalance   = yearBalance + ytdProfitLoss;
                 ytdProfitLoss = 0;
                 year          = trades[i].EntryTime.Year;
             }
             double profitLoss = trades.CalcProfitLoss(i);
             string tableRow   = "<tr>";
             tableRow += "<td class=\"leftcol\">" + trades[i].EntryTime.Month + "/" + trades[i].EntryTime.Day + "/" + year + "</td>";
             tableRow += "<td class=\"data\">" + Math.Round(profitLoss, 2) + "</td>";
             double monthlyReturn = ((currentBalance + profitLoss) / currentBalance) - 1;
             tableRow      += "<td class=\"data\">" + Math.Round(monthlyReturn * 100, 2) + "%</td>";
             ytdProfitLoss += profitLoss;
             double ytdReturn = ((yearBalance + ytdProfitLoss) / yearBalance) - 1;
             tableRow       += "<td class=\"data\">" + Math.Round(ytdReturn * 100, 2) + "%</td>";
             currentBalance += profitLoss;
             tableRow       += "<td class=\"data\">" + Math.Round(currentBalance, 2) + "</td>";
             tableRow       += "</tr>";
             tableData.Add(tableRow);
         }
         tableData.Add(WriteYearTitles(year));
         for (int i = tableData.Count - 1; i >= 0; i--)
         {
             fwriter.WriteLine(tableData[i]);
         }
         WriteYearFooter();
     }
 }
Пример #6
0
 public override void Constructor(TransactionPairs trades)
 {
     tradeStats      = new TradeStats(trades);
     tradeStats.Name = "Test Strategy";
     baseStats       = tradeStats;
 }