def initialize(context):
    """
        API function to define things to do at the start of the strategy.
    """
    # set strategy parameters
    context.lookback_data = 60
    context.lookback_long = 20
    context.leverage = 2.0

    # reset everything at start
    daily_reset(context)

    # create our universe
    create_universe(context)

    # schedule calculation at the end of opening range (30 minutes)
    schedule_function(calculate_trading_metrics, date_rules.every_day(), 
                            time_rules.market_open(hours=0, minutes=30))
    
    # schedule entry rules
    schedule_function(no_more_entry, date_rules.every_day(), 
                            time_rules.market_open(hours=1, minutes=30))
    
    # schedule exit rules
    schedule_function(unwind, date_rules.every_day(), 
                            time_rules.market_close(hours=0, minutes=30))
    
    # set trading costs
    set_commission(commission.PerShare(cost=0.0, min_trade_cost=0.0))
    set_slippage(slippage.FixedSlippage(0.00))
def initialize(context):
    context.lookback = 12 * 21
    context.offset = 1 * 21
    context.min_volume = 1E8
    context.max_size = 10
    context.min_size = 5
    context.weight = 0

    context.universe = []
    if context.broker.name == 'regT':
        context.hedge = symbol('SPY')
    elif context.broker.name == 'nse-backtest':
        context.hedge = symbol('NIFTY-I')
    else:
        raise ValueError(f'this broker not supported:{context.broker.name}')

    context.hedge_threshold = 10000

    schedule_function(strategy, date_rules.month_start(days_offset=0),
                      time_rules.market_close(hours=2, minutes=30))
    attach_pipeline(make_strategy_pipeline(context), name='strategy_pipeline')
    schedule_function(hedge, date_rules.every_day(),
                      time_rules.market_open(hours=0, minutes=30))
    schedule_function(hedge, date_rules.every_day(),
                      time_rules.market_close(hours=0, minutes=30))
def initialize(context):
    print("{}:inside initialize".format(get_datetime()))

    schedule_function(rebalance, date_rule=date_rules.month_start(),
                        time_rule=time_rules.market_open())

    context.frequency = 120
    context.loop_count = 0
def initialize(context):
    """
        function to define things to do at the start of the strategy
    """
    context.x = symbol('AMBUJACEM')
    context.y = symbol('ACC')
    context.leverage = 5
    context.signal = 0

    # Trade entry and exit when the z_score is +/- entry_z_score and exit_z_score respectively
    context.entry_z_score = 2.0
    context.exit_z_score = 0.5

    # Lookback window
    context.lookback = 200

    # used for zscore calculation
    context.z_window = 100

    # Call strategy function on the first trading day of each week at 10 AM
    schedule_function(pair_trading_strategy, date_rules.week_start(),
                      time_rules.market_open(minutes=30))
def initialize(context):
    """
        function to define things to do at the start of the strategy
    """
    # set the account currency, only valid for backtests
    set_account_currency("USD")

    # trading pound parity!
    # this should work after the European sovereign crisis settled down
    # and before the Brexit noise started (2012-2015)
    context.x = symbol('GBP/USD')
    context.y = symbol('EUR/USD')
    context.leverage = 5
    context.signal = 0

    # Trade entry and exit when the z_score is +/- entry_z_score and exit_z_score respectively
    context.entry_z_score = 2.0
    context.exit_z_score = 0.5

    # Lookback window
    context.lookback = 720

    # used for zscore calculation
    context.z_window = 360

    # Call strategy function after the London open every day
    schedule_function(pair_trading_strategy, date_rules.every_day(),
                      time_rules.market_open(hours=9, minutes=30))

    # square off towards to NYC close
    context.trading_hours = False

    # set a timeout for trading
    schedule_function(stop_trading, date_rules.every_day(),
                      time_rules.market_close(hours=0, minutes=31))
    # call square off to zero out positions 30 minutes before close.
    schedule_function(daily_square_off, date_rules.every_day(),
                      time_rules.market_close(hours=0, minutes=30))