Esempio n. 1
0
        protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            var changed = false;

            if (statistics.Type == PortfolioStatisticsType.GrossProfit)
            {
                this.grossProfit = statistics;
                changed          = true;
            }
            if (statistics.Type == PortfolioStatisticsType.GrossLoss)
            {
                this.grossLoss = statistics;
                changed        = true;
            }
            if (changed)
            {
                this.longValue = this.shortValue = this.totalValue = 0;
                if (this.grossProfit != null)
                {
                    this.longValue  += this.grossProfit.LongValue;
                    this.shortValue += this.grossProfit.ShortValue;
                    this.totalValue += this.grossProfit.TotalValue;
                }
                if (this.grossLoss != null)
                {
                    this.longValue  += this.grossLoss.LongValue;
                    this.shortValue += this.grossLoss.ShortValue;
                    this.totalValue += this.grossLoss.TotalValue;
                }
                LongValues.Add(Clock.DateTime, this.longValue);
                ShortValues.Add(Clock.DateTime, this.shortValue);
                TotalValues.Add(Clock.DateTime, this.totalValue);
                Emit();
            }
        }
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == this.type)
     {
         bool changed = false;
         if (statistics.LongValues.Count > LongValues.Count)
         {
             this.longAvg = (this.longAvg * LongValues.Count + statistics.LongValue) / (LongValues.Count + 1);
             this.longValue = GetStdDev(statistics.LongValues, this.longAvg);
             LongValues.Add(Clock.DateTime, LongValue);
             changed = true;
         }
         if (statistics.ShortValues.Count > this.shortValues.Count)
         {
             this.shortAvg = (this.shortAvg * this.shortValues.Count + statistics.ShortValue) / (ShortValues.Count + 1);
             this.shortValue = GetStdDev(statistics.ShortValues, this.shortAvg);
             ShortValues.Add(Clock.DateTime, this.shortValue);
             changed = true;
         }
         if (statistics.TotalValues.Count > this.totalValues.Count)
         {
             this.totalAvg = (this.totalAvg * this.totalValues.Count + statistics.TotalValue) / (TotalValues.Count + 1);
             this.totalValue = GetStdDev(statistics.TotalValues, this.totalAvg);
             TotalValues.Add(Clock.DateTime, this.totalValue);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
 }
Esempio n. 3
0
 public void OnInit(string name)
 {
     this.name      = name;
     this.portfolio = Framework.Current.PortfolioManager[name];
     if (this.portfolio == null)
     {
         return;
     }
     this.ltvStatistics.BeginUpdate();
     this.ltvStatistics.Groups.Clear();
     this.ltvStatistics.Items.Clear();
     for (int index = 0; index < this.portfolio.Statistics.Items.Count; ++index)
     {
         PortfolioStatisticsItem statistics = this.portfolio.Statistics.Items[index];
         if (statistics.Show)
         {
             if (this.ltvStatistics.Groups[statistics.Category] == null)
             {
                 this.ltvStatistics.Groups.Add(statistics.Category, statistics.Category);
             }
             StatisticsViewItem statisticsViewItem = new StatisticsViewItem(statistics);
             statisticsViewItem.Group = this.ltvStatistics.Groups[statistics.Category];
             this.ltvStatistics.Items.Add((ListViewItem)statisticsViewItem);
         }
     }
     this.ltvStatistics.EndUpdate();
 }
Esempio n. 4
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == this.type)
     {
         bool changed = false;
         if (statistics.LongValues.Count > this.longValues.Count)
         {
             this.longValue = (this.longValue * this.longValues.Count + statistics.LongValue) / (this.longValues.Count + 1);
             this.longValues.Add(Clock.DateTime, this.longValue);
             changed = true;
         }
         if (statistics.ShortValues.Count > this.shortValues.Count)
         {
             this.shortValue = (this.shortValue * this.shortValues.Count + statistics.ShortValue) / (this.shortValues.Count + 1);
             this.shortValues.Add(Clock.DateTime, this.shortValue);
             changed = true;
         }
         if (statistics.TotalValues.Count > this.totalValues.Count)
         {
             this.totalValue = (this.totalValue * this.totalValues.Count + statistics.TotalValue) / (this.totalValues.Count + 1);
             this.totalValues.Add(base.Clock.DateTime, this.totalValue);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
 }
Esempio n. 5
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == this.type)
     {
         bool changed = false;
         if (statistics.LongValues.Count > this.longValues.Count)
         {
             this.longValue = (this.longValue * this.longValues.Count + statistics.LongValue) / (this.longValues.Count + 1);
             this.longValues.Add(Clock.DateTime, this.longValue);
             changed = true;
         }
         if (statistics.ShortValues.Count > this.shortValues.Count)
         {
             this.shortValue = (this.shortValue * this.shortValues.Count + statistics.ShortValue) / (this.shortValues.Count + 1);
             this.shortValues.Add(Clock.DateTime, this.shortValue);
             changed = true;
         }
         if (statistics.TotalValues.Count > this.totalValues.Count)
         {
             this.totalValue = (this.totalValue * this.totalValues.Count + statistics.TotalValue) / (this.totalValues.Count + 1);
             this.totalValues.Add(base.Clock.DateTime, this.totalValue);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
 }
        public static void Change(this StatisticsManager manager, int type, PortfolioStatisticsItem statisticsItem)
        {
            var i = (ICustomStatisticsType)statisticsItem;

            i.SetStatisticsType(type);
            manager.Add(statisticsItem);
        }
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == this.type)
     {
         bool changed = false;
         if (statistics.LongValues.Count > LongValues.Count)
         {
             this.longAvg   = (this.longAvg * LongValues.Count + statistics.LongValue) / (LongValues.Count + 1);
             this.longValue = GetStdDev(statistics.LongValues, this.longAvg);
             LongValues.Add(Clock.DateTime, LongValue);
             changed = true;
         }
         if (statistics.ShortValues.Count > this.shortValues.Count)
         {
             this.shortAvg   = (this.shortAvg * this.shortValues.Count + statistics.ShortValue) / (ShortValues.Count + 1);
             this.shortValue = GetStdDev(statistics.ShortValues, this.shortAvg);
             ShortValues.Add(Clock.DateTime, this.shortValue);
             changed = true;
         }
         if (statistics.TotalValues.Count > this.totalValues.Count)
         {
             this.totalAvg   = (this.totalAvg * this.totalValues.Count + statistics.TotalValue) / (TotalValues.Count + 1);
             this.totalValue = GetStdDev(statistics.TotalValues, this.totalAvg);
             TotalValues.Add(Clock.DateTime, this.totalValue);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
 }
Esempio n. 8
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     var changed = false;
     if (statistics.Type == PortfolioStatisticsType.GrossProfit)
     {
         this.grossProfit = statistics;
         changed = true;
     }
     if (statistics.Type == PortfolioStatisticsType.GrossLoss)
     {
         this.grossLoss = statistics;
         changed = true;
     }
     if (changed)
     {
         this.longValue = this.shortValue = this.totalValue = 0;
         if (this.grossProfit != null)
         {
             this.longValue += this.grossProfit.LongValue;
             this.shortValue += this.grossProfit.ShortValue;
             this.totalValue += this.grossProfit.TotalValue;
         }
         if (this.grossLoss != null)
         {
             this.longValue += this.grossLoss.LongValue;
             this.shortValue += this.grossLoss.ShortValue;
             this.totalValue += this.grossLoss.TotalValue;
         }
         LongValues.Add(Clock.DateTime, this.longValue);
         ShortValues.Add(Clock.DateTime, this.shortValue);
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 9
0
 public StatisticsViewItem(PortfolioStatisticsItem statistics)
   : base(new string[4])
 {
     this.Statistics = statistics;
     this.UseItemStyleForSubItems = false;
     this.SubItems[0].Text = this.Statistics.Name;
     this.Update();
 }
 private void UpdateSubItem(int index, PortfolioStatisticsItem statistics)
 {
     this.SubItems[index].Text = statistics.TotalValue.ToString(statistics.Format);
     if (statistics.TotalValue < 0.0)
         this.SubItems[index].ForeColor = Color.Red;
     else
         this.SubItems[index].ForeColor = Color.Black;
 }
Esempio n. 11
0
 public StatisticsViewItem(PortfolioStatisticsItem statistics)
     : base(new string[4])
 {
     this.Statistics = statistics;
     this.UseItemStyleForSubItems = false;
     this.SubItems[0].Text        = this.Statistics.Name;
     this.Update();
 }
Esempio n. 12
0
 protected override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.DailyNumOfWinTrades)
     {
         bool isEmit = false;
         if (statistics.LongValue != this.longLossTrades)
         {
             this.longLossTrades = statistics.LongValue;
             base.longValues.Add(base.Clock.DateTime, ++base.longValue);
             isEmit = true;
         }
         if (statistics.ShortValue != this.shortLossTrades)
         {
             this.shortLossTrades = statistics.ShortValue;
             base.shortValues.Add(base.Clock.DateTime, ++base.shortValue);
             isEmit = true;
         }
         if (statistics.TotalValue != this.totalLossTrades)
         {
             this.totalLossTrades = statistics.TotalValue;
             base.totalValues.Add(base.Clock.DateTime, ++base.totalValue);
             isEmit = true;
         }
         if (isEmit)
         {
             base.Emit();
         }
     }
     if (statistics.Type == PortfolioStatisticsType.DailyNumOfLossTrades)
     {
         bool isEmit = false;
         if (statistics.LongValue != this.longWinTrades)
         {
             this.longWinTrades = statistics.LongValue;
             base.longValue     = 0.0;
             base.longValues.Add(base.Clock.DateTime, base.longValue);
             isEmit = true;
         }
         if (statistics.ShortValue != this.shortWinTrades)
         {
             this.shortWinTrades = statistics.ShortValue;
             base.shortValue     = 0.0;
             base.shortValues.Add(base.Clock.DateTime, base.shortValue);
             isEmit = true;
         }
         if (statistics.TotalValue != this.totalWinTrades)
         {
             this.totalWinTrades = statistics.TotalValue;
             base.totalValue     = 0.0;
             base.totalValues.Add(base.Clock.DateTime, base.totalValue);
             isEmit = true;
         }
         if (isEmit)
         {
             base.Emit();
         }
     }
 }
