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

        # set algorithm framework models
        self.SetUniverseSelection(
            ManualUniverseSelectionModel(
                [Symbol.Create("SPY", SecurityType.Equity, Market.USA)]))
        self.SetAlpha(
            ConstantAlphaModel(InsightType.Price, InsightDirection.Up,
                               timedelta(minutes=20), 0.025, None))
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())

        # define risk management model as a composite of several risk management models
        self.SetRiskManagement(
            CompositeRiskManagementModel(
                MaximumUnrealizedProfitPercentPerSecurity(0.01),
                MaximumDrawdownPercentPerSecurity(0.01)))
예제 #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):

        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())

        # 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())
예제 #4
0
 def Initialize(self):
     self.SetStartDate(2019, 3, 27)  # Set Start Date
     self.SetEndDate(2019, 3, 28)  # Set End Date
     self.SetCash(5000)  # Set Strategy Cash
     # self.AddEquity("SPY", Resolution.Minute)
     self.slowPeriod = 1050
     self.longPeriod = 10080
     self.resolution = Resolution.Minute
     self.SetWarmup(timedelta(7))
     self.AddAlpha(
         EmaReversionAlphaModel(self.resolution, self.slowPeriod,
                                self.longPeriod, 0.02, -0.02))
     self.SetExecution(VolumeWeightedAveragePriceExecutionModel())
     #self.SetPortfolioConstruction(MyPortfolioConstructionModel())
     self.SetPortfolioConstruction(
         EqualWeightingPortfolioConstructionModel())
     self.symbols = [
         Symbol.Create("BTCUSD", SecurityType.Crypto, Market.Bitfinex)
     ]
     self.SetUniverseSelection(ManualUniverseSelectionModel(self.symbols))
     self.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Margin)
     #self.SetBenchmark("SPY")
     stockPlot = Chart('Trade Plot')
     stockPlot.AddSeries(Series('Equity', SeriesType.Line, 0))
     stockPlot.AddSeries(Series('Benchmark', SeriesType.Line, 0))
    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):

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

        self.SetStartDate(2014, 3, 25)
        self.SetEndDate(2014, 4, 7)
        self.SetCash(100000)

        # set algorithm framework models
        self.SetUniverseSelection(FineFundamentalUniverseSelectionModel(self.SelectCoarse, self.SelectFine))
        self.SetAlpha(ConstantAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(1)))
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetRiskManagement(MaximumSectorExposureRiskManagementModel())
예제 #7
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())
    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)
            ]))

        # using hourly rsi to generate more insights
        self.SetAlpha(RsiAlphaModel(14, Resolution.Hour))
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())
        self.SetExecution(SpreadExecutionModel())

        self.InsightsGenerated += self.OnInsightsGenerated
예제 #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):
        ''' 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)
        self.SetEndDate(2013,10,11)
        self.SetCash(1000000)

        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(RsiAlphaModel(14, Resolution.Hour))
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(StandardDeviationExecutionModel())
예제 #12
0
    def Initialize(self):

        self.SetStartDate(2013, 1, 1)
        self.SetEndDate(2015, 1, 1)
        self.SetCash(100000)

        fastPeriod = 100
        slowPeriod = 300
        count = 10

        self.UniverseSettings.Leverage = 2.0
        self.UniverseSettings.Resolution = Resolution.Daily

        self.SetUniverseSelection(
            EmaCrossUniverseSelectionModel(fastPeriod, slowPeriod, count))
        self.SetAlpha(
            ConstantAlphaModel(InsightType.Price, InsightDirection.Up,
                               timedelta(1), None, None))
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())
    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))