コード例 #1
0
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			if (systemPerformance.ShortTrades.LosingTrades.TradesPerformance.Percent.AvgProfit == 0)
				return 1;
			else
				return systemPerformance.ShortTrades.WinningTrades.TradesPerformance.Percent.AvgProfit / Math.Abs(systemPerformance.ShortTrades.LosingTrades.TradesPerformance.Percent.AvgProfit);
		}
コード例 #2
0
        public void CompactData_WorksWithEmptyList()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>();

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>(), data.ToList());
        }
コード例 #3
0
        public void CompactData_WorksWithThreeEntriesThatAreTheSame()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 1, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 10
                },
            };

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 10
                },
            }, data.ToList());
        }
コード例 #4
0
        public void CompactData_WorksWithTwoEntriesThatAreFarApart()
        {
            // Since it will be greater than the secondsInterval, 2 should be inserted to represent the gap
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 10, 0), Value = 10
                },
            };

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 1), Value = 0
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 9, 59), Value = 0
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 10, 0), Value = 10
                },
            }, data.ToList(), string.Format("Different number of elements: {0}", data.Count));
        }
コード例 #5
0
        public IList <SystemPerformance> GetSystemCpuPerformanceData(string cpuFrom, string to, bool?raw = null)
        {
            try
            {
                DateTime fromDate = DateTime.ParseExact(cpuFrom, Constants.DateFormat, CultureInfo.InvariantCulture);
                DateTime toDate   = DateTime.ParseExact(to, Constants.DateFormat, CultureInfo.InvariantCulture);

                using (var dao = _daoFactory.Create <ISystemDao>())
                {
                    var data = dao.GetCpuPerformanceData(fromDate, toDate);

                    if (raw != true)
                    {
                        SystemPerformance.CompactData(data, SecondsInterval);
                        SystemPerformance.LowerResolution(
                            data,
                            ApplicationSettings.Current.PerformanceGraphMaxPoints,
                            ApplicationSettings.Current.PerformanceGraphThreshold);
                    }

                    return(data);
                }
            }
            catch (Exception e)
            {
                log.Error("REST API Error", e);
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
コード例 #6
0
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			if (systemPerformance.LongTrades.TradesCount == 0)
				return 0;
			else
				return (double) systemPerformance.LongTrades.WinningTrades.TradesCount / systemPerformance.LongTrades.TradesCount;
		}
コード例 #7
0
        public void LowerResolution_WorksWithEmptyList()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>();

            SystemPerformance.LowerResolution(data, 1, 0);
            CollectionAssert.AreEqual(new List <SystemPerformance>(), data.ToList());
        }
コード例 #8
0
        public SystemPerformance getPerformance(int cpu, int memory)
        {
            SystemPerformance systemperformance = new SystemPerformance();

            systemperformance.cpu    = cpu;
            systemperformance.memory = memory;
            return(systemperformance);
        }
コード例 #9
0
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     if (systemPerformance.AllTrades.TradesCount == 0)
     {
         return(0);
     }
     else
     {
         return((double)systemPerformance.AllTrades.WinningTrades.TradesCount / systemPerformance.AllTrades.TradesCount);
     }
 }
コード例 #10
0
ファイル: MaxProbability.cs プロジェクト: kbh0001/kennt-stuff
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			if (systemPerformance.AllTrades.TradesCount <= 1 || systemPerformance.AllTrades.TradesPerformance.Percent.AvgProfit == 0)
				return 0;
			else
			{
				double div	= systemPerformance.AllTrades.TradesPerformance.Percent.StdDev / Math.Sqrt(systemPerformance.AllTrades.TradesCount);
				double t	= Stat.StudTp(systemPerformance.AllTrades.TradesPerformance.Percent.AvgProfit / div, systemPerformance.AllTrades.TradesCount - 1);
				return (div <= 0.5 ? 1 - t : t);
			}
		}