Esempio n. 13
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.NumOfWinTrades)
     {
         bool changed = false;
         if (statistics.LongValue > this.longWinTrades)
         {
             this.longWinTrades = statistics.LongValue;
             LongValues.Add(Clock.DateTime, this.longValue += 1.0);
             changed = true;
         }
         if (statistics.ShortValue > this.shortWinTrades)
         {
             this.shortWinTrades = statistics.ShortValue;
             ShortValues.Add(Clock.DateTime, this.shortValue += 1.0);
             changed = true;
         }
         if (statistics.TotalValue > this.totalWinTrades)
         {
             this.totalWinTrades = statistics.TotalValue;
             TotalValues.Add(Clock.DateTime, this.totalValue += 1.0);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
     if (statistics.Type == PortfolioStatisticsType.NumOfLossTrades)
     {
         bool changed = false;
         if (statistics.LongValue > this.longLossTrades)
         {
             this.longLossTrades = statistics.LongValue;
             this.longValue      = 0;
             LongValues.Add(Clock.DateTime, 0);
             changed = true;
         }
         if (statistics.ShortValue > this.shortLossTrades)
         {
             this.shortLossTrades = statistics.ShortValue;
             this.shortValue      = 0;
             ShortValues.Add(Clock.DateTime, 0);
             changed = true;
         }
         if (statistics.TotalValue > this.totalLossTrades)
         {
             this.totalLossTrades = statistics.TotalValue;
             this.totalValue      = 0;
             TotalValues.Add(Clock.DateTime, 0);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
 }
Esempio n. 14
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.AnnualReturn)
     {
         this.totalValue = Pow(1 + Enumerable.Range(0, statistics.TotalValues.Count).Sum(i => statistics.TotalValues[i]) / this.initial, 1.0 / statistics.TotalValues.Count) - 1;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 15
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.AnnualReturn)
     {
         this.totalValue = Pow(1 + Enumerable.Range(0, statistics.TotalValues.Count).Sum(i => statistics.TotalValues[i]) / this.initial, 1.0 / statistics.TotalValues.Count) - 1;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 16
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.DailyDownsideRisk)
     {
         this.totalValue = AnnualizedFactor * statistics.TotalValue;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 17
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.DailyReturnPercentStdDev)
     {
         this.totalValue = this.AnnualizedFactor * statistics.TotalValue;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 18
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == 66)
     {
         this.totalValue = statistics.TotalValue * AnnualizedFactor;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 19
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.DailyDownsideRisk)
     {
         this.totalValue = AnnualizedFactor * statistics.TotalValue;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 20
0
 private void UpdateSubItem(int index, PortfolioStatisticsItem statistics)
 {
     this.SubItems[index].Text = statistics.TotalValue.ToString(statistics.Format);
     if (statistics.TotalValue < 0.0)
     {
         this.SubItems[index].ForeColor = Color.Red;
     }
     else
     {
         this.SubItems[index].ForeColor = Color.Black;
     }
 }
Esempio n. 21
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == this.type)
     {
         this.longValue = Max(this.longValue, statistics.LongValue);
         LongValues.Add(Clock.DateTime, this.longValue);
         this.shortValue = Max(this.shortValue, statistics.ShortValue);
         ShortValues.Add(Clock.DateTime, this.shortValue);
         this.totalValue = Max(this.totalValue, statistics.TotalValue);
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 22
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == this.type)
     {
         this.longValue = Min(this.longValue, statistics.LongValue);
         LongValues.Add(Clock.DateTime, this.longValue);
         this.shortValue = Min(this.shortValue, statistics.ShortValue);
         ShortValues.Add(Clock.DateTime, this.shortValue);
         this.totalValue = Min(this.totalValue, statistics.TotalValue);
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 23
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type != this.type)
     {
         return;
     }
     this.longValue  = Math.Max(this.longValue, statistics.longValue);
     this.shortValue = Math.Max(this.shortValue, statistics.shortValue);
     this.totalValue = Math.Max(this.totalValue, statistics.totalValue);
     this.longValues.Add(this.Clock.DateTime, this.longValue);
     this.shortValues.Add(this.Clock.DateTime, this.shortValue);
     this.totalValues.Add(this.Clock.DateTime, this.totalValue);
     this.Emit();
 }
Esempio n. 24
0
        private void ltvStatistics_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.ltvStatistics.SelectedIndices.Count <= 0)
            {
                return;
            }
            StatisticsViewItem statisticsViewItem = this.ltvStatistics.Items[this.ltvStatistics.SelectedIndices[0]] as StatisticsViewItem;

            if (statisticsViewItem == null)
            {
                return;
            }
            this.selectedItem = statisticsViewItem.Statistics;
            this.Invoke((Action)(() => this.Reset()));
        }
