Пример #1
0
        public virtual double GetAllPositionsUnrealizedPnL(PerformanceUnit unit)
        {
            double pnl = 0;

            if (IsLiveTrading())
            {
                for (int i = 0; i < Positions.Length; i++)
                {
                    if (PositionsAccount[i].MarketPosition != MarketPosition.Flat)
                    {
                        pnl = pnl + PositionsAccount[i].GetUnrealizedProfitLoss(unit, Closes[i][0]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < Positions.Length; i++)
                {
                    if (Positions[i].MarketPosition != MarketPosition.Flat)
                    {
                        pnl = pnl + Positions[i].GetUnrealizedProfitLoss(unit, Closes[i][0]);
                    }
                }
            }
            return(pnl);
        }
Пример #2
0
        public void GetMarkedMethods_TestMethodHasAttribute_ReturnstestMethod()
        {
            var analyzer = new Analyzer();
            IEnumerable <PerformanceSet> sets = analyzer.GetPerformanceSets((typeof(Test).Assembly));
            PerformanceSet  set  = sets.First();
            PerformanceUnit unit = set.PerformanceUnits.First();


            Assert.AreEqual("TestMethod", unit.Name);
        }
Пример #3
0
        public void Build_BuildAnActionFromTypeAndMethodInfo_ReturnsActionThatDoesNotThrow()
        {
            var             analyzer        = new Analyzer();
            PerformanceSet  set             = analyzer.GetPerformanceSets((typeof(Test).Assembly)).First();
            PerformanceUnit performanceUnit = set.PerformanceUnits.First();

            var builder = new DelegateBuilder();

            Action action = builder.Build(set.Type, performanceUnit.MethodInfo);

            Assert.DoesNotThrow(action.Invoke);
        }
Пример #4
0
        public virtual double GetPairTotalCommission(PerformanceUnit unit)
        {
            double com0, com1;

            if (IsLiveTrading())
            {
                com0 = SystemPerformance.RealTimeTrades.TradesPerformance.TotalCommission;
                //sp1 = PositionsAccount[1].GetUnrealizedProfitLoss(unit, Closes[1][0]);
            }
            else
            {
                com0 = SystemPerformance.AllTrades.TradesPerformance.TotalCommission;
                //sp1 = SystemPerformance.AllTrades.ByDay
            }
            return(com0);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="unit">one tick for stock is $0.01,
        /// the total $$ amount will be 100*totalSlippage</param>
        /// <returns></returns>
        public virtual double GetPairTotalSlippage(PerformanceUnit unit)
        {
            double sp0, sp1;

            if (IsLiveTrading())
            {
                sp0 = SystemPerformance.RealTimeTrades.TradesPerformance.TotalSlippage;
                //sp1 = PositionsAccount[1].GetUnrealizedProfitLoss(unit, Closes[1][0]);
            }
            else
            {
                sp0 = SystemPerformance.AllTrades.TradesPerformance.TotalSlippage;
                //sp1 = SystemPerformance.AllTrades.ByDay
            }
            return(sp0);
        }
Пример #6
0
        public virtual double GetPairGrossPnL(PerformanceUnit unit)
        {
            double pnl0;

            if (IsLiveTrading())
            {
                pnl0 = SystemPerformance.RealTimeTrades.TradesPerformance.GrossLoss
                       + SystemPerformance.RealTimeTrades.TradesPerformance.GrossProfit;
            }
            else
            {
                pnl0 = SystemPerformance.AllTrades.TradesPerformance.GrossLoss
                       + SystemPerformance.AllTrades.TradesPerformance.GrossProfit;
            }
            return(pnl0);
        }
Пример #7
0
        public virtual double GetPairUnrealizedPnL(PerformanceUnit unit)
        {
            double pnl0, pnl1;

            if (IsLiveTrading())
            {
                pnl0 = PositionsAccount[0].GetUnrealizedProfitLoss(unit, Closes[0][0]);
                pnl1 = PositionsAccount[1].GetUnrealizedProfitLoss(unit, Closes[1][0]);
            }
            else
            {
                pnl0 = Positions[0].GetUnrealizedProfitLoss(unit, Closes[0][0]);
                pnl1 = Positions[1].GetUnrealizedProfitLoss(unit, Closes[1][0]);
            }
            return(pnl0 + pnl1);
        }
Пример #8
0
        PerformanceUnit AddPerformanceReport(GPUProgram gpuProgram, int multicompileIndex, string rawReport, ProgramPerformanceMetrics parsedReport)
        {
            var programIndex = m_Programs.IndexOf(gpuProgram);

            var unit = new PerformanceUnit(this, programIndex, multicompileIndex, rawReport, parsedReport);

            m_PerformanceUnit.Add(unit);

            if (!m_ProgramPerformanceUnits.ContainsKey(unit.programIndex))
            {
                m_ProgramPerformanceUnits[unit.programIndex] = new Dictionary <int, int>();
            }

            m_ProgramPerformanceUnits[unit.programIndex][unit.multicompileIndex] = m_PerformanceUnit.Count - 1;

            return(unit);
        }
Пример #9
0
        public void Run_RunsAMarkedMethodOneHundredTimes_ReturnsResultWithOneHundredResults()
        {
            var analyzer = new Analyzer();
            IEnumerable <PerformanceSet> sets = analyzer.GetPerformanceSets((typeof(Test).Assembly));
            PerformanceSet  set  = sets.First();
            PerformanceUnit unit = set.PerformanceUnits.First();

            MethodInfo methodInfo = unit.MethodInfo;

            var    builder = new DelegateBuilder();
            Action action  = builder.Build(set.Type, methodInfo);

            var runner = new UnitRunner();

            Result result = runner.Run(set.Name, methodInfo.Name, action, unit.Runs);

            Assert.IsTrue(result.Success);
        }
Пример #10
0
        public virtual double GetTotalCapitalTraded(PerformanceUnit unit)
        {
            double capTotal = 0;

            if (IsLiveTrading())
            {
                foreach (Trade td in SystemPerformance.RealTimeTrades)
                {
                    capTotal = capTotal + td.Entry.Price * td.Entry.Quantity;
                }
            }
            else
            {
                foreach (Trade td in SystemPerformance.AllTrades)
                {
                    capTotal = capTotal + td.Entry.Price * td.Entry.Quantity;
                }
                //sp1 = SystemPerformance.AllTrades.ByDay
            }
            return(capTotal);
        }
Пример #11
0
        public virtual TradeCollection GetTradesToday(PerformanceUnit unit)
        {
            TradeCollection tdtoday = null;
            Dictionary <object, TradeCollection> dt;
            DateTime now = Time[0].Date;

            if (IsLiveTrading())
            {
//				foreach(Trade td in SystemPerformance.RealTimeTrades) {
//					capTotal = capTotal + td.Entry.Price * td.Entry.Quantity;
//				}
                dt = SystemPerformance.RealTimeTrades.ByDay;
//				foreach(var item in dt){
//					Print(string.Format("ByDayRT: k={0}, v={1}", item.Key, item.Value));
//				}
            }
            else
            {
//				foreach(Trade td in SystemPerformance.AllTrades) {
//					capTotal = capTotal + td.Entry.Price * td.Entry.Quantity;
//				}
                dt = SystemPerformance.AllTrades.ByDay;
//				foreach(var item in dt){
//					Print(string.Format("ByDay: k={0}, ktype={1}, v={2}, tdtoday={3}",
//						item.Key, item.Key.GetType(), item.Value, tdtoday));
//				}
            }
            if (dt != null)
            {
                dt.TryGetValue(now, out tdtoday);
            }
            if (tdtoday != null)
            {
                Print(string.Format("ByDay tdtoday: now={0}, tdtoday={1}, count={2}, TradesCount={3}",
                                    now, tdtoday, tdtoday.Count, tdtoday.TradesCount));
            }
            return(tdtoday);
        }