コード例 #11
0
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     if (systemPerformance.ShortTrades.LosingTrades.TradesPerformance.Percent.AvgProfit == 0)
     {
         return(1);
     }
     else
     {
         return(systemPerformance.ShortTrades.WinningTrades.TradesPerformance.Percent.AvgProfit / Math.Abs(systemPerformance.ShortTrades.LosingTrades.TradesPerformance.Percent.AvgProfit));
     }
 }
コード例 #12
0
        /// <summary>
        /// Return the performance value of a backtesting result.
        /// </summary>
        /// <param name="systemPerformance"></param>
        /// <returns></returns>
        public override double GetPerformanceValue(SystemPerformance systemPerformance)
        {
            var performanceValue = double.MinValue;

            if (systemPerformance.AllTrades.Count >= _minimumTrades && systemPerformance.AllTrades.Count <= _maximumTrades)
            {
                performanceValue = _optimisationType.GetPerformanceValue(systemPerformance);
            }

            _lastPerformanceValue = performanceValue;

            return performanceValue;
        }
コード例 #13
0
        /// <summary>
        /// Return the performance value of a backtesting result.
        /// </summary>
        /// <param name="systemPerformance"></param>
        /// <returns></returns>
        public override double GetPerformanceValue(SystemPerformance systemPerformance)
        {
            var performanceValue = double.MinValue;

            if (systemPerformance.AllTrades.Count >= _minimumTrades && systemPerformance.AllTrades.Count <= _maximumTrades)
            {
                performanceValue = _optimisationType.GetPerformanceValue(systemPerformance);
            }

            _lastPerformanceValue = performanceValue;

            return(performanceValue);
        }
コード例 #14
0
ファイル: MaxProbability.cs プロジェクト: fandres70/custom
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     if (systemPerformance.AllTrades.TradesCount <= 1 || systemPerformance.AllTrades.TradesPerformance.Percent.AvgProfit == 0)
     {
         return(0);
     }
     else
     {
         double div = systemPerformance.AllTrades.TradesPerformance.Percent.StdDev / Math.Sqrt(systemPerformance.AllTrades.TradesCount);
         double t   = Stat.StudTp(systemPerformance.AllTrades.TradesPerformance.Percent.AvgProfit / div, systemPerformance.AllTrades.TradesCount - 1);
         return(div <= 0.5 ? 1 - t : t);
     }
 }
コード例 #15
0
        public void LowerResolution_WorksWithSingleItemInTheList(int maxPoints, decimal threshold)
        {
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                }
            };

            SystemPerformance.LowerResolution(data, maxPoints, threshold);
            Assert.AreEqual(1, data.Count, "Records were incorrectly removed.");
            AssertPerformanceEquality(10m, new DateTime(2015, 1, 1, 6, 0, 0), data[0]);
        }
コード例 #16
0
 public override void BuildOnceAfterFullBlindBacktestFinished(SystemPerformance performance)
 {
     this.systemPerformance = performance;
     if (this.systemPerformance.Bars.IsIntraday)
     {
         this.olvcEntryDate.Width = 120;
         this.olvcExitDate.Width  = 120;
     }
     else
     {
         this.olvcEntryDate.Width = 80;
         this.olvcExitDate.Width  = 80;
     }
     this.reversePositionsCalcCumulativesDumpToTitleAndOLV();
 }
コード例 #17
0
        public void CompatData_WorksWithSingleEntry()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                }
            };

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                }
            }, data.ToList());
        }
コード例 #18
0
        public void BuildOnceAllReports(SystemPerformance performance)
        {
            if (this.ChartFormManager.ChartForm.InvokeRequired)
            {
                this.ChartFormManager.ChartForm.BeginInvoke((MethodInvoker) delegate { this.BuildOnceAllReports(performance); });
                return;
            }
            foreach (Reporter rep in this.ReporterShortNamesUserInvoked.Values)
            {
                rep.BuildOnceAfterFullBlindBacktestFinished(performance);

                // Reporters.Position should display "Positions (276)"
                ReporterFormWrapper parent = rep.Parent as ReporterFormWrapper;
                if (parent == null)
                {
                    continue;
                }
                parent.Text = rep.TabText + " :: " + this.ChartFormManager.ChartForm.Text;
            }
        }