Esempio n. 25
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.NetProfit)
     {
         if (!this.method_0(statistics.TotalValue))
         {
             this.pnls.Add(statistics.TotalValue);
         }
         int num = this.pnls.Count - (int)(this.Level * (double)this.pnls.Count / 100.0) - 1;
         if (num >= 0 && num <= this.pnls.Count - 1)
         {
             this.totalValue = this.pnls[num];
             this.totalValues.Add(Clock.DateTime, this.totalValue);
             Emit();
         }
     }
 }
Esempio n. 26
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.DailyReturnPercent)
     {
         this.sumsq += Pow(Max(0, statistics.TotalValue - Threshold), 2);
         if (statistics.TotalValue < 0)
         {
             this.count++;
         }
         if (this.count > 0)
         {
             this.totalValue = Sqrt(this.sumsq / this.count);
             TotalValues.Add(Clock.DateTime, this.totalValue);
             Emit();
         }
     }
 }
Esempio n. 27
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.NetProfit)
     {
         if (!this.method_0(statistics.TotalValue))
         {
             this.pnls.Add(statistics.TotalValue);
         }
         int num = this.pnls.Count - (int)(this.Level * (double)this.pnls.Count / 100.0) - 1;
         if (num >= 0 && num <= this.pnls.Count - 1)
         {
             this.totalValue = this.pnls[num];
             this.totalValues.Add(Clock.DateTime, this.totalValue);
             Emit();
         }
     }
 }
        public static void AddStatisticsItem(this StatisticsManager manager, PortfolioStatisticsItem statisticsItem)
        {
            var i = (ICustomStatisticsType)statisticsItem;

            if (i != null)
            {
                var max = 0;
                foreach (var item in manager.Statistics)
                {
                    if (item.GetType() == statisticsItem.GetType())
                    {
                        return;
                    }
                    max = Math.Max(max, item.Type);
                }
                i.SetStatisticsType(max + 1);
            }
            manager.Add(statisticsItem);
        }
