Esempio n. 1
0
    def Initialize(self):

        self.SetStartDate(2018, 1, 1)
        self.SetCash(100000)

        # Set zero transaction fees
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        # select stocks using PennyStockUniverseSelectionModel
        self.UniverseSettings.Resolution = Resolution.Daily
        self.SetUniverseSelection(PennyStockUniverseSelectionModel())

        # Use SykesShortMicroCapAlphaModel to establish insights
        self.SetAlpha(SykesShortMicroCapAlphaModel())

        # 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())
    def Initialize(self):

        self.SetStartDate(2018, 1, 1)
        self.SetCash(100000)

        #Set zero transaction fees
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        # select stocks using MagicFormulaUniverseSelectionModel
        self.SetUniverseSelection(
            GreenBlattMagicFormulaUniverseSelectionModel())

        # Use MagicFormulaAlphaModel to establish insights
        self.SetAlpha(RateOfChangeAlphaModel())

        # 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())
    def Initialize(self):

        self.SetStartDate(2018, 1, 1)  #Set Start Date
        self.SetCash(100000)  #Set Strategy Cash

        ## Initialize variables to be used in controlling frequency of universe selection
        self.week = -1

        ## Manual Universe Selection
        self.UniverseSettings.Resolution = Resolution.Minute
        self.SetUniverseSelection(
            CoarseFundamentalUniverseSelectionModel(
                self.CoarseSelectionFunction))

        ## Set trading fees to $0
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        ## Set custom Alpha Model
        self.SetAlpha(PriceGapMeanReversionAlphaModel())

        ## Set equal-weighting Portfolio Construction Model
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel())

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

        ## Set Risk Management Model
        self.SetRiskManagement(NullRiskManagementModel())
Esempio n. 4
0
    def Initialize(self):

        self.SetStartDate(2019, 1, 1)   #Set Start Date
        self.SetCash(100000)           #Set Strategy Cash
        self.SetWarmUp(20)

        ## Setup Universe settings and tickers to be used
        tickers = ['VIA','VIAB']
        self.UniverseSettings.Resolution = Resolution.Minute
        symbols = [ Symbol.Create(ticker, SecurityType.Equity, Market.USA) for ticker in tickers]
        self.SetSecurityInitializer(lambda security: security.SetFeeModel(ConstantFeeModel(0)))  ## Set $0 fees to mimic High-Frequency Trading

        ## Set Manual Universe Selection
        self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) )
        
        ## Set Custom Alpha Model
        self.SetAlpha(ShareClassMeanReversionAlphaModel(tickers = tickers))

        ## Set Equal Weighting Portfolio Construction Model        
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        
        ## Set Immediate Execution Model
        self.SetExecution(ImmediateExecutionModel())
        
        ## Set Null Risk Management Model
        self.SetRiskManagement(NullRiskManagementModel())
Esempio n. 5
0
    def Initialize(self):

        # -- STRATEGY INPUT PARAMETERS --
        self.k1 = 0.63
        self.k2 = 0.63
        self.rangePeriod = 20
        self.consolidatorBars = 30

        # Settings
        self.SetStartDate(2018, 10, 1)
        self.SetSecurityInitializer(lambda security: security.SetFeeModel(ConstantFeeModel(0)))
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);

        # Universe Selection
        self.UniverseSettings.Resolution = Resolution.Minute   # it's minute by default, but lets leave this param here
        symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA)]
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))

        # Warming up
        resolutionInTimeSpan =  Extensions.ToTimeSpan(self.UniverseSettings.Resolution)
        warmUpTimeSpan = Time.Multiply(resolutionInTimeSpan, self.consolidatorBars)
        self.SetWarmUp(warmUpTimeSpan)

        # Alpha Model
        self.SetAlpha(DualThrustAlphaModel(self.k1, self.k2, self.rangePeriod, self.UniverseSettings.Resolution, self.consolidatorBars))

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

        ## Execution
        self.SetExecution(ImmediateExecutionModel())

        ## Risk Management
        self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.03))
Esempio n. 6
0
    def Initialize(self):

        self.SetStartDate(2019, 2, 1)  #Set Start Date
        self.SetCash(100000)  #Set Strategy Cash

        # Set zero transaction fees
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        ## Select trio of currencies to trade where
        ## Currency A = USD
        ## Currency B = EUR
        ## Currency C = GBP
        currencies = ['EURUSD', 'EURGBP', 'GBPUSD']
        symbols = [
            Symbol.Create(currency, SecurityType.Forex, Market.Oanda)
            for currency in currencies
        ]

        ## Manual universe selection with tick-resolution data
        self.UniverseSettings.Resolution = Resolution.Minute
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))

        self.SetAlpha(
            ForexTriangleArbitrageAlphaModel(Resolution.Minute, symbols))

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

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

        ## Set Null Risk Management Model
        self.SetRiskManagement(NullRiskManagementModel())
Esempio n. 7
0
    def Initialize(self):

        self.SetStartDate(2018, 1, 1)

        self.SetCash(100000)

        # Set zero transaction fees
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        # Use Hourly Data For Simplicity
        self.UniverseSettings.Resolution = Resolution.Hour
        self.SetUniverseSelection(
            CoarseFundamentalUniverseSelectionModel(
                self.CoarseSelectionFunction))

        # Use MeanReversionLunchBreakAlphaModel to establish insights
        self.SetAlpha(MeanReversionLunchBreakAlphaModel())

        # 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())
    def Initialize(self):

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

        # Set zero transaction fees
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        # Select resolution
        resolution = Resolution.Hour

        # Reversion on the USD.
        symbols = [Symbol.Create("EURUSD", SecurityType.Forex, Market.Oanda)]

        # Set requested data resolution
        self.UniverseSettings.Resolution = resolution
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
        self.SetAlpha(IntradayReversalAlphaModel(5, resolution))

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

        #Set WarmUp for Indicators
        self.SetWarmUp(20)
