Beispiel #1
0
def initialize(context):

    # Let's set a look up date inside our backtest to ensure we grab the correct security
    #set_symbol_lookup_date('2015-01-01')

    # Use a very liquid set of stocks for quick order fills
    context.symbol = symbol('SPY')
    #context.stocks = symbols(['TWX','AIG','PSX','EMC','YHOO','MDY','TNA','CHK','FXI',
    #                            'PEP','SBUX','VZ','VWO','TWC','HAL','MDLZ','CAT','TSLA',
    #                            'MU','PM','WYNN','MET',NOV BRK_B SNDK ESRX YELP])
    #set_universe(universe.DollarVolumeUniverse(99.5, 100))
    #set_benchmark(symbol('SPY'))

    # set a more realistic commission for IB, remove both this and slippage when live trading in IB
    set_commission(commission.PerShare(cost=0.014, min_trade_cost=1.4))

    # Default slippage values, but here to mess with for fun.
    set_slippage(
        slippage.VolumeShareSlippage(volume_limit=0.25, price_impact=0.1))

    # Use dicts to store items for plotting or comparison
    context.next_pred_price = {}  # Current cycles prediction

    #Change us!
    context.history_len = 500  # How many days in price history for training set
    context.out_of_sameple_bin_size = 2
    context.score_filter = -1000.0
    context.action_to_move_percent = 0.0

    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    add_history(context.history_len, '1d', 'price')
    context.i = 0
Beispiel #2
0
def initialize(context):
    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    add_history(100, '1d', 'price')
    add_history(300, '1d', 'price')

    context.i = 0
Beispiel #3
0
def initialize_magc(context):
    set_commission(commission.PerDollar(cost = COMMISSION))
    add_history(20, '1d', 'price')
    add_history(60, '1d', 'price')
    context.i = 0
    context.investment = False
    context.buy_price = 0
Beispiel #4
0
def initialize_bband(context):
    set_commission(commission.PerDollar(cost = COMMISSION))
    context.i = 0
    context.investment = False
    context.buy_price = 0
    context.position = 0.0
    add_history(20, '1d', 'price')
Beispiel #5
0
def initialize(context):

    # Let's set a look up date inside our backtest to ensure we grab the correct security
    #set_symbol_lookup_date('2015-01-01')
    

    # Use a very liquid set of stocks for quick order fills
    context.symbol = symbol('SPY')
    #context.stocks = symbols(['TWX','AIG','PSX','EMC','YHOO','MDY','TNA','CHK','FXI',
    #                            'PEP','SBUX','VZ','VWO','TWC','HAL','MDLZ','CAT','TSLA',
    #                            'MU','PM','WYNN','MET',NOV BRK_B SNDK ESRX YELP])
    #set_universe(universe.DollarVolumeUniverse(99.5, 100))
    #set_benchmark(symbol('SPY'))
    
    # set a more realistic commission for IB, remove both this and slippage when live trading in IB
    set_commission(commission.PerShare(cost=0.014, min_trade_cost=1.4))
    
    # Default slippage values, but here to mess with for fun.
    set_slippage(slippage.VolumeShareSlippage(volume_limit=0.25, price_impact=0.1))
        
    # Use dicts to store items for plotting or comparison
    context.next_pred_price = {} # Current cycles prediction
    
    #Change us!
    context.history_len              = 500    # How many days in price history for training set
    context.out_of_sameple_bin_size  = 2
    context.score_filter             = -1000.0
    context.action_to_move_percent   = 0.0

    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    add_history(context.history_len, '1d', 'price')
    context.i = 0
Beispiel #6
0
def initialize(context):
    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    add_history(100, '1d', 'price')
    add_history(300, '1d', 'price')

    context.i = 0
Beispiel #7
0
def initialize(context):
    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    add_history(25, '1d', 'price')
    set_commission(commission.PerDollar(0.0003))

    context.i = 0
    context.pct = 0.1
Beispiel #8
0
def initialize(context):
        
    #register 2 histories to track daily prices
    add_history(100, '1d', 'price')
    add_history(300, '1d', 'price')
    
    context.i = 0
    context.invested = False
def initialize(context):
    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    add_history(100, "1d", "price")
    add_history(300, "1d", "price")

    context.sym = symbol("AAPL")

    context.i = 0
