Exemple #1
0
        /// <summary>
        /// Calculates the total gain / total loss ratio.
        /// Depends on 4 cases, and the result will be presented depending on those.
        /// 1. If we have no trades, profit factor is 0.
        /// 2. If we only have winning trades profit factor gets capped to 100.
        /// 3. If we only have losingtrades profit factor is 0.
        /// 4. If we have both winning and losing trades, profit factor is calculated.
        /// </summary>
        public double ProfitFactor(TradeManager tradeList)
        {
            double lossLosingTrades  = 0;
            double gainWinningTrades = 0;

            SummerizeProfit(ref lossLosingTrades, ref gainWinningTrades, tradeList);
            return(ReturnProfitfactorFromRules(lossLosingTrades, gainWinningTrades));
        }
Exemple #2
0
        public int NumberOfFinishedTrades(TradeManager tradeList)
        {
            int nbrFinishedTrades = 0;

            foreach (var item in tradeList.GetTradeList)
            {
                if (item.Finished)
                {
                    nbrFinishedTrades++;
                }
            }
            return(nbrFinishedTrades);
        }
Exemple #3
0
        public int NbrOfWinners(TradeManager tradeList)
        {
            int nbrWinners = 0;

            foreach (var item in tradeList.GetTradeList)
            {
                if (item.ProfitTrade() > 0 && item.Finished)
                {
                    nbrWinners++;
                }
            }
            return(nbrWinners);
        }
Exemple #4
0
        public double TotalLoss(TradeManager tradelist)
        {
            double totalLoss = 0;

            foreach (var item in tradelist.GetTradeList)
            {
                if (item.ProfitTrade() < 0 && item.Finished)
                {
                    totalLoss += item.ProfitTrade() / item.Sell * _valuePerPoint;
                }
            }

            return(Math.Abs(totalLoss));
        }
Exemple #5
0
        public double TotalGain(TradeManager tradelist)
        {
            double totalGain = 0;

            foreach (var item in tradelist.GetTradeList)
            {
                if (item.ProfitTrade() > 0 && item.Finished)
                {
                    totalGain += item.ProfitTrade() / item.Sell * _valuePerPoint;
                }
            }

            return(totalGain);
        }
Exemple #6
0
        public double AverageProfit(TradeManager tradeList)
        {
            double sumProfitInSek = 0;

            foreach (var item in tradeList.GetTradeList)
            {
                sumProfitInSek += item.ProfitTrade() / item.Sell * _valuePerPoint;
            }

            if (tradeList.NbrFinishedTrades() == 0)
            {
                return(0);
            }
            else
            {
                return(sumProfitInSek / tradeList.NbrFinishedTrades());
            }
        }
Exemple #7
0
        public double StandardDeviation(TradeManager tradeList)
        {
            double sumSquaredDevFromMean = 0;

            foreach (var item in tradeList.GetTradeList)
            {
                sumSquaredDevFromMean += Math.Pow(item.ProfitTrade() / item.Sell * _valuePerPoint - AverageProfit(tradeList), 2);
            }

            if (tradeList.NbrFinishedTrades() == 0)
            {
                return(0);
            }
            else
            {
                return(Math.Sqrt(sumSquaredDevFromMean / tradeList.NbrFinishedTrades()));
            }
        }
Exemple #8
0
        public double AverageLoss(TradeManager tradeList)
        {
            double nbrLosers = 0;
            double totalLoss = 0;

            foreach (var item in tradeList.GetTradeList)
            {
                if (item.ProfitTrade() < 0 && item.Finished)
                {
                    totalLoss += item.ProfitTrade() / item.Sell * _valuePerPoint;
                    nbrLosers++;
                }
            }

            if (nbrLosers == 0)
            {
                return(0);
            }
            else
            {
                return(Math.Abs(totalLoss / nbrLosers));
            }
        }