Esempio n. 29
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     bool changed = false;
     if (statistics.Type == PortfolioStatisticsType.AvgAnnualReturnPercent)
     {
         this.avgReturnPercent = statistics;
         changed = true;
     }
     if (statistics.Type == PortfolioStatisticsType.AnnualDownsideRisk)
     {
         this.downsideRisk = statistics;
         changed = true;
     }
     if (changed && this.avgReturnPercent != null && this.downsideRisk != null && this.downsideRisk.TotalValue != 0)
     {
         this.totalValue = (this.avgReturnPercent.TotalValue - RiskFreeReturn) / this.downsideRisk.TotalValue;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 30
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     var changed = false;
     if (statistics.Type == PortfolioStatisticsType.CompoundAnnualGrowthRate)
     {
         this.cagr = statistics;
         changed = true;
     }
     if (statistics.Type == PortfolioStatisticsType.MaxDrawdownPercent)
     {
         this.maxDrawdownPercent = statistics;
         changed = true;
     }
     if (changed && this.cagr != null && this.maxDrawdownPercent != null && this.maxDrawdownPercent.TotalValue != 0)
     {
         this.totalValue = Abs(this.cagr.TotalValue / this.maxDrawdownPercent.TotalValue);
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 31
0
        protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            bool changed = false;

            if (statistics.Type == PortfolioStatisticsType.GrossProfit)
            {
                this.grossProfit = statistics;
                changed          = true;
            }
            if (statistics.Type == PortfolioStatisticsType.GrossLoss)
            {
                this.grossLoss = statistics;
                changed        = true;
            }
            if (changed && this.grossProfit != null && this.grossLoss != null)
            {
                bool updated = false;
                if (this.grossLoss.LongValue != 0)
                {
                    this.longValue = this.grossProfit.LongValue / -this.grossLoss.LongValue;
                    LongValues.Add(base.Clock.DateTime, this.longValue);
                    updated = true;
                }
                if (this.grossLoss.ShortValue != 0)
                {
                    this.shortValue = this.grossProfit.ShortValue / -this.grossLoss.ShortValue;
                    ShortValues.Add(Clock.DateTime, this.shortValue);
                    updated = true;
                }
                if (this.grossLoss.TotalValue != 0.0)
                {
                    this.totalValue = this.grossProfit.TotalValue / -this.grossLoss.TotalValue;
                    TotalValues.Add(Clock.DateTime, this.totalValue);
                    updated = true;
                }
                if (updated)
                {
                    Emit();
                }
            }
        }
Esempio n. 32
0
        protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            bool changed = false;

            if (statistics.Type == PortfolioStatisticsType.NumOfWinTrades)
            {
                this.numOfWinTrades = statistics;
                changed             = true;
            }
            if (statistics.Type == PortfolioStatisticsType.NumOfTrades)
            {
                this.numOfTrades = statistics;
                changed          = true;
            }
            if (changed && this.numOfWinTrades != null && this.numOfTrades != null)
            {
                bool updated = false;
                if (this.numOfTrades.LongValue != 0)
                {
                    this.longValue = this.numOfWinTrades.LongValue / this.numOfTrades.LongValue;
                    LongValues.Add(Clock.DateTime, this.longValue);
                    updated = true;
                }
                if (this.numOfTrades.ShortValues.Count != 0)
                {
                    this.shortValue = this.numOfWinTrades.ShortValue / this.numOfTrades.ShortValue;
                    ShortValues.Add(Clock.DateTime, this.shortValue);
                    updated = true;
                }
                if (this.numOfTrades.TotalValues.Count != 0)
                {
                    this.totalValue = this.numOfWinTrades.TotalValue / this.numOfTrades.TotalValue;
                    TotalValues.Add(Clock.DateTime, this.totalValue);
                    updated = true;
                }
                if (updated)
                {
                    Emit();
                }
            }
        }
