示例#1
0
        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetCash(decimal)"/>
        public override void Initialize()
        {
            #region logging
            var algoname = this.GetType().Name;
            mylog.Debug(algoname);
            mylog.Debug(ondataheader);
            dailylog.Debug(algoname);
            dailylog.Debug(dailyheader);
            _transactions = new List <OrderTransaction>();
            string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv";
            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            #endregion

            //Initialize dates
            SetStartDate(_startDate);
            SetEndDate(_endDate);
            SetCash(_portfolioAmount);

            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // Indicators
            Price = new RollingWindow <IndicatorDataPoint>(14);      // The price history

            // ITrend
            trend        = new InstantaneousTrend(7);
            trendHistory = new RollingWindow <IndicatorDataPoint>(14);

            // The ITrendStrategy
            iTrendStrategy = new InstantTrendStrategy(symbol, 14, this);
            for (int i = 0; i < signals.Length; i++)
            {
                signals[i] = OrderSignal.doNothing;
            }



            _ticketsQueue = new ConcurrentQueue <OrderTicket>();
            #region lists
            #endregion


            // for use with Tradier. Default is IB.
            //var security = Securities[symbol];
            //security.TransactionModel = new ConstantFeeTransactionModel(1.0m);
        }
        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetCash(decimal)"/>
        public override void Initialize()
        {
            #region logging
            var algoname = this.GetType().Name;
            mylog.Debug(algoname);
            mylog.Debug(ondataheader);
            dailylog.Debug(algoname);
            dailylog.Debug(dailyheader);
            _transactions = new List <OrderTransaction>();
            string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv";
            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            #endregion

            //Initialize dates
            SetStartDate(_startDate);
            SetEndDate(_endDate);
            SetCash(_portfolioAmount);

            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // Indicators
            Price = new RollingWindow <IndicatorDataPoint>(14);      // The price history

            // ITrend
            trend        = new InstantaneousTrend(7);
            trendHistory = new RollingWindow <IndicatorDataPoint>(14);

            // The ITrendStrategy
            iTrendStrategy = new InstantTrendStrategy(symbol, 14, this);
            iTrendStrategy.ShouldSellOutAtEod = shouldSellOutAtEod;
            #region lists
            #endregion

            var security = Securities[symbol];
            security.TransactionModel = new ConstantFeeTransactionModel(1.0m);
        }
示例#3
0
        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetCash(decimal)"/>
        public override void Initialize()
        {
            #region logging
            var algoname = this.GetType().Name;
            mylog.Debug(algoname);
            mylog.Debug(ondataheader);
            dailylog.Debug(algoname);
            dailylog.Debug(dailyheader);
            _transactions = new List <OrderTransaction>();



            var days = _endDate.Subtract(_startDate).TotalDays;
            MaxDailyProfit = new Maximum("MaxDailyProfit", (int)days);
            MinDailyProfit = new Minimum("MinDailyProfit", (int)days);
            #endregion

            //Initialize dates
            SetStartDate(_startDate);
            SetEndDate(_endDate);
            SetCash(_portfolioAmount);

            //Add as many securities as you like. All the data will be passed into the event handler:
            //AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // Initialize the Symbol indexed dictionaries
            foreach (string s in Symbols)
            {
                AddSecurity(SecurityType.Equity, s, Resolution.Minute);
                Strategy.Add(symbol, new MultiITStrategy(s, ITrendPeriod, this));
                Tickets.Add(s, new List <OrderTicket>());
                // Equal portfolio shares for every stock.
                ShareSize.Add(s, (maxLeverage * (1 - leverageBuffer)) / Symbols.Count());
                LastOrderSent.Add(s, OrderSignal.doNothing);

                #region Logging stuff - Initializing Stock Logging

                //stockLogging.Add(new StringBuilder());
                //stockLogging[i].AppendLine("Counter, Time, Close, ITrend, Trigger," +
                //    "Momentum, EntryPrice, Signal," +
                //    "TriggerCrossOverITrend, TriggerCrossUnderITrend, ExitFromLong, ExitFromShort," +
                //    "StateFromStrategy, StateFromPorfolio, Portfolio Value");
                //i++;

                #endregion Logging stuff - Initializing Stock Logging
            }

            // Indicators
            Price = new RollingWindow <IndicatorDataPoint>(14);      // The price history

            // ITrend
            trend        = new InstantaneousTrend("Main", 7, .25m);
            trendHistory = new RollingWindow <IndicatorDataPoint>(14);

            // The ITrendStrategy
            iTrendStrategy = new InstantTrendStrategy(symbol, 14, this);
            iTrendStrategy.ShouldSellOutAtEod = shouldSellOutAtEod;

            #region lists
            // Initialize the lists for the strategies
            trendList        = new Dictionary <int, InstantaneousTrend>();
            trendHistoryList = new Dictionary <int, RollingWindow <IndicatorDataPoint> >();
            strategyList     = new Dictionary <int, MultiITStrategy>();
            entryPriceList   = new Dictionary <int, decimal>();

            int listIndex = 0;
            for (decimal d = .25m; d < .26m; d += .01m)
            {
                trendList.Add(listIndex, new InstantaneousTrend("ITrend_" + d, 7, d));  // eg ITrend.25, period 7, alpha .25
                trendHistoryList.Add(listIndex, new RollingWindow <IndicatorDataPoint>(4));
                strategyList.Add(listIndex, new MultiITStrategy(symbol, 7, this));
                entryPriceList.Add(listIndex, 0);
                listIndex++;
            }

            #endregion
            #region Proforma

            _brokerSimulator = new BrokerSimulator(this);



            #endregion
        }
        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetCash(decimal)"/>
        public override void Initialize()
        {
            #region logging
            var algoname = this.GetType().Name;
            mylog.Debug(algoname);
            mylog.Debug(ondataheader);
            dailylog.Debug(algoname);
            dailylog.Debug(dailyheader);
            _transactions = new List<OrderTransaction>();
            string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv";
            if (File.Exists(filepath)) File.Delete(filepath);
            #endregion

            //Initialize dates
            SetStartDate(_startDate);
            SetEndDate(_endDate);
            SetCash(_portfolioAmount);

            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // Indicators
            Price = new RollingWindow<IndicatorDataPoint>(14);      // The price history

            // ITrend
            trend = new InstantaneousTrend(7);
            trendHistory = new RollingWindow<IndicatorDataPoint>(14);

            // The ITrendStrategy
            iTrendStrategy = new InstantTrendStrategy(symbol, 14, this);
            for (int i = 0; i < signals.Length; i++)
                signals[i] = OrderSignal.doNothing;

            _ticketsQueue = new ConcurrentQueue<OrderTicket>();
            #region lists
            #endregion

            // for use with Tradier. Default is IB.
            //var security = Securities[symbol];
            //security.TransactionModel = new ConstantFeeTransactionModel(1.0m);
        }