Beispiel #10
0
def initialize(context):
    context.count = 252
    #context.stock = symbol('CSCO')

    context.stock = symbol('MMM')
    add_history(bar_count=252, frequency='1d', field='price')
    #spy_data = history(252, '1d', 'price')

    context.other_stocks = {'AAPL'}
    add_history(bar_count=252, frequency='1d', field='price')
Beispiel #11
0
def initialize(context):

    context.stocks = ['VNQ', 'XLE', 'VTI','VEA', 'VWO', 'VIG', 'SCHP', 'MUB', 'LQD', 'EMB']

    context.leverage = 2
    add_history(950, '1d', 'price')

    context.x0 = 1.0*np.ones(len(context.stocks))/len(context.stocks)
    #context.i = 0
    context.day_count = -1
Beispiel #12
0
def initialize(context):
    context.count = 252
    #context.stock = symbol('CSCO')
    
    context.stock = symbol('MMM')
    add_history(bar_count=252, frequency='1d', field='price')
    #spy_data = history(252, '1d', 'price')

    context.other_stocks = {'AAPL'}
    add_history(bar_count=252, frequency='1d', field='price')
def initialize(context):
    logging.debug('enter initialize')
    context.set_slippage(FixedSlippage())
    context.set_commission(commission.PerTrade(cost=5))

    context.LOW_RSI = initialize.low_RSI
    context.HIGH_RSI = initialize.high_RSI
    context.rsi_window = initialize.rsi_window
    add_history(context.rsi_window, '1d', 'price')
    context.i = 0
    context.invested = False
def initialize(context):
    logging.debug('enter initialize')
    context.set_slippage(FixedSlippage())
    context.set_commission(commission.PerTrade(cost=5))

    context.LOW_RSI = initialize.low_RSI
    context.HIGH_RSI = initialize.high_RSI
    context.rsi_window = initialize.rsi_window
    add_history(context.rsi_window, '1d', 'price')
    context.i = 0
    context.invested = False
Beispiel #15
0
def initialize(context):
    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    # mid 此处可以多次add_history(),但是,程序在历史数据管理中,对相同参数,只是大小不同的数据不会开辟多个panel
    # mid 而是会按最长的空间开辟buffer
    add_history(20, '1d', 'price')
    add_history(40, '1d', 'price')

    context.sym = symbol('AAPL')

    context.i = 0
Beispiel #16
0
def initialize(context):
    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    # mid 此处可以多次add_history(),但是,程序在历史数据管理中,对相同参数,只是大小不同的数据不会开辟多个panel
    # mid 而是会按最长的空间开辟buffer
    add_history(20, '1d', 'price')
    add_history(40, '1d', 'price')

    context.sym = symbol('AAPL')

    context.i = 0
Beispiel #17
0
def initialize(context, eps = 10, window_length = 50):
    
    #init    
    context.stocks = STOCKS
    context.sids = SIDS
    #context.sids = [context.symbol(symb) for symb in context.stocks]
    context.m = np.size(STOCKS)
    context.price = {}
    context.b_t = np.ones(context.m)/float(context.m)
    context.prev_weights = np.ones(context.m)/float(context.m)
    context.eps = eps
    context.init = True
    context.days = 0
    context.window_length = window_length
    
    add_history(window_length, '1d', 'price')
Beispiel #18
0
    def initialize(self, context):
        add_history(200, '1d', 'price')
        set_slippage(slippage.FixedSlippage(spread=0.0))
        set_commission(commission.PerShare(cost=0.01, min_trade_cost=1.0))
        context.tick = 0

        dp_data = self.data
        df_data = pd.DataFrame(index=dp_data.axes[1])
        df_data['close'] = dp_data[:, :, 'close']
        df_data['open'] = dp_data[:, :, 'open']
        df_data['high'] = dp_data[:, :, 'high']
        df_data['low'] = dp_data[:, :, 'low']
        df_data['volume'] = dp_data[:, :, 'volume']

        self.atr = atr_per_close(df_data, atrLen = self.atr_len)
        context.longstop = 0
Beispiel #19
0
def initialize(context, eps=10, window_length=50):

    #init
    context.stocks = STOCKS
    context.sids = SIDS
    #context.sids = [context.symbol(symb) for symb in context.stocks]
    context.m = np.size(STOCKS)
    context.price = {}
    context.b_t = np.ones(context.m) / float(context.m)
    context.prev_weights = np.ones(context.m) / float(context.m)
    context.eps = eps
    context.init = True
    context.days = 0
    context.window_length = window_length

    add_history(window_length, '1d', 'price')
