Exemplo n.º 1
0
        public string GetTransactionReport()
        {
            string report = "";

            for (int i = 0; i < _traderAgent.Agents.Count; i++)
            {
                AbstractStrategy abstracttrader = (AbstractStrategy)_traderAgent.Agents[i];
                //report += "Instrument:\t\t\t\t\t" + abstracttrader._instrument.Name + "\r\n";
                report += "Date range:\t\t\t" + GetStartDate().ToShortDateString() + " - " + GetEndDate().ToShortDateString() + "\r\n";
                report += "Initial Balance:\t\t\t" + abstracttrader.Account.InitialBalance.ToString() + "\r\n";
                report += "Total bars:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getDays().ToString() + "\r\n";
                report += "Total transactions:\t\t" + TotalTransactions.ToString() + "\r\n";
                report += "Total bars held:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).TotalHeldBars.ToString() + "\r\n";
                report += "Total bars won:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getUpPosDays().ToString() + "\r\n";
                report += "Total bars even:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getEvenPosDays().ToString() + "\r\n";
                report += "Total bars lost:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getDownPosDays().ToString() + "\r\n";
                report += "Maximum consecutive wins:\t\t" + ((Statistics)_traderstats[abstracttrader]).MaximumConsectutiveWinBars.ToString() + "\r\n";
                report += "Average consecutive wins:\t\t" + ((Statistics)_traderstats[abstracttrader]).AverageConsectutiveWinBars.ToString() + "\r\n";
                report += "Maximum consecutive even:\t\t" + ((Statistics)_traderstats[abstracttrader]).MaximumConsectutiveEvenBars.ToString() + "\r\n";
                report += "Average consecutive even:\t\t" + ((Statistics)_traderstats[abstracttrader]).AverageConsectutiveEvenBars.ToString() + "\r\n";
                report += "Maximum consecutive losses:\t\t" + ((Statistics)_traderstats[abstracttrader]).MaximumConsectutiveLoseBars.ToString() + "\r\n";
                report += "Average consecutive losses:\t\t" + ((Statistics)_traderstats[abstracttrader]).AverageConsectutiveLoseBars.ToString() + "\r\n";
                report += "Maximum bar profit:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getMaximumPosWin().ToString() + "\r\n";
                report += "Maximum bar loss:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getMaximumPosLoss().ToString() + "\r\n";
                report += "Total Profit/Loss:\t\t\t" + TotalPnL.ToString() + "\r\n";
                report += "Risk:\t\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getMeanRisk().ToString() + "\r\n";
                //report += "Score:\t\t\t\t" + TotalScore.ToString() + "\r\n";
                report += "Transactions:\t\t\t" + ((Transaction)abstracttrader.Account.Transactions[0]).Date.ToShortDateString() + ", " + ((Transaction)abstracttrader.Account.Transactions[0]).Quantity.ToString() + ", " + ((Transaction)abstracttrader.Account.Transactions[0]).Amount.ToString() + ", " + (double)(Math.Abs(((Transaction)abstracttrader.Account.Transactions[0]).Amount) / Math.Abs(((Transaction)abstracttrader.Account.Transactions[0]).Quantity)) + "\r\n";
                for (int x = 1; x < abstracttrader.Account.Transactions.Count; x++)
                {
                    report += "\t\t\t\t" + ((Transaction)abstracttrader.Account.Transactions[x]).Date.ToShortDateString() + ", " + ((Transaction)abstracttrader.Account.Transactions[x]).Quantity.ToString() + ", " + ((Transaction)abstracttrader.Account.Transactions[x]).Amount.ToString() + ", " + (double)(Math.Abs(((Transaction)abstracttrader.Account.Transactions[x]).Amount) / Math.Abs(((Transaction)abstracttrader.Account.Transactions[x]).Quantity)) + "\r\n";
                }
            }
            return(report);
        }
