コード例 #1
0
 public void ProfitLossException()
 {
     pair = TransactionPairBinary.Create();
     using (BinaryStore tradeData = Factory.Engine.PageStore("TradeData")) {
         TransactionPairsBinary tradesBinary = new TransactionPairsBinary(tradeData);
         tradesBinary.Add(pair);
         TransactionPairs trades = new TransactionPairs(null, new ProfitLossCallback(), tradesBinary);
         double           pnl    = trades.CalcProfitLoss(0);
     }
 }
コード例 #2
0
        public void TradeTesting()
        {
            PerformanceInner      manager  = TradeTickProcessing(0, 0, 30000);
            TransactionPairBinary expected = TransactionPairBinary.Create();

            expected.Enter(1, 105.660, new TimeStamp(2005, 2, 8, 11, 57, 22, 429), emptyTime, 1, 0, 0);
            expected.Exit(105.670, new TimeStamp(2005, 2, 8, 11, 57, 51, 479), emptyTime, 1, 0, 0);
            TransactionPairs rts = manager.ComboTrades;

            Assert.AreEqual(-.034, Math.Round(rts.CalcProfitLoss(0), 3), "First Trade PnL");
        }
コード例 #3
0
        public void ProfitLoss()
        {
            Constructor();
            double ProfitLoss = (pair.ExitPrice - pair.EntryPrice) * 1;

            using (BinaryStore tradeData = Factory.Engine.PageStore("TradeData")) {
                TransactionPairsBinary tradesBinary = new TransactionPairsBinary(tradeData);
                tradesBinary.Add(pair);
                TransactionPairs trades = new TransactionPairs(null, new ProfitLossCallback(), tradesBinary);
                Assert.AreEqual(113096, trades.CalcProfitLoss(0), "ProfitLoss");
            }
        }
コード例 #4
0
ファイル: BaseStats.cs プロジェクト: zoomcoder/TickZoomPublic
 private void calcProfitLoss()
 {
     profitLoss = 0;
     for (int i = 0; i < trades.Count; i++)
     {
         profitLoss += trades.CalcProfitLoss(i);
     }
 }
コード例 #5
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();
     }
 }
コード例 #6
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);
        }
コード例 #7
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();
     }
 }