Beispiel #20
0
def initialize(context):

    add_history(190, '1d', 'price')
    add_history(365, '1d', 'price')

    context.syms = symbols('AAPL', 'AXP', 'BA', 'CAT', 'CSCO', 'CVX', 'DD', 'DIS', 'GE', 'GS', 'HD', 'IBM', 'INTC', 'JNJ', 'JPM', 'KO', 'MCD', 'MMM', 'MRK', 'MSFT', 'NKE', 'PFE', 'PG', 'TRV', 'UNH', 'UTX', 'V', 'VZ', 'WMT', 'XOM')

    context.stocks_to_long = 10
    context.stocks_to_short = 10

    context.day = 0
    context.n = 0

    context.weekCounter = 0 
    


    algo.set_commission(commission.PerShare(cost=0.15))
Beispiel #21
0
def initialize(context):
    # Register 2 histories that track daily prices,
    # one with a 100 window and one with a 300 day window
    context.N = 5 + 1
    context.k = 0.7
    add_history(context.N, '1d', 'close')
    add_history(context.N, '1d', 'open')
    add_history(context.N, '1d', 'high')
    add_history(context.N, '1d', 'low')

    context.i = 0
    context.invested = False
def initialize(context):
    '''
    Called once at the very beginning of a backtest (and live trading). 
    Use this method to set up any bookkeeping variables.
    
    The context object is passed to all the other methods in your algorithm.

    Parameters

    context: An initialized and empty Python dictionary that has been 
             augmented so that properties can be accessed using dot 
             notation as well as the traditional bracket notation.
    
    Returns None
    '''
    # Register history container to keep a window of the last 100 prices.
    add_history(10, '1d', 'price')
    # Turn off the slippage model
    set_slippage(slippage.FixedSlippage(spread=0.0))
    # Set the commission model (Interactive Brokers Commission)
    set_commission(commission.PerShare(cost=0.0, min_trade_cost=0.0))
    context.tick = 0
def initialize(context):
    '''
    Called once at the very beginning of a backtest (and live trading). 
    Use this method to set up any bookkeeping variables.
    
    The context object is passed to all the other methods in your algorithm.

    Parameters

    context: An initialized and empty Python dictionary that has been 
             augmented so that properties can be accessed using dot 
             notation as well as the traditional bracket notation.
    
    Returns None
    '''
    # Register history container to keep a window of the last 100 prices.
    add_history(10, '1d', 'price')
    # Turn off the slippage model
    set_slippage(slippage.FixedSlippage(spread=0.0))
    # Set the commission model (Interactive Brokers Commission)
    set_commission(commission.PerShare(cost=0.0, min_trade_cost=0.0))
    context.tick = 0
Beispiel #24
0
def initialize(context):
    # Hack to manually add the assets into the universe so they register with
    # the history container.
    for s in context.asset_finder.sids:
        context._current_universe.add(s)
    add_history(5, '1d', 'price')
Beispiel #25
0
 def initialize(self, context):
     add_history(60, '1d', 'price')
     set_slippage(slippage.FixedSlippage(spread=0.0))
     set_commission(commission.PerShare(cost=0.01, min_trade_cost=1.0))
     context.tick = 0
Beispiel #26
0
def add_strat_history(context):
    for p in ['open_price', 'high', 'low', 'close_price', 'volume', 'price']:
        add_history(context.max_lookback, '1d', p)
Beispiel #27
0
def initialize(context):
    add_history(5, '1d', 'price')
    add_history(20, '1d', 'price')
    context.i = 0
    context.stockCd = '035720'
Beispiel #28
0
def initialize(context):
    add_history(120, '1d', 'price')
    set_slippage(slippage.FixedSlippage(spread=0.0))
    set_commission(commission.PerShare(cost=0.01, min_trade_cost=1.0))
    context.tick = 0
Beispiel #29
0
def initialize(context):
    set_commission(commission.PerDollar(cost=0.00165))
    add_history(5, '1d', 'price')
    add_history(20, '1d', 'price')
    context.i = 0
    context.investment = False
Beispiel #30
0
def initialize(context):
    set_commission(commission.PerDollar(cost=0.00165))
    add_history(5, '1d', 'price')
    add_history(20, '1d', 'price')
    context.i = 0
    context.investment = False