Exemplo n.º 1
0
        private TradingResult PerformBackTesting( SystemResult systemResult )
        {
            if ( systemResult.Prices.Empty() || systemResult.Signals.Empty() )
            {
                return null;
            }

            const int InitialCash = 10000;
            var tradingLog = new TradingLog();
            var portfolio = new Portfolio( InitialCash, Broker, tradingLog );

            foreach ( var signal in systemResult.Signals )
            {
                if ( signal.Value.Type == SignalType.Buy )
                {
                    var price = systemResult.Prices[ signal.Time ];
                    portfolio.Buy( signal.Time, price.Value );
                }
                else if ( signal.Value.Type == SignalType.Sell )
                {
                    var price = systemResult.Prices[ signal.Time ];
                    portfolio.Sell( signal.Time, price.Value );
                }
            }

            return new TradingResult( systemResult )
            {
                TradingTimeSpan = systemResult.Prices.Last().Time - systemResult.Prices.First().Time,
                TradingLog = tradingLog,
                InitialCash = InitialCash,
                PortfolioValue = portfolio.GetValue( systemResult.Prices.Last().Value )
            };
        }
Exemplo n.º 2
0
        private TradingResult PerformBackTesting(SystemResult systemResult)
        {
            if (systemResult.Prices.Empty() || systemResult.Signals.Empty())
            {
                return(null);
            }

            const int InitialCash = 10000;
            var       tradingLog  = new TradingLog();
            var       portfolio   = new Portfolio(InitialCash, Broker, tradingLog);

            foreach (var signal in systemResult.Signals)
            {
                if (signal.Value.Type == SignalType.Buy)
                {
                    var price = systemResult.Prices[signal.Time];
                    portfolio.Buy(signal.Time, price.Value);
                }
                else if (signal.Value.Type == SignalType.Sell)
                {
                    var price = systemResult.Prices[signal.Time];
                    portfolio.Sell(signal.Time, price.Value);
                }
            }

            return(new TradingResult(systemResult)
            {
                TradingTimeSpan = systemResult.Prices.Last().Time - systemResult.Prices.First().Time,
                TradingLog = tradingLog,
                InitialCash = InitialCash,
                PortfolioValue = portfolio.GetValue(systemResult.Prices.Last().Value)
            });
        }
Exemplo n.º 3
0
        public Portfolio(double cash, IBroker broker, TradingLog tradingLog)
        {
            myCash       = cash;
            myBroker     = broker;
            myTradingLog = tradingLog;

            myQuantity = 0;
        }
Exemplo n.º 4
0
        public Portfolio( double cash, IBroker broker, TradingLog tradingLog )
        {
            myCash = cash;
            myBroker = broker;
            myTradingLog = tradingLog;

            myQuantity = 0;
        }