Exemple #9
0
        public double AverageGain(TradeManager tradeList)
        {
            double nbrWinners = 0;
            double totalGain  = 0;

            foreach (var item in tradeList.GetTradeList)
            {
                if (item.ProfitTrade() > 0 && item.Finished)
                {
                    totalGain += item.ProfitTrade() / item.Sell * _valuePerPoint;
                    nbrWinners++;
                }
            }

            if (nbrWinners == 0)
            {
                return(0);
            }
            else
            {
                return(totalGain / nbrWinners);
            }
        }
Exemple #10
0
        public OneStockBackTestData GetOneStockBacktest(TradeManager _tradeManager, List <DailyDataPoint> _dataList, string algoName, string stockName, DateTime startDate, DateTime endDate)
        {
            var backTestData = new OneStockBackTestData();

            backTestData.AlgoName               = algoName;
            backTestData.Ticker                 = stockName;
            backTestData.TimeSpanStart          = startDate.ToShortDateString();
            backTestData.TimeSpanFinish         = endDate.ToShortDateString();
            backTestData.PortfolioValueStart    = PortfolioValueStart;
            backTestData.PortfolioValueFinish   = PortfolioValue;
            backTestData.ReturnSek              = ReturnSek();
            backTestData.ReturnProcent          = ReturnProcent();
            backTestData.NumberOfFinishedTrades = NumberOfFinishedTrades(_tradeManager);
            backTestData.Winners                = WinnersPercent(_tradeManager);
            backTestData.TotalGain              = TotalGain(_tradeManager);
            backTestData.TotalLoss              = TotalLoss(_tradeManager);
            backTestData.AverageGain            = AverageGain(_tradeManager);
            backTestData.AverageLoss            = AverageLoss(_tradeManager);
            backTestData.ProfitFactor           = ProfitFactor(_tradeManager);
            backTestData.Cagr               = Cagr(_dataList, startDate, endDate);
            backTestData.SharpRatio         = SharpRatio(_tradeManager, _dataList, startDate, endDate);
            backTestData.MaxDrawDownPercent = MaxDrawDownProp;
            return(backTestData);
        }
Exemple #11
0
 private double SharpRatioFromRules(double top, double bottom, TradeManager tradeList)
 {
     // If only one trade there is no variance and sharp ratio is useless, ie bottom is 0.
     if (top > 0 && bottom == 0)
     {
         return(100);
     }
     else if (top < 0 && bottom == 0)
     {
         return(-100);
     }
     else if (NumberOfFinishedTrades(tradeList) == 0)
     {
         return(0);
     }
     else if (top <= -100)
     {
         return(-100);
     }
     else
     {
         return(top / bottom);
     }
 }
Exemple #12
0
 public NegMaImpuls(List <DailyDataPoint> dataList, int index, TradeManager tradeManager)
 {
     _dataList     = dataList;
     _index        = index;
     _tradeManager = tradeManager;
 }
Exemple #13
0
 /// <summary>
 /// Portfolio value after a trade
 /// </summary>
 public double ChangePortFolValue(TradeManager tradeList, int index)
 {
     _portfolioValue += (tradeList.GetTradeList[index].ProfitTrade() / tradeList.GetTradeList[index].Sell) * _valuePerPoint;
     return(_portfolioValue);
 }
Exemple #14
0
 private void SummerizeProfit(ref double lossLosingTrades, ref double gainWinningTrades, TradeManager tradeList)
 {
     foreach (var item in tradeList.GetTradeList)
     {
         if (item.ProfitTrade() > 0 && item.Finished)
         {
             gainWinningTrades += item.ProfitTrade() / item.Sell * _valuePerPoint;
         }
         else if (item.ProfitTrade() < 0 && item.Finished)
         {
             lossLosingTrades += item.ProfitTrade() / item.Sell * _valuePerPoint;
         }
     }
 }
 public AlgoPicker(List <DailyDataPoint> dataList, string nameOFAlgo, TradeManager tradeManager)
 {
     _dataList     = dataList;
     _nameOfAlgo   = nameOFAlgo;
     _tradeManager = tradeManager;
 }
 private void InitializeBacktest()
 {
     _tradeManager = new TradeManager();
     _backtest     = new Backtest(100000, 30000);
 }