Ejemplo n.º 1
0
        /// <summary>
        /// Setup the algorithm cash, dates and portfolio as desired.
        /// </summary>
        /// <param name="algorithm">Existing algorithm instance</param>
        /// <param name="brokerage">New brokerage instance</param>
        /// <param name="baseJob">Backtesting job</param>
        /// <returns>Boolean true on successfully setting up the console.</returns>
        public bool Setup(IAlgorithm algorithm, out IBrokerage brokerage, AlgorithmNodePacket baseJob)
        {
            var initializeComplete = false;

            brokerage = new BacktestingBrokerage(algorithm);

            try
            {
                //Set common variables for console programs:

                if (baseJob.Type == PacketType.BacktestNode)
                {
                    var backtestJob = baseJob as BacktestNodePacket;

                    //Set the limits on the algorithm assets (for local no limits)
                    algorithm.SetAssetLimits(999, 999, 999);
                    algorithm.SetMaximumOrders(int.MaxValue);

                    //Setup Base Algorithm:
                    algorithm.Initialize();
                    //Add currency data feeds that weren't explicity added in Initialize
                    algorithm.Portfolio.CashBook.EnsureCurrencyDataFeeds(algorithm.SubscriptionManager, algorithm.Securities);

                    //Construct the backtest job packet:
                    backtestJob.PeriodStart  = algorithm.StartDate;
                    backtestJob.PeriodFinish = algorithm.EndDate;
                    backtestJob.BacktestId   = "LOCALHOST";
                    backtestJob.UserId       = 1001;
                    backtestJob.Type         = PacketType.BacktestNode;

                    //Endpoints:
                    backtestJob.TransactionEndpoint = TransactionHandlerEndpoint.Backtesting;
                    backtestJob.ResultEndpoint      = ResultHandlerEndpoint.Console;
                    backtestJob.DataEndpoint        = DataFeedEndpoint.FileSystem;
                    backtestJob.RealTimeEndpoint    = RealTimeEndpoint.Backtesting;
                    backtestJob.SetupEndpoint       = SetupHandlerEndpoint.Console;

                    //Backtest Specific Parameters:
                    StartingDate    = backtestJob.PeriodStart;
                    StartingCapital = algorithm.Portfolio.Cash;
                }
                else
                {
                    var liveJob = baseJob as LiveNodePacket;

                    //Live Job Parameters:
                    liveJob.DeployId     = "LOCALHOST";
                    liveJob.IssuedAt     = DateTime.Now.Subtract(TimeSpan.FromSeconds(86399 - 60)); //For testing, first access token expires in 60 sec. refresh.
                    liveJob.LifeTime     = TimeSpan.FromSeconds(86399);
                    liveJob.AccessToken  = "123456";
                    liveJob.AccountId    = "123456";
                    liveJob.RefreshToken = "";
                    liveJob.Type         = PacketType.LiveNode;

                    //Endpoints:
                    liveJob.TransactionEndpoint = TransactionHandlerEndpoint.Backtesting;
                    liveJob.ResultEndpoint      = ResultHandlerEndpoint.LiveTrading;
                    liveJob.DataEndpoint        = DataFeedEndpoint.LiveTrading;
                    liveJob.RealTimeEndpoint    = RealTimeEndpoint.LiveTrading;
                    liveJob.SetupEndpoint       = SetupHandlerEndpoint.Console;

                    //Call in the paper trading setup:
                    var setup = new PaperTradingSetupHandler();
                    setup.Setup(algorithm, out brokerage, baseJob);

                    //Live Specific Parameters:
                    StartingDate    = DateTime.Now;
                    StartingCapital = algorithm.Portfolio.Cash;
                }
            }
            catch (Exception err)
            {
                Log.Error("ConsoleSetupHandler().Setup(): " + err.Message);
                Errors.Add("Failed to initialize algorithm: Initialize(): " + err.Message);
            }

            if (Errors.Count == 0)
            {
                initializeComplete = true;
            }

            return(initializeComplete);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Setup the algorithm cash, dates and portfolio as desired.
        /// </summary>
        /// <param name="algorithm">Existing algorithm instance</param>
        /// <param name="brokerage">New brokerage instance</param>
        /// <param name="baseJob">Backtesting job</param>
        /// <returns>Boolean true on successfully setting up the console.</returns>
        public bool Setup(IAlgorithm algorithm, out IBrokerage brokerage, AlgorithmNodePacket baseJob)
        {
            var initializeComplete = false;

            brokerage = new BacktestingBrokerage(algorithm);

            try
            {
                //Set common variables for console programs:

                if (baseJob.Type == PacketType.BacktestNode)
                {
                    var backtestJob = baseJob as BacktestNodePacket;
                    //Setup Base Algorithm:
                    algorithm.Initialize();

                    //Construct the backtest job packet:
                    backtestJob.PeriodStart  = algorithm.StartDate;
                    backtestJob.PeriodFinish = algorithm.EndDate;
                    backtestJob.BacktestId   = "LOCALHOST";
                    backtestJob.UserId       = 1001;
                    backtestJob.Type         = PacketType.BacktestNode;

                    //Endpoints:
                    backtestJob.TransactionEndpoint = TransactionHandlerEndpoint.Backtesting;
                    backtestJob.ResultEndpoint      = ResultHandlerEndpoint.Console;
                    backtestJob.DataEndpoint        = DataFeedEndpoint.FileSystem;
                    backtestJob.RealTimeEndpoint    = RealTimeEndpoint.Backtesting;
                    backtestJob.SetupEndpoint       = SetupHandlerEndpoint.Console;

                    //Backtest Specific Parameters:
                    StartingDate    = backtestJob.PeriodStart;
                    StartingCapital = algorithm.Portfolio.Cash;
                }
                else
                {
                    var liveJob = baseJob as LiveNodePacket;

                    //Live Job Parameters:
                    liveJob.UserId       = liveJob.UserId;
                    liveJob.DeployId     = "LOCALHOST";
                    liveJob.IssuedAt     = DateTime.Now.Subtract(TimeSpan.FromSeconds(86399 - 60)); //For testing, first access token expires in 60 sec. refresh.
                    liveJob.LifeTime     = TimeSpan.FromSeconds(86399);
                    liveJob.AccessToken  = "123456";
                    liveJob.AccountId    = 123456;
                    liveJob.RefreshToken = "";
                    liveJob.Type         = PacketType.LiveNode;

                    //Endpoints:
                    liveJob.TransactionEndpoint = TransactionHandlerEndpoint.Backtesting;
                    liveJob.ResultEndpoint      = ResultHandlerEndpoint.LiveTrading;

                    bool testLiveTradingEnabled = Config.GetBool("test-live-trading-enabled", defaultValue: false);
                    liveJob.DataEndpoint     = testLiveTradingEnabled ? DataFeedEndpoint.Test : DataFeedEndpoint.LiveTrading;
                    liveJob.RealTimeEndpoint = RealTimeEndpoint.LiveTrading;
                    liveJob.SetupEndpoint    = SetupHandlerEndpoint.Console;

                    //Call in the paper trading setup:
                    var setup = new PaperTradingSetupHandler();
                    setup.Setup(algorithm, out brokerage, baseJob);

                    //Live Specific Parameters:
                    StartingDate    = DateTime.Now;
                    StartingCapital = algorithm.Portfolio.Cash;
                }
            }
            catch (Exception err)
            {
                Log.Error("ConsoleSetupHandler().Setup(): " + err.Message);
            }

            if (Errors.Count == 0)
            {
                initializeComplete = true;
            }

            return(initializeComplete);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Setup the algorithm cash, dates and portfolio as desired.
        /// </summary>
        /// <param name="algorithm">Existing algorithm instance</param>
        /// <param name="brokerage">New brokerage instance</param>
        /// <param name="baseJob">Backtesting job</param>
        /// <returns>Boolean true on successfully setting up the console.</returns>
        public bool Setup(IAlgorithm algorithm, out IBrokerage brokerage, AlgorithmNodePacket baseJob)
        {
            var initializeComplete = false;
            brokerage = new BacktestingBrokerage(algorithm);

            try
            {
                //Set common variables for console programs:

                if (baseJob.Type == PacketType.BacktestNode)
                {
                    var backtestJob = baseJob as BacktestNodePacket;

                    //Set the limits on the algorithm assets (for local no limits)
                    algorithm.SetAssetLimits(999, 999, 999);

                    //Setup Base Algorithm:
                    algorithm.Initialize();

                    //Construct the backtest job packet:
                    backtestJob.PeriodStart = algorithm.StartDate;
                    backtestJob.PeriodFinish = algorithm.EndDate;
                    backtestJob.BacktestId = "LOCALHOST";
                    backtestJob.UserId = 1001;
                    backtestJob.Type = PacketType.BacktestNode;

                    //Endpoints:
                    backtestJob.TransactionEndpoint = TransactionHandlerEndpoint.Backtesting;
                    backtestJob.ResultEndpoint = ResultHandlerEndpoint.Console;
                    backtestJob.DataEndpoint = DataFeedEndpoint.FileSystem;
                    backtestJob.RealTimeEndpoint = RealTimeEndpoint.Backtesting;
                    backtestJob.SetupEndpoint = SetupHandlerEndpoint.Console;

                    //Backtest Specific Parameters:
                    StartingDate = backtestJob.PeriodStart;
                    StartingCapital = algorithm.Portfolio.Cash;
                }
                else
                {
                    var liveJob = baseJob as LiveNodePacket;

                    //Live Job Parameters:
                    liveJob.UserId = liveJob.UserId;
                    liveJob.DeployId = "LOCALHOST";
                    liveJob.IssuedAt = DateTime.Now.Subtract(TimeSpan.FromSeconds(86399 - 60));     //For testing, first access token expires in 60 sec. refresh.
                    liveJob.LifeTime = TimeSpan.FromSeconds(86399);
                    liveJob.AccessToken = "123456";
                    liveJob.AccountId = 123456;
                    liveJob.RefreshToken = "";
                    liveJob.Type = PacketType.LiveNode;

                    //Endpoints:
                    liveJob.TransactionEndpoint = TransactionHandlerEndpoint.Backtesting;
                    liveJob.ResultEndpoint = ResultHandlerEndpoint.LiveTrading;

                    bool testLiveTradingEnabled = Config.GetBool("test-live-trading-enabled", defaultValue: false);
                    liveJob.DataEndpoint = testLiveTradingEnabled ? DataFeedEndpoint.Test : DataFeedEndpoint.LiveTrading;
                    liveJob.RealTimeEndpoint = RealTimeEndpoint.LiveTrading;
                    liveJob.SetupEndpoint = SetupHandlerEndpoint.Console;

                    //Call in the paper trading setup:
                    var setup = new PaperTradingSetupHandler();
                    setup.Setup(algorithm, out brokerage, baseJob);

                    //Live Specific Parameters:
                    StartingDate = DateTime.Now;
                    StartingCapital = algorithm.Portfolio.Cash;
                }
            }
            catch (Exception err)
            {
                Log.Error("ConsoleSetupHandler().Setup(): " + err.Message);
            }

            if (Errors.Count == 0)
            {
                initializeComplete = true;
            }

            return initializeComplete;
        }