Esempio n. 9
0
    def Initialize(self):

        ## Set testing timeframe and starting cash
        self.SetStartDate(2019, 1, 1)
        self.SetCash(100000)

        ## We choose a pair of stock tickers that represent different
        ## share classes of the same company -- the idea being that their
        ## prices will move almost identically but likely with slight deviations
        ## e.g., Google
        symbols = ['GOOG', 'GOOGL']

        self.symbols = symbols
        for symbol in symbols:
            self.AddEquity(symbol, Resolution.Minute)
            self.Securities[symbol].FeeModel = ConstantFeeModel(
                0)  ## Set fees to $0 for High Freq. Trading

        ## Register a 20-bar SMA indicator for tracking the value of the
        ## long/short position
        self.sma = SimpleMovingAverage(20)

        ## Warm up our 20-bar indicator
        self.SetWarmup(20)

        ## Initialize a list to keep track of our position value, a period counter
        ## to assist in tracking our position relative to the SMA,
        ## and alpha + beta to represent position sizes in our assets
        self.portfolio = []
        self.period_counter = 0
        self.alpha = None
        self.beta = None
Esempio n. 10
0
    def Initialize(self):

        self.SetStartDate(2018, 1, 1)

        self.SetCash(100000)

        # Set zero transaction fees
        self.SetSecurityInitializer(lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        # 3X ETF pair tickers
        ultraLong = Symbol.Create("UGLD", SecurityType.Equity, Market.USA)
        ultraShort = Symbol.Create("DGLD", SecurityType.Equity, Market.USA)

        # Manually curated universe
        self.UniverseSettings.Resolution = Resolution.Daily
        self.SetUniverseSelection(ManualUniverseSelectionModel([ultraLong, ultraShort]))

        # Select the demonstration alpha model
        self.SetAlpha(RebalancingTripleLeveragedETFAlphaModel(ultraLong, ultraShort))

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

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

        ## Set Null Risk Management Model
        self.SetRiskManagement(NullRiskManagementModel())
    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.'''

        # what resolution should the data *added* to the universe be?
        self.UniverseSettings.Resolution = Resolution.Daily

        # Use raw prices
        self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw

        self.SetStartDate(2014, 3, 24)  #Set Start Date
        self.SetEndDate(2014, 4, 7)  #Set End Date
        self.SetCash(50000)  #Set Strategy Cash

        # Set the security initializer with zero fees
        self.SetSecurityInitializer(
            lambda x: x.SetFeeModel(ConstantFeeModel(0)))

        self.AddUniverse("MyUniverse", Resolution.Daily,
                         self.SelectionFunction)
    def Initialize(self):

        self.SetStartDate(2018, 1, 1)

        self.SetCash(100000)

        # Set zero transaction fees
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        # Global Equity ETF tickers
        tickers = [
            "ECH", "EEM", "EFA", "EPHE", "EPP", "EWA", "EWC", "EWG", "EWH",
            "EWI", "EWJ", "EWL", "EWM", "EWM", "EWO", "EWP", "EWQ", "EWS",
            "EWT", "EWU", "EWY", "EWZ", "EZA", "FXI", "GXG", "IDX", "ILF",
            "EWM", "QQQ", "RSX", "SPY", "THD"
        ]

        symbols = [
            Symbol.Create(ticker, SecurityType.Equity, Market.USA)
            for ticker in tickers
        ]

        # Manually curated universe
        self.UniverseSettings.Resolution = Resolution.Daily
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))

        # Use GlobalEquityMeanReversionAlphaModel to establish insights
        self.SetAlpha(MeanReversionIBSAlphaModel())

        # 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())
Esempio n. 13
0
    def Initialize(self):
        self.SetStartDate(2018, 1, 1)  #Set Start Date
        self.SetCash(100000)  #Set Strategy Cash

        natural_gas = [
            Symbol.Create(x, SecurityType.Equity, Market.USA)
            for x in ['UNG', 'BOIL', 'FCG']
        ]
        crude_oil = [
            Symbol.Create(x, SecurityType.Equity, Market.USA)
            for x in ['USO', 'UCO', 'DBO']
        ]

        ## Set Universe Selection
        self.UniverseSettings.Resolution = Resolution.Minute
        self.SetUniverseSelection(
            ManualUniverseSelectionModel(natural_gas + crude_oil))
        self.SetSecurityInitializer(
            lambda security: security.SetFeeModel(ConstantFeeModel(0)))

        ## Custom Alpha Model
        self.SetAlpha(
            PairsAlphaModel(leading=natural_gas,
                            following=crude_oil,
                            history_days=90,
                            resolution=Resolution.Minute))

        ## Equal-weight our positions, in this case 100% in USO
        self.SetPortfolioConstruction(
            EqualWeightingPortfolioConstructionModel(
                resolution=Resolution.Minute))

        ## Immediate Execution Fill Model
        self.SetExecution(CustomExecutionModel())

        ## Null Risk-Management Model
        self.SetRiskManagement(NullRiskManagementModel())
Esempio n. 14
0
 def CustomSecurityInitializer(self, security):
     '''Initialize the security with raw prices and zero fees 
     Args:
         security: Security which characteristics we want to change'''
     security.SetDataNormalizationMode(DataNormalizationMode.Raw)
     security.SetFeeModel(ConstantFeeModel(0))
Esempio n. 15
0
 def InitializeSecurities(self, security):
     security.SetFeeModel( ConstantFeeModel(0) )