コード例 #19
0
ファイル: Performance.cs プロジェクト: xiechun/SquareOne
        void propagatePerformanceReport(SystemPerformance performance)
        {
            DataSeriesTimeBased equityCurve = performance.SlicesShortAndLong.EquityCurve;

            this.fontsByStyle.Clear();
            this.fontsByStyle.Add(this.Font.Style, this.Font);
            try {
                this.olvReport.BeginUpdate();
                this.olvReport.Items.Clear();

                this.currentColumn = 0;
                this.currentRow    = 0;
                this.GenerateReportForOneColumn(performance.SlicesShortAndLong);

                this.currentColumn++;
                this.currentRow = 0;
                this.GenerateReportForOneColumn(performance.SliceLong);

                this.currentColumn++;
                this.currentRow = 0;
                this.GenerateReportForOneColumn(performance.SliceShort);

                this.currentColumn++;
                this.currentRow = 0;
                this.GenerateReportForOneColumn(performance.SliceBuyHold);

                if (performance.BenchmarkSymbolBars != null)
                {
                    this.colBuyHold.Text  = performance.BenchmarkSymbolBars.Symbol;
                    this.colBuyHold.Width = 50;
                }
                else
                {
                    this.colBuyHold.Text  = "Buy & Hold";
                    this.colBuyHold.Width = 50;
                }
                //AdjustColumnSize();
            } finally {
                this.olvReport.EndUpdate();
            }
        }
コード例 #20
0
ファイル: Sqn.cs プロジェクト: redrhino/MoGo
        /// <summary>
        /// Return the performance value of a backtesting result.
        /// </summary>
        /// <param name="systemPerformance"></param>
        /// <returns></returns>
        public override double GetPerformanceValue(SystemPerformance systemPerformance)
        {
            // This calc comes from NT standard net profit opt type
            var averageProfitPerTrade = (systemPerformance.AllTrades.TradesPerformance.GrossProfit +
                                         systemPerformance.AllTrades.TradesPerformance.GrossLoss) /
                                        systemPerformance.AllTrades.Count;

            double stddev = 0;

            // Now figure std dev of profit
            // Note: I forget my statistics & pulled this algorithm from the internet,
            foreach (Trade trade in systemPerformance.AllTrades)
            {
                var tradeProfit = (trade.ProfitPoints * trade.Quantity *
                                   trade.Entry.Instrument.MasterInstrument.PointValue);

                stddev += Math.Pow(tradeProfit - averageProfitPerTrade, 2);
            }

            stddev /= systemPerformance.AllTrades.Count;
            stddev = Math.Sqrt(stddev);

            return (Math.Sqrt(systemPerformance.AllTrades.Count) * averageProfitPerTrade) / stddev;
        }
コード例 #21
0
ファイル: Sqn.cs プロジェクト: minhpascal/MoGo
        /// <summary>
        /// Return the performance value of a backtesting result.
        /// </summary>
        /// <param name="systemPerformance"></param>
        /// <returns></returns>
        public override double GetPerformanceValue(SystemPerformance systemPerformance)
        {
            // This calc comes from NT standard net profit opt type
            var averageProfitPerTrade = (systemPerformance.AllTrades.TradesPerformance.GrossProfit +
                                         systemPerformance.AllTrades.TradesPerformance.GrossLoss) /
                                        systemPerformance.AllTrades.Count;

            double stddev = 0;

            // Now figure std dev of profit
            // Note: I forget my statistics & pulled this algorithm from the internet,
            foreach (Trade trade in systemPerformance.AllTrades)
            {
                var tradeProfit = (trade.ProfitPoints * trade.Quantity *
                                   trade.Entry.Instrument.MasterInstrument.PointValue);

                stddev += Math.Pow(tradeProfit - averageProfitPerTrade, 2);
            }

            stddev /= systemPerformance.AllTrades.Count;
            stddev  = Math.Sqrt(stddev);

            return((Math.Sqrt(systemPerformance.AllTrades.Count) * averageProfitPerTrade) / stddev);
        }