Esempio n. 33
0
        protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            bool changed = false;

            if (statistics.Type == PortfolioStatisticsType.NetProfit)
            {
                this.netProfit = statistics;
                changed        = true;
            }
            if (statistics.Type == PortfolioStatisticsType.MaxDrawdown)
            {
                this.maxDrawdown = statistics;
                changed          = true;
            }
            if (changed && this.netProfit != null && this.maxDrawdown != null)
            {
                bool updated = false;
                if (this.maxDrawdown.LongValue != 0)
                {
                    this.longValue = Abs(this.netProfit.LongValue / this.maxDrawdown.LongValue);
                    LongValues.Add(Clock.DateTime, this.longValue);
                    updated = true;
                }
                if (this.maxDrawdown.ShortValue != 0)
                {
                    this.shortValue = Abs(this.netProfit.ShortValue / this.maxDrawdown.ShortValue);
                    ShortValues.Add(Clock.DateTime, this.shortValue);
                    updated = true;
                }
                if (this.maxDrawdown.TotalValue != 0)
                {
                    this.totalValue = Math.Abs(this.netProfit.TotalValue / this.maxDrawdown.TotalValue);
                    TotalValues.Add(Clock.DateTime, this.totalValue);
                    updated = true;
                }
                if (updated)
                {
                    Emit();
                }
            }
        }
Esempio n. 34
0
        protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            bool changed = false;

            if (statistics.Type == PortfolioStatisticsType.AvgWinTrade)
            {
                this.avgWinTrades = statistics;
                changed           = true;
            }
            if (statistics.Type == PortfolioStatisticsType.AvgLossTrade)
            {
                this.avgLossTrades = statistics;
                changed            = true;
            }
            if (changed && this.avgWinTrades != null && this.avgLossTrades != null)
            {
                bool updated = false;
                if (this.avgLossTrades.LongValue != 0)
                {
                    this.longValue = Abs(this.avgWinTrades.LongValue / this.avgLossTrades.LongValue);
                    LongValues.Add(Clock.DateTime, this.longValue);
                    updated = true;
                }
                if (this.avgLossTrades.ShortValue != 0.0)
                {
                    this.shortValue = Math.Abs(this.avgWinTrades.ShortValue / this.avgLossTrades.ShortValue);
                    ShortValues.Add(Clock.DateTime, this.shortValue);
                    updated = true;
                }
                if (this.avgLossTrades.TotalValue != 0.0)
                {
                    this.totalValue = Abs(this.avgWinTrades.TotalValue / this.avgLossTrades.TotalValue);
                    TotalValues.Add(Clock.DateTime, this.totalValue);
                    updated = true;
                }
                if (updated)
                {
                    Emit();
                }
            }
        }
