def Initialize(self):
        ''' Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

        # Set requested data resolution
        self.UniverseSettings.Resolution = Resolution.Minute

        self.SetStartDate(2013, 10, 7)  #Set Start Date
        self.SetEndDate(2013, 10, 11)  #Set End Date
        self.SetCash(100000)  #Set Strategy Cash

        # Find more symbols here: http://quantconnect.com/data
        # Forex, CFD, Equities Resolutions: Tick, Second, Minute, Hour, Daily.
        # Futures Resolution: Tick, Second, Minute
        # Options Resolution: Minute Only.
        symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA)]

        # set algorithm framework models
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
        self.SetAlpha(
            ConstantAlphaModel(InsightType.Price, InsightDirection.Up,
                               timedelta(minutes=20), 0.025, None))
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.01))

        self.Debug("numpy test >>> print numpy.pi: " + str(np.pi))
示例#2
0
    def Initialize(self):

        ## Set requested data resolution and variables to help with Universe Selection control
        self.UniverseSettings.Resolution = Resolution.Daily
        self.month = -1

        ## Declare single variable to be passed in multiple places -- prevents issue with conflicting start dates declared in different places
        self.SetStartDate(2018, 1, 1)
        self.SetCash(100000)

        ## SPDR Small Cap ETF is a better benchmark than the default SP500
        self.SetBenchmark('IJR')

        ## Set Universe Selection Model
        self.SetUniverseSelection(
            FineFundamentalUniverseSelectionModel(self.CoarseSelectionFunction,
                                                  self.FineSelectionFunction))
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))
        ## Set CCA Alpha Model
        self.SetAlpha(ContingentClaimsAnalysisAlphaModel())

        ## Set Portfolio Construction Model
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())

        ## Set Execution Model
        self.SetExecution(ImmediateExecutionModel())

        ## Set Risk Management Model
        self.SetRiskManagement(NullRiskManagementModel())
示例#3
0
    def Initialize(self):

        # Set requested data resolution
        self.UniverseSettings.Resolution = Resolution.Minute

        self.SetStartDate(2013, 10, 7)  #Set Start Date
        self.SetEndDate(2013, 10, 11)  #Set End Date
        self.SetCash(100000)  #Set Strategy Cash

        self.symbols = [
            Symbol.Create(x, SecurityType.Equity, Market.USA)
            for x in ['AIG', 'BAC', 'IBM', 'SPY']
        ]

        optimizer = UnconstrainedMeanVariancePortfolioOptimizer()

        # set algorithm framework models
        self.SetUniverseSelection(
            CoarseFundamentalUniverseSelectionModel(self.coarseSelector))
        self.SetAlpha(HistoricalReturnsAlphaModel(resolution=Resolution.Daily))
        self.SetPortfolioConstruction(
            BlackLittermanOptimizationPortfolioConstructionModel(
                optimizer=optimizer))
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(NullRiskManagementModel())
示例#4
0
    def Initialize(self):
        self.SetStartDate(2018, 1, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)
        self.AddAlpha(SmartInsiderAlphaModel())

        self.SetExecution(ImmediateExecutionModel())

        self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())

        self.SetRiskManagement(MaximumDrawdownPercentPortfolio(0.03))

        self.SetUniverseSelection(TechnologyUniverseModule())
    def Initialize(self):

        self.SetStartDate(2013,10,7)
        self.SetEndDate(2013,10,11)

        bac = self.AddEquity("BAC")
        aig = self.AddEquity("AIG")

        self.SetUniverseSelection(ManualUniverseSelectionModel(self.Securities.Keys))
        self.SetAlpha(PairsTradingAlphaModel(bac.Symbol, aig.Symbol))
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(NullRiskManagementModel())
示例#6
0
    def Initialize(self):

        self.UniverseSettings.Resolution = Resolution.Minute

        self.SetStartDate(2013, 10, 7)
        self.SetEndDate(2013, 10, 11)
        self.SetCash(100000)

        # set framework models
        self.SetUniverseSelection(FrontMonthFutureUniverseSelectionModel(self.SelectFutureChainSymbols))
        self.SetAlpha(ConstantFutureContractAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(1)))
        self.SetPortfolioConstruction(SingleSharePortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(NullRiskManagementModel())
    def Initialize(self):

        self.UniverseSettings.Resolution = Resolution.Minute

        self.SetStartDate(2014, 6, 5)
        self.SetEndDate(2014, 6, 6)
        self.SetCash(100000)

        # set framework models
        self.SetUniverseSelection(EarliestExpiringWeeklyAtTheMoneyPutOptionUniverseSelectionModel(self.SelectOptionChainSymbols))
        self.SetAlpha(ConstantOptionContractAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(hours = 0.5)))
        self.SetPortfolioConstruction(SingleSharePortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(NullRiskManagementModel())
示例#8
0
    def Initialize(self):
        self.SetStartDate(2018, 10, 10)  # Set Start Date
        self.SetEndDate(2020, 10, 10)  # Set End Date
        self.SetCash(100000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)
        self.AddAlpha(
            MacdAlphaModel(12, 26, 9, MovingAverageType.Simple,
                           Resolution.Daily))

        self.SetExecution(ImmediateExecutionModel())

        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())

        self.SetRiskManagement(MaximumUnrealizedProfitPercentPerSecurity(0.03))

        #Add Counters here
        symbols = [
            Symbol.Create("AAPL", SecurityType.Equity, Market.USA),
            Symbol.Create("AZN", SecurityType.Equity, Market.USA),
            Symbol.Create("BABA", SecurityType.Equity, Market.USA),
            Symbol.Create("BLK", SecurityType.Equity, Market.USA),
            Symbol.Create("CHGG", SecurityType.Equity, Market.USA),
            Symbol.Create("EBAY", SecurityType.Equity, Market.USA),
            Symbol.Create("GOOG", SecurityType.Equity, Market.USA),
            Symbol.Create("GSK", SecurityType.Equity, Market.USA),
            Symbol.Create("HD", SecurityType.Equity, Market.USA),
            Symbol.Create("JPM", SecurityType.Equity, Market.USA),
            Symbol.Create("LLY", SecurityType.Equity, Market.USA),
            Symbol.Create("MCD", SecurityType.Equity, Market.USA),
            Symbol.Create("MSFT", SecurityType.Equity, Market.USA),
            Symbol.Create("NFLX", SecurityType.Equity, Market.USA),
            Symbol.Create("SGOL", SecurityType.Equity, Market.USA),
            Symbol.Create("SBUX", SecurityType.Equity, Market.USA),
            Symbol.Create("SPOT", SecurityType.Equity, Market.USA),
            Symbol.Create("V", SecurityType.Equity, Market.USA),
            Symbol.Create("WMT", SecurityType.Equity, Market.USA),
            Symbol.Create("UNH", SecurityType.Equity, Market.USA),
            Symbol.Create("VZ", SecurityType.Equity, Market.USA),
            Symbol.Create("CMCSA", SecurityType.Equity, Market.USA),
            Symbol.Create("JNJ", SecurityType.Equity, Market.USA),
            Symbol.Create("MDT", SecurityType.Equity, Market.USA),
            Symbol.Create("DUK", SecurityType.Equity, Market.USA)
        ]
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
    def Initialize(self):

        self.SetStartDate(2013, 10, 7)
        self.SetEndDate(2013, 10, 11)

        self.SetUniverseSelection(
            ManualUniverseSelectionModel(
                Symbol.Create('AIG', SecurityType.Equity, Market.USA),
                Symbol.Create('BAC', SecurityType.Equity, Market.USA),
                Symbol.Create('IBM', SecurityType.Equity, Market.USA),
                Symbol.Create('SPY', SecurityType.Equity, Market.USA)))

        self.SetAlpha(
            PearsonCorrelationPairsTradingAlphaModel(252, Resolution.Daily))
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(NullRiskManagementModel())
示例#10
0
    def Initialize(self):

        self.SetStartDate(2015, 7, 12)
        self.SetEndDate(2018, 7, 27)
        self.SetCash(100000)

        symbols = [
            Symbol.Create("EURUSD", SecurityType.Forex, Market.Oanda),
            Symbol.Create("EURGBP", SecurityType.Forex, Market.Oanda),
            Symbol.Create("EURAUD", SecurityType.Forex, Market.Oanda),
            Symbol.Create("EURCHF", SecurityType.Forex, Market.Oanda),
            Symbol.Create("EURJPY", SecurityType.Forex, Market.Oanda),
            Symbol.Create("EURCHF", SecurityType.Forex, Market.Oanda),
            Symbol.Create("USDJPY", SecurityType.Forex, Market.Oanda),
            Symbol.Create("USDCHF", SecurityType.Forex, Market.Oanda),
            Symbol.Create("USDCAD", SecurityType.Forex, Market.Oanda),
            Symbol.Create("AUDUSD", SecurityType.Forex, Market.Oanda),
            Symbol.Create("AUDJPY", SecurityType.Forex, Market.Oanda),
            Symbol.Create("GBPJPY", SecurityType.Forex, Market.Oanda),
            Symbol.Create("GBPUSD", SecurityType.Forex, Market.Oanda),
            Symbol.Create("NZDUSD", SecurityType.Forex, Market.Oanda)
        ]

        # Initializes the class that provides DailyFx News
        self.AddData(DailyFx, "DFX", Resolution.Minute, TimeZones.Utc)

        # Set Our Universe
        self.UniverseSettings.Resolution = Resolution.Minute
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))

        # Set to use our FxCalendar Alpha Model
        self.SetAlpha(FxCalendarTrigger())

        # Equally weigh securities in portfolio, based on insights
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())

        # Set Immediate Execution Model
        self.SetExecution(ImmediateExecutionModel())

        # Set Null Risk Management Model
        self.SetRiskManagement(NullRiskManagementModel())
示例#11
0
    def Initialize(self):

        self.SetStartDate(2013,10,7)   #Set Start Date
        self.SetEndDate(2013,10,11)    #Set End Date
        self.SetCash(100000)           #Set Strategy Cash
        
        # even though we're using a framework algorithm, we can still add our securities
        # using the AddEquity/Forex/Crypto/ect methods and then pass them into a manual
        # universe selection model using Securities.Keys
        self.AddEquity("SPY")
        self.AddEquity("IBM")
        self.AddEquity("BAC")
        self.AddEquity("AIG")

        # define a manual universe of all the securities we manually registered
        self.SetUniverseSelection(ManualUniverseSelectionModel(self.Securities.Keys))

        # define alpha model as a composite of the rsi and ema cross models
        self.SetAlpha(CompositeAlphaModel(RsiAlphaModel(), EmaCrossAlphaModel()))

        # default models for the rest
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(NullRiskManagementModel())