コード例 #22
0
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     return(systemPerformance.LongTrades.TradesPerformance.ProfitFactor);
 }
コード例 #23
0
ファイル: MaxNetProfitLong.cs プロジェクト: fandres70/custom
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     return(systemPerformance.LongTrades.TradesPerformance.GrossProfit + systemPerformance.LongTrades.TradesPerformance.GrossLoss);
 }
コード例 #24
0
ファイル: MaxSharpeRatio.cs プロジェクト: kbh0001/kennt-stuff
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			return systemPerformance.AllTrades.TradesPerformance.SharpeRatio;
		}
コード例 #25
0
ファイル: MinDrawDownLong.cs プロジェクト: fandres70/custom
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     return(systemPerformance.LongTrades.TradesPerformance.Percent.DrawDown);
 }
コード例 #26
0
        [TestCase(1, 0.075, 1)] // 7.5% threshold
        public void LowerResolution_ThresholdWorksWithEightPoints(int maxPoints, decimal threshold, int expectedValuesIndex)
        {
            // These aren't great tests - they're looking at way too much data to test.
            // TODO: Rework this test into smaller tests and manybe use the TestCaseSource
            var expectedValues = new List <List <TimeValue> >
            {
                new List <TimeValue>
                {
                    // all records returned
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10.25m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.763m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.57m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 12.727m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 13.682m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.365m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 14.724m)
                },
                new List <TimeValue>
                {
                    // all records returned
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10.25m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.763m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.57m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 12.727m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 13.682m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.365m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 14.724m)
                }
            };

            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10.25m
                },                                                                                       // +2.5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 1, 0), Value = 10.763m
                },                                                                                        // +5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 11.57m
                },                                                                                       // +7.5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 3, 0), Value = 12.727m
                },                                                                                        // +10%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 4, 0), Value = 13.682m
                },                                                                                        // +7.5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 4, 0), Value = 14.365m
                },                                                                                        // +5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 5, 0), Value = 14.724m
                }                                                                                        // +2.5%
            };

            SystemPerformance.LowerResolution(data, maxPoints, threshold);

            Assert.AreEqual(expectedValues[expectedValuesIndex].Count, data.Count, "Records were incorrectly removed (or added).");
            for (int i = 0; i < expectedValues[expectedValuesIndex].Count; i++)
            {
                var timeValue = expectedValues[expectedValuesIndex].ElementAt(i);
                AssertPerformanceEquality(timeValue.Value, timeValue.DateTime, data[i]);
            }
        }
コード例 #27
0
        [TestCase(5, 1, 4)]   // with zero threshold, all points should be returned
        public void LowerResolution_MaxPointsWorksWithSixItemsInTheList(int maxPoints, decimal threshold, int expectedValuesIndex)
        {
            // These aren't great tests - they're looking at way too much data to test.
            // TODO: Rework this test into smaller tests and manybe use the TestCaseSource
            var expectedValues = new List <List <TimeValue> >
            {
                new List <TimeValue>
                {
                    // all records returned
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 2 records (0 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 3 records returned (1 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 4 records returned (2 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 5 records returned (3 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
            };

            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 1, 0), Value = 10.5m
                },                                                                                      // +5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 11.55m
                },                                                                                       // +10%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 3, 0), Value = 13.286m
                },                                                                                        // +15%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 4, 0), Value = 14.611m
                },                                                                                        // +10%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 5, 0), Value = 15.341m
                }                                                                                        // +5%
            };

            SystemPerformance.LowerResolution(data, maxPoints, threshold);

            Assert.AreEqual(expectedValues[expectedValuesIndex].Count, data.Count, "Records were incorrectly removed (or added).");
            for (int i = 0; i < expectedValues[expectedValuesIndex].Count; i++)
            {
                var timeValue = expectedValues[expectedValuesIndex].ElementAt(i);
                AssertPerformanceEquality(timeValue.Value, timeValue.DateTime, data[i]);
            }
        }