Esempio n. 35
0
        protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            var changed = false;

            if (statistics.Type == PortfolioStatisticsType.CompoundAnnualGrowthRate)
            {
                this.cagr = statistics;
                changed   = true;
            }
            if (statistics.Type == PortfolioStatisticsType.MaxDrawdownPercent)
            {
                this.maxDrawdownPercent = statistics;
                changed = true;
            }
            if (changed && this.cagr != null && this.maxDrawdownPercent != null && this.maxDrawdownPercent.TotalValue != 0)
            {
                this.totalValue = Abs(this.cagr.TotalValue / this.maxDrawdownPercent.TotalValue);
                TotalValues.Add(Clock.DateTime, this.totalValue);
                Emit();
            }
        }
Esempio n. 36
0
        protected override void OnStrategyInit()
        {
            bars86400 = new BarSeries("Bars86400");

            int n = N;

            if (StrategyType.RangeBreak == strategyType)
            {
                n = 1;
            }

            HH = new PriceChannel(bars86400, n, PriceChannel.CalcType.Max, PriceChannel.IncludeLast.Yes, BarData.High);
            HC = new PriceChannel(bars86400, n, PriceChannel.CalcType.Max, PriceChannel.IncludeLast.Yes, BarData.Close);
            LC = new PriceChannel(bars86400, n, PriceChannel.CalcType.Min, PriceChannel.IncludeLast.Yes, BarData.Close);
            LL = new PriceChannel(bars86400, n, PriceChannel.CalcType.Min, PriceChannel.IncludeLast.Yes, BarData.Low);

            dailyNumOfLossTrades       = Portfolio.Statistics.Get(QuantBox.Demo.Statistics.PortfolioStatisticsType.DailyNumOfLossTrades);
            dailyConsecutiveLossTrades = Portfolio.Statistics.Get(QuantBox.Demo.Statistics.PortfolioStatisticsType.DailyConsecutiveLossTrades);

            AddGroups();
        }
Esempio n. 37
0
        protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            bool changed = false;

            if (statistics.Type == PortfolioStatisticsType.AvgAnnualReturnPercent)
            {
                this.avgReturnPercent = statistics;
                changed = true;
            }
            if (statistics.Type == PortfolioStatisticsType.AnnualReturnPercentStdDev)
            {
                this.stdDev = statistics;
                changed     = true;
            }
            if (changed && this.avgReturnPercent != null && this.stdDev != null && this.stdDev.TotalValue != 0)
            {
                this.totalValue = (this.avgReturnPercent.TotalValue - RiskFreeReturn) / this.stdDev.TotalValue;
                this.totalValues.Add(Clock.DateTime, this.totalValue);
                Emit();
            }
        }
Esempio n. 38
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     bool changed = false;
     if (statistics.Type == PortfolioStatisticsType.NumOfWinTrades)
     {
         this.numOfWinTrades = statistics;
         changed = true;
     }
     if (statistics.Type == PortfolioStatisticsType.NumOfTrades)
     {
         this.numOfTrades = statistics;
         changed = true;
     }
     if (changed && this.numOfWinTrades != null && this.numOfTrades != null)
     {
         bool updated = false;
         if (this.numOfTrades.LongValue != 0)
         {
             this.longValue = this.numOfWinTrades.LongValue / this.numOfTrades.LongValue;
             LongValues.Add(Clock.DateTime, this.longValue);
             updated = true;
         }
         if (this.numOfTrades.ShortValues.Count != 0)
         {
             this.shortValue = this.numOfWinTrades.ShortValue / this.numOfTrades.ShortValue;
             ShortValues.Add(Clock.DateTime, this.shortValue);
             updated = true;
         }
         if (this.numOfTrades.TotalValues.Count != 0)
         {
             this.totalValue = this.numOfWinTrades.TotalValue / this.numOfTrades.TotalValue;
             TotalValues.Add(Clock.DateTime, this.totalValue);
             updated = true;
         }
         if (updated)
         {
             Emit();
         }
     }
 }
