Exemple #1
0
def initialize(context):

    # List of Major World Indices Yahoo tickers - https://finance.yahoo.com/world-indices
    with open('tickers.pickle', 'rb') as handle:
        indices_tickers = pickle.load(handle)  # load in tickers from pickle

    os.remove('tickers.pickle')  # delete tickers pickle file

    context.indices = [symbol(ticker) for ticker in indices_tickers
                       ]  # create list of ticker symbols
    context.days_of_correction = [
        0 for _ in indices_tickers
    ]  # create list of days since correction has begun
    set_benchmark(symbol('^GSPC'))
    set_commission(
        commission.PerTrade(cost=15.0)
    )  # commission for IBKR, UK for Stocks, ETF's & Warrants - https://www.interactivebrokers.co.uk/en/index.php?f=39753&p=stocks1
    '''-----------------------------PARAMETERS TO BE OPTIMISED--------------------------------'''
    context.correction_margin = 0.1  # the percentage drawdown considered a correction
    print('Drawdown percentage range from peak for correction: ' +
          str(round(context.correction_margin * 100)) + '%')
    context.upturn_coefficient = 0.24  # the ratio upturn from trough indicating end of correction - used in calculate_required_upturn function
    print('Upturn Coefficient: ' + str(round(context.upturn_coefficient, 4)))
    context.min_gain = 0.05  # the highest the price can be from peak and still be considered for ordering
    print('Mainimum potential gain from peak to be considered: ' +
          str(round(context.min_gain * 100, 0)) + '%')
    context.state_threshold = -10.0  # 0.0002 threshold between bull and bear markets
    print('Market state threshhold: ' +
          str(round(context.state_threshold, 4)) + '%')
 def initialize(self, context):
     context.set_slippage(slippage.FixedSlippage(spread=0))
     context.set_commission(commission.PerTrade(cost=0))
     context.target_duration = 30  # How long to test strategies for
     context.num_parents = 4  # Number of parents each new species has
     context.generation_size = 5  # How many species to generate per generation
     context.frames = deque(maxlen=70)  # Store past frames for past prices
     context.species = []  # All species are stored here
     self.new_generation(
         context)  # Create a new generation (starts testing on 70th day)
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
Exemple #4
0
 def initialize(self,stockA,stockB, window_length=14):  
     self.spreads = []  
     self.capital_base=10000  
     self.invested = 0  
     self.window_length = window_length  
     self.instant_fill=True                    #Pairslog results are built using EOD data. (I assumed same day of signal)  
     self.stockA=stockA  
     self.stockB=stockB  
     self.posSizeA=self.capital_base  
     self.posSizeB=self.capital_base           #I assumed 50% margin for both long and short trades  
     self.set_commission(commission.PerTrade(cost=0))        #Pairslog results do not consider commissions.  
     self.set_slippage(slippage.FixedSlippage(spread=0.0))   #Pairslog results are built using EOD data and do not consider liquidity factor.  
     self.txnumber=0  
     self.trades = pd.DataFrame()