コード例 #28
0
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			return systemPerformance.LongTrades.TradesPerformance.GrossProfit + systemPerformance.LongTrades.TradesPerformance.GrossLoss;
		}
コード例 #29
0
ファイル: SQN.cs プロジェクト: redrhino/NinjaTrader.Base
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			// Allow override of minimum number of trades to return a value
			// Parameter is SQNMinTrades
			int minTrades = 30;
			if (sMinTrades > 0)
			{
				minTrades = sMinTrades;
			}
			else
			{
				int n;
				for (n = 0; n < Strategy.Parameters.Count; n++)
				{
					if ("SQNMinTrades".CompareTo(Strategy.Parameters[n].Name) == 0)
					{
						minTrades = (int)Strategy.Parameters[n].Value;
						break;
					}
				}
			}
		
			double numTrades = systemPerformance.AllTrades.Count;
			
			if (numTrades < minTrades)
				return 0;
			
			// This calc comes from NT standard net profit opt type
			double avgProfit = (systemPerformance.AllTrades.TradesPerformance.GrossProfit +
				systemPerformance.AllTrades.TradesPerformance.GrossLoss) / numTrades;

			double stddev = 0;
			double tradeProf;
			
			// Now figure std dev of profit
			// Note: I forget my statistics & pulled this algorithm from the internet,
			// corrections welcomed.
			foreach (Trade t in systemPerformance.AllTrades)
			{
				tradeProf = (t.ProfitPoints * t.Quantity * t.Entry.Instrument.MasterInstrument.PointValue);
				
				// Uncomment this section for debug output to NT's output window
				/*
				Strategy.Print(t.Entry.Time + "," + t.Quantity + "," + t.Entry.Price + "," + t.Exit.Price + "," +
					t.ProfitPoints.ToString("N2") + "," + t.Quantity + "," +
					t.Entry.Instrument.MasterInstrument.PointValue + "," + tradeProf);
				*/
				
				stddev += Math.Pow(tradeProf - avgProfit, 2);
			}
			
			stddev /= numTrades;
			stddev = Math.Sqrt(stddev);
			
			double sqn = (Math.Sqrt(numTrades) * avgProfit) / stddev;

			// Uncomment this section for debug output to NT's output window
			/*
			Strategy.Print("numTrades: " + numTrades.ToString("N2") + "  avgProfit: " + avgProfit.ToString("N2") +
				"  stddev: " + stddev.ToString("N2") + "  sqn: " + sqn.ToString("N2"));
			*/
			
			// Hoping to access this from my optimizer (note: it works.)
			sLastSQN = sqn;
			return sqn;
		}
コード例 #30
0
ファイル: Performance.cs プロジェクト: xiechun/SquareOne
 public override void BuildOnceAfterFullBlindBacktestFinished(SystemPerformance performance)
 {
     this.systemPerformance = performance;
     this.propagatePerformanceReport(performance);
 }
コード例 #31
0
 /// <summary>
 /// Helper method that performs an assert on the system performance data point
 /// </summary>
 /// <param name="expectedValue"></param>
 /// <param name="expectedDate"></param>
 /// <param name="dataPoint"></param>
 private static void AssertPerformanceEquality(decimal expectedValue, DateTime expectedDate, SystemPerformance dataPoint)
 {
     Assert.AreEqual(expectedValue, dataPoint.Value, "Performance data point value has changed.");
     Assert.AreEqual(expectedDate, dataPoint.AuditTime, "Data point time has changed.");
 }
コード例 #32
0
ファイル: MaxSharpeRatio.cs プロジェクト: yuxi214/ninja-code
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     return(systemPerformance.AllTrades.TradesPerformance.SharpeRatio);
 }