Esempio n. 39
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     bool changed = false;
     if (statistics.Type == PortfolioStatisticsType.AvgWinTrade)
     {
         this.avgWinTrades = statistics;
         changed = true;
     }
     if (statistics.Type == PortfolioStatisticsType.AvgLossTrade)
     {
         this.avgLossTrades = statistics;
         changed = true;
     }
     if (changed && this.avgWinTrades != null && this.avgLossTrades != null)
     {
         bool updated = false;
         if (this.avgLossTrades.LongValue != 0)
         {
             this.longValue = Abs(this.avgWinTrades.LongValue / this.avgLossTrades.LongValue);
             LongValues.Add(Clock.DateTime, this.longValue);
             updated = true;
         }
         if (this.avgLossTrades.ShortValue != 0.0)
         {
             this.shortValue = Math.Abs(this.avgWinTrades.ShortValue / this.avgLossTrades.ShortValue);
             ShortValues.Add(Clock.DateTime, this.shortValue);
             updated = true;
         }
         if (this.avgLossTrades.TotalValue != 0.0)
         {
             this.totalValue = Abs(this.avgWinTrades.TotalValue / this.avgLossTrades.TotalValue);
             TotalValues.Add(Clock.DateTime, this.totalValue);
             updated = true;
         }
         if (updated)
         {
             Emit();
         }
     }
 }
Esempio n. 40
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     bool changed = false;
     if (statistics.Type == PortfolioStatisticsType.NetProfit)
     {
         this.netProfit = statistics;
         changed = true;
     }
     if (statistics.Type == PortfolioStatisticsType.MaxDrawdown)
     {
         this.maxDrawdown = statistics;
         changed = true;
     }
     if (changed && this.netProfit != null && this.maxDrawdown != null)
     {
         bool updated = false;
         if (this.maxDrawdown.LongValue != 0)
         {
             this.longValue = Abs(this.netProfit.LongValue / this.maxDrawdown.LongValue);
             LongValues.Add(Clock.DateTime, this.longValue);
             updated = true;
         }
         if (this.maxDrawdown.ShortValue != 0)
         {
             this.shortValue = Abs(this.netProfit.ShortValue / this.maxDrawdown.ShortValue);
             ShortValues.Add(Clock.DateTime, this.shortValue);
             updated = true;
         }
         if (this.maxDrawdown.TotalValue != 0)
         {
             this.totalValue = Math.Abs(this.netProfit.TotalValue / this.maxDrawdown.TotalValue);
             TotalValues.Add(Clock.DateTime, this.totalValue);
             updated = true;
         }
         if (updated)
         {
             Emit();
         }
     }
 }
Esempio n. 41
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     bool changed = false;
     if (statistics.Type == PortfolioStatisticsType.GrossProfit)
     {
         this.grossProfit = statistics;
         changed = true;
     }
     if (statistics.Type == PortfolioStatisticsType.GrossLoss)
     {
         this.grossLoss = statistics;
         changed = true;
     }
     if (changed && this.grossProfit != null && this.grossLoss != null)
     {
         bool updated = false;
         if (this.grossLoss.LongValue != 0)
         {
             this.longValue = this.grossProfit.LongValue / -this.grossLoss.LongValue;
             LongValues.Add(base.Clock.DateTime, this.longValue);
             updated = true;
         }
         if (this.grossLoss.ShortValue != 0)
         {
             this.shortValue = this.grossProfit.ShortValue / -this.grossLoss.ShortValue;
             ShortValues.Add(Clock.DateTime, this.shortValue);
             updated = true;
         }
         if (this.grossLoss.TotalValue != 0.0)
         {
             this.totalValue = this.grossProfit.TotalValue / -this.grossLoss.TotalValue;
             TotalValues.Add(Clock.DateTime, this.totalValue);
             updated = true;
         }
         if (updated)
         {
             Emit();
         }
     }
 }
Esempio n. 42
0
        protected override void OnStatistics(PortfolioStatisticsItem statistics)
        {
            if (statistics.Type == this.type)
            {
                if (IsNewDay)
                {
                    // 减去昨天最后的数据
                    base.longValue  = statistics.LongValue - longTrades_Last;
                    base.shortValue = statistics.ShortValue - shortTrades_Last;
                    base.totalValue = statistics.TotalValue - totalTrades_Last;

                    // 本天初始化的数量
                    this.longTrades_Begin  = statistics.LongValue;
                    this.shortTrades_Begin = statistics.ShortValue;
                    this.totalTrades_Begin = statistics.TotalValue;
                }
                else
                {
                    // 当天第一轮的后几个
                    base.longValue  = statistics.LongValue - longTrades_Begin;
                    base.shortValue = statistics.ShortValue - shortTrades_Begin;
                    base.totalValue = statistics.TotalValue - totalTrades_Begin;
                }

                IsNewDay = false;

                // 一直更新,第二天早上要用
                longTrades_Last  = statistics.LongValue;
                shortTrades_Last = statistics.ShortValue;
                totalTrades_Last = statistics.TotalValue;

                base.longValues.Add(base.Clock.DateTime, base.longValue);
                base.shortValues.Add(base.Clock.DateTime, base.shortValue);
                base.totalValues.Add(base.Clock.DateTime, base.totalValue);

                base.Emit();
            }
        }