示例#5
0
        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/>
        /// <seealso cref="QCAlgorithm.SetCash(decimal)"/>
        public override void Initialize()
        {
            #region logging
            var algoname = this.GetType().Name;
            mylog.Debug(algoname);
            mylog.Debug(ondataheader);
            dailylog.Debug(algoname);
            dailylog.Debug(dailyheader);
            _transactions = new List<OrderTransaction>();

            var days = _endDate.Subtract(_startDate).TotalDays;
            MaxDailyProfit = new Maximum("MaxDailyProfit", (int)days);
            MinDailyProfit = new Minimum("MinDailyProfit", (int)days);
            #endregion

            //Initialize dates
            SetStartDate(_startDate);
            SetEndDate(_endDate);
            SetCash(_portfolioAmount);

            //Add as many securities as you like. All the data will be passed into the event handler:
            //AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

            // Initialize the Symbol indexed dictionaries
            foreach (string s in Symbols)
            {
                AddSecurity(SecurityType.Equity, s, Resolution.Minute);
                Strategy.Add(symbol, new MultiITStrategy(s, ITrendPeriod, this));
                Tickets.Add(s, new List<OrderTicket>());
                // Equal portfolio shares for every stock.
                ShareSize.Add(s, (maxLeverage * (1 - leverageBuffer)) / Symbols.Count());
                LastOrderSent.Add(s, OrderSignal.doNothing);

                #region Logging stuff - Initializing Stock Logging

                //stockLogging.Add(new StringBuilder());
                //stockLogging[i].AppendLine("Counter, Time, Close, ITrend, Trigger," +
                //    "Momentum, EntryPrice, Signal," +
                //    "TriggerCrossOverITrend, TriggerCrossUnderITrend, ExitFromLong, ExitFromShort," +
                //    "StateFromStrategy, StateFromPorfolio, Portfolio Value");
                //i++;

                #endregion Logging stuff - Initializing Stock Logging
            }

            // Indicators
            Price = new RollingWindow<IndicatorDataPoint>(14);      // The price history

            // ITrend
            trend = new InstantaneousTrend("Main", 7, .25m);
            trendHistory = new RollingWindow<IndicatorDataPoint>(14);

            // The ITrendStrategy
            iTrendStrategy = new InstantTrendStrategy(symbol, 14, this);
            iTrendStrategy.ShouldSellOutAtEod = shouldSellOutAtEod;

            #region lists
            // Initialize the lists for the strategies
            trendList = new Dictionary<int, InstantaneousTrend>();
            trendHistoryList = new Dictionary<int, RollingWindow<IndicatorDataPoint>>();
            strategyList = new Dictionary<int, MultiITStrategy>();
            entryPriceList = new Dictionary<int, decimal>();

            int listIndex = 0;
            for (decimal d = .25m; d < .26m; d += .01m)
            {
                trendList.Add(listIndex, new InstantaneousTrend("ITrend_" + d, 7, d));  // eg ITrend.25, period 7, alpha .25
                trendHistoryList.Add(listIndex, new RollingWindow<IndicatorDataPoint>(4));
                strategyList.Add(listIndex, new MultiITStrategy(symbol, 7, this));
                entryPriceList.Add(listIndex, 0);
                listIndex++;
            }

            #endregion
            #region Proforma

            _brokerSimulator = new BrokerSimulator(this);

            #endregion
        }