コード例 #33
0
        /// <summary>
        /// Return the performance value of a backtesting result.
        /// </summary>
        /// <param name="systemPerformance"></param>
        /// <returns></returns>
        public override double GetPerformanceValue(SystemPerformance systemPerformance)
        {
            // Allow override of minimum number of trades to return a value
            // Parameter is SQNMinTrades
            int minTrades = 30;

            if (sMinTrades > 0)
            {
                minTrades = sMinTrades;
            }
            else
            {
                int n;
                for (n = 0; n < Strategy.Parameters.Count; n++)
                {
                    if ("SQNMinTrades".CompareTo(Strategy.Parameters[n].Name) == 0)
                    {
                        minTrades = (int)Strategy.Parameters[n].Value;
                        break;
                    }
                }
            }

            double numTrades = systemPerformance.AllTrades.Count;

            if (numTrades < minTrades)
            {
                return(0);
            }

            // This calc comes from NT standard net profit opt type
            double avgProfit = (systemPerformance.AllTrades.TradesPerformance.GrossProfit +
                                systemPerformance.AllTrades.TradesPerformance.GrossLoss) / numTrades;

            double stddev = 0;
            double tradeProf;

            // Now figure std dev of profit
            // Note: I forget my statistics & pulled this algorithm from the internet,
            // corrections welcomed.
            foreach (Trade t in systemPerformance.AllTrades)
            {
                tradeProf = (t.ProfitPoints * t.Quantity * t.Entry.Instrument.MasterInstrument.PointValue);

                // Uncomment this section for debug output to NT's output window

                /*
                 * Strategy.Print(t.Entry.Time + "," + t.Quantity + "," + t.Entry.Price + "," + t.Exit.Price + "," +
                 *      t.ProfitPoints.ToString("N2") + "," + t.Quantity + "," +
                 *      t.Entry.Instrument.MasterInstrument.PointValue + "," + tradeProf);
                 */

                stddev += Math.Pow(tradeProf - avgProfit, 2);
            }

            stddev /= numTrades;
            stddev  = Math.Sqrt(stddev);

            double sqn = (Math.Sqrt(numTrades) * avgProfit) / stddev;

            // Uncomment this section for debug output to NT's output window

            /*
             * Strategy.Print("numTrades: " + numTrades.ToString("N2") + "  avgProfit: " + avgProfit.ToString("N2") +
             *      "  stddev: " + stddev.ToString("N2") + "  sqn: " + sqn.ToString("N2"));
             */

            // Hoping to access this from my optimizer (note: it works.)
            sLastSQN = sqn;
            return(sqn);
        }
コード例 #34
0
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     return(systemPerformance.ShortTrades.TradesPerformance.Percent.AvgProfit);
 }
コード例 #35
0
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			return systemPerformance.LongTrades.TradesPerformance.Percent.AvgProfit;
		}
コード例 #36
0
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			return systemPerformance.LongTrades.TradesPerformance.ProfitFactor;
		}
コード例 #37
0
		/// <summary>
		/// Return the performance value of a backtesting result.
		/// </summary>
		/// <param name="systemPerformance"></param>
		/// <returns></returns>
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
		{
			return systemPerformance.LongTrades.TradesPerformance.Percent.DrawDown;
		}
コード例 #38
0
 /// <summary>
 /// Return the performance value of a backtesting result.
 /// </summary>
 /// <param name="systemPerformance"></param>
 /// <returns></returns>
 public override double GetPerformanceValue(SystemPerformance systemPerformance)
 {
     return(-systemPerformance.AllTrades.TradesPerformance.Points.CumProfit / systemPerformance.AllTrades.TradesPerformance.Points.DrawDown);
     //return systemPerformance.AllTrades.TradesPerformance.Points.CumProfit;
     //return systemPerformance.AllTrades.TradesPerformance.Points.DrawDown;
 }