Exemplo n.º 2
0
        public string GetReport()
        {
            string report = "";

            for (int i = 0; i < _traderAgent.Agents.Count; i++)
            {
                AbstractStrategy abstracttrader = (AbstractStrategy)_traderAgent.Agents[i];
                //report += "Instrument:\t\t\t\t\t" + abstracttrader._instrument.Name + "\r\n";
                report += "Date range:\t\t\t" + GetStartDate().ToShortDateString() + " - " + GetEndDate().ToShortDateString() + "\r\n";
                report += "Total bars:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getDays().ToString() + "\r\n";
                report += "Total transactions:\t\t\t" + TotalTransactions.ToString() + "\r\n";
                report += "Total bars held:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).TotalHeldBars.ToString() + "\r\n";
                report += "Total bars won:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getUpPosDays().ToString() + "\r\n";
                report += "Total bars even:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getEvenPosDays().ToString() + "\r\n";
                report += "Total bars lost:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getDownPosDays().ToString() + "\r\n";
                report += "Maximum consecutive wins:\t\t" + ((Statistics)_traderstats[abstracttrader]).MaximumConsectutiveWinBars.ToString() + "\r\n";
                report += "Average consecutive wins:\t\t" + ((Statistics)_traderstats[abstracttrader]).AverageConsectutiveWinBars.ToString() + "\r\n";
                report += "Maximum consecutive even:\t\t" + ((Statistics)_traderstats[abstracttrader]).MaximumConsectutiveEvenBars.ToString() + "\r\n";
                report += "Average consecutive even:\t\t" + ((Statistics)_traderstats[abstracttrader]).AverageConsectutiveEvenBars.ToString() + "\r\n";
                report += "Maximum consecutive losses:\t\t" + ((Statistics)_traderstats[abstracttrader]).MaximumConsectutiveLoseBars.ToString() + "\r\n";
                report += "Average consecutive losses:\t\t" + ((Statistics)_traderstats[abstracttrader]).AverageConsectutiveLoseBars.ToString() + "\r\n";
                report += "Maximum bar profit:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getMaximumPosWin().ToString() + "\r\n";
                report += "Maximum bar loss:\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getMaximumPosLoss().ToString() + "\r\n";
                report += "Total Profit/Loss:\t\t\t" + TotalPnL.ToString() + "\r\n";
                report += "Risk:\t\t\t\t" + ((Statistics)_traderstats[abstracttrader]).getMeanRisk().ToString() + "\r\n";
                //report += "Score:\t\t\t\t" + TotalScore.ToString();
            }

            return(report);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="trader"></param>
        internal virtual void AddTrader(AbstractStrategy strategy)
        {
            Account account = _account;

            _agents.Add(strategy);
            strategy.Account    = account;
            _accounts[strategy] = account;
        }
Exemplo n.º 4
0
 private void UpdateStatistics()
 {
     for (int i = 0; i < _traderAgent.Agents.Count; i++)
     {
         AbstractStrategy abstracttrader = (AbstractStrategy)_traderAgent.Agents[i];
         ((Statistics)_traderstats[abstracttrader]).Update(abstracttrader.GetPosition(""), abstracttrader.GetCash(), abstracttrader.GetValue());
     }
 }
Exemplo n.º 5
0
 private void pushEval()
 {
     double[] af = new double[_traders.Count];
     for (int i = 0; i < _traders.Count; i++)
     {
         AbstractStrategy abstracttrader = (AbstractStrategy)_traders[i];
         af[i] = abstracttrader.GetPnL();
     }
     _evalHistory.Insert(0, af);
 }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 internal virtual void ClearOrders()
 {
     for (System.Collections.IEnumerator it = _agents.GetEnumerator(); it.MoveNext();)
     {
         AbstractStrategy trader = (AbstractStrategy)it.Current;
         if (!(trader.GetPendingOrders().Count == 0))
         {
             trader.GetPendingOrders().Clear();
         }
     }
 }
Exemplo n.º 7
0
 internal virtual void ClosePosition()
 {
     for (System.Collections.IEnumerator it = _agents.GetEnumerator(); it.MoveNext();)
     {
         AbstractStrategy trader = (AbstractStrategy)it.Current;
         if (trader.GetPosition(trader._instrument.Name) != 0)
         {
             trader.AddQuantityOrder(trader._instrument.Name, -trader.GetPosition(trader._instrument.Name));
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 public virtual void Initialize()
 {
     for (System.Collections.IEnumerator it = _agents.GetEnumerator(); it.MoveNext();)
     {
         AbstractStrategy trader  = (AbstractStrategy)it.Current;
         Account          account = (Account)_accounts[trader];
         trader.Market  = _market;
         account.Market = _market;
         account.init();
         trader.Initialize();
     }
 }
Exemplo n.º 9
0
 private void UpdateCumulative()
 {
     for (int i = 0; i < _traderAgent.Agents.Count; i++)
     {
         AbstractStrategy abstracttrader = (AbstractStrategy)_traderAgent.Agents[i];
         double           score          = (abstracttrader.GetTransactionCount() == 0) ? 0 : abstracttrader.GetPnL() / (abstracttrader.GetDaysHeld() / abstracttrader.GetTransactionCount());
         double           transactions   = abstracttrader.GetTransactionCount();
         double           pnl            = abstracttrader.GetPnL();
         //double days = abstracttrader.GetDaysHeld();
         total             += score;
         totalpnl          += pnl;
         totaltransactions += transactions;
         //totaldays += days;
     }
 }
Exemplo n.º 10
0
 public void onStarted()
 {
     _dateStart   = new DateTime();
     _dateCurrent = new DateTime();
     _dateEnd     = new DateTime();
     _year        = 0;
     for (int i = 0; i < _traderAgent.Agents.Count; i++)
     {
         AbstractStrategy abstracttrader = (AbstractStrategy)_traderAgent.Agents[i];
         ((Statistics)_traderstats[abstracttrader]).setLastEval(abstracttrader.GetValue());
     }
     for (int i = 0; i < _observers.Count; i++)
     {
         ((Observer)_observers[i]).onStarted();
     }
 }
Exemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 internal virtual void ProcessOrders()
 {
     for (System.Collections.IEnumerator it = _agents.GetEnumerator(); it.MoveNext();)
     {
         AbstractStrategy trader = (AbstractStrategy)it.Current;
         if (!(trader.GetPendingOrders().Count == 0))
         {
             Account account = (Account)_accounts[trader];
             for (System.Collections.IEnumerator itord = trader.GetPendingOrders().GetEnumerator(); itord.MoveNext();)
             {
                 Order order = (Order)itord.Current;
                 ProcessOrder(trader, account, order);
             }
             trader.GetPendingOrders().Clear();
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="trader"></param>
        /// <param name="account"></param>
        /// <param name="order"></param>
        private void ProcessOrder(AbstractStrategy trader, Account account, Order order)
        {
            double result = 0;

            if (order.Type)
            {
                result = account.NewQuantityTransaction(order.Instrument, order.Value);
            }
            else
            {
                result = account.NewCashTransaction(order.Instrument, order.Value);
            }
            trader.GetTickEvents().Clear();
            if (result == 0)
            {
                trader.GetTickEvents().Add(new TransactionEvent(TransactionEvent.ORDER_REJECT));
            }
            else
            {
                trader.GetTickEvents().Add(new TransactionEvent(TransactionEvent.ORDER_EXEC));
            }
        }
Exemplo n.º 13
0
 /// <summary> Adds a new trader to the TraderContainer, it also creates a new IAccount
 /// for the trader, this must be use before starting the engine.
 ///
 /// </summary>
 /// <param name="">trader
 /// </param>
 public virtual void register(AbstractStrategy trader)
 {
     _trader.AddTrader(trader);
 }
Exemplo n.º 14
0
        public Statistics GetStatistics()
        {
            AbstractStrategy abstracttrader = (AbstractStrategy)_traderAgent.Agents[0];

            return((Statistics)_traderstats[abstracttrader]);
        }