Esempio n. 43
0
        public void Update()
        {
            for (int index = 0; index < this.Portfolio.Statistics.Items.Count; ++index)
            {
                PortfolioStatisticsItem statistics = this.Portfolio.Statistics.Items[index];
                switch (statistics.Name)
                {
                case "Net Profit":
                    this.UpdateSubItem(1, statistics);
                    break;

                case "Gross Profit":
                    this.UpdateSubItem(2, statistics);
                    break;

                case "Gross Loss":
                    this.UpdateSubItem(3, statistics);
                    break;

                case "Average Drawdown %":
                    this.UpdateSubItem(4, statistics);
                    break;

                case "Maximum Drawdown %":
                    this.UpdateSubItem(5, statistics);
                    break;

                case "Profit Factor":
                    this.UpdateSubItem(6, statistics);
                    break;

                case "Recovery Factor":
                    this.UpdateSubItem(7, statistics);
                    break;
                }
            }
        }
Esempio n. 44
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.NumOfLossTrades)
     {
         bool changed = false;
         if (statistics.LongValue > this.longLossTrades)
         {
             this.longLossTrades = statistics.LongValue;
             LongValues.Add(Clock.DateTime, this.longValue += 1);
             changed = true;
         }
         if (statistics.ShortValue > this.shortLossTrades)
         {
             this.shortLossTrades = statistics.ShortValue;
             ShortValues.Add(Clock.DateTime, this.shortValue += 1.0);
             changed = true;
         }
         if (statistics.TotalValue > this.totalLossTrades)
         {
             this.totalLossTrades = statistics.TotalValue;
             TotalValues.Add(Clock.DateTime, this.totalValue += 1.0);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
     if (statistics.Type == PortfolioStatisticsType.NumOfWinTrades)
     {
         bool changed = false;
         if (statistics.LongValue > this.longWinTrades)
         {
             this.longWinTrades = statistics.LongValue;
             this.longValue = 0;
             LongValues.Add(Clock.DateTime, 0);
             changed = true;
         }
         if (statistics.ShortValue > this.shortWinTrades)
         {
             this.shortWinTrades = statistics.ShortValue;
             this.shortValue = 0;
             ShortValues.Add(Clock.DateTime, 0);
             changed = true;
         }
         if (statistics.TotalValue > this.totalWinTrades)
         {
             this.totalWinTrades = statistics.TotalValue;
             this.totalValue = 0;
             TotalValues.Add(Clock.DateTime, 0);
             changed = true;
         }
         if (changed)
         {
             Emit();
         }
     }
 }
Esempio n. 45
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.DailyReturnPercentStdDev)
     {
         this.totalValue = this.AnnualizedFactor * statistics.TotalValue;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }
Esempio n. 46
0
 private void ltvStatistics_SelectedIndexChanged(object sender, EventArgs e)
 {
   if (this.ltvStatistics.SelectedIndices.Count <= 0)
     return;
   StatisticsViewItem statisticsViewItem = this.ltvStatistics.Items[this.ltvStatistics.SelectedIndices[0]] as StatisticsViewItem;
   if (statisticsViewItem == null)
     return;
   this.selectedItem = statisticsViewItem.Statistics;
   this.Invoke((Action) (() => this.Reset()));
 }
Esempio n. 47
0
 public void Add(PortfolioStatisticsItem item) => Statistics.Add(item);
Esempio n. 48
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == PortfolioStatisticsType.DailyReturnPercent)
     {
         this.sumsq += Pow(Max(0, statistics.TotalValue - Threshold), 2);
         if (statistics.TotalValue < 0)
         {
             this.count++;
         }
         if (this.count > 0)
         {
             this.totalValue = Sqrt(this.sumsq / this.count);
             TotalValues.Add(Clock.DateTime, this.totalValue);
             Emit();
         }
     }
 }
Esempio n. 49
0
 protected internal override void OnStatistics(PortfolioStatisticsItem statistics)
 {
     if (statistics.Type == 66)
     {
         this.totalValue = statistics.TotalValue * AnnualizedFactor;
         TotalValues.Add(Clock.DateTime, this.totalValue);
         Emit();
     }
 }