Пример #1
0
    def __init__(self, calendar_list):
        Strategy.__init__(self, calendar_list, name='N Calendar Spread')

        # Check that calendar list is not empty
        if not calendar_list:
            raise ValueError(
                'No calendars given to NCalendarSpread constructor')
        else:
            self.calendar_list = calendar_list
        # Check all given calendars have the same underlying
        fist_ticker = calendar_list[0].get_ticker()
        if not all(cal.get_ticker() == fist_ticker for cal in calendar_list):
            raise ValueError(
                'All given calendars must refer to the same underlying')
        else:
            self.ticker = fist_ticker
        # Check all calendars have the same near-term and next-term expiries
        if not all(c.near_term_opt.expiration == self.get_nearest_expiration()
                   for c in calendar_list):
            raise ValueError('All given calendars must refer to the same '
                             'near-term expiration date')
        else:
            self.near_term_exp = self.get_nearest_expiration()
        self.next_term_exp = calendar_list[0].next_term_opt.expiration
        if not all(c.next_term_opt.expiration == self.next_term_exp
                   for c in calendar_list):
            raise ValueError('All given calendars must refer to the same '
                             'next-term expiration date')
 def __init__(self):
     Strategy.__init__(self, constants.Strategies.Q)
     self.learningRate = 0.2
     self.decay = 0.8
     self.exploratory_rate = 0.1
     self.states = {}
     self.states_history = []
 def __init__(self, start_date, end_date, initial_position, market, params, h5file=None):
     Strategy.__init__(self, start_date, end_date, initial_position, market, params, h5file)
     self.diff = {}
     for symbol in initial_position.keys():
         if symbol == "$":
             continue
         self.diff[symbol] = [0.0]
         self.addIndicator(symbol, "value", SimpleValue())
         try:
             period = params['period']
         except KeyError:
             period = averageSystem.DEF_PERIOD
         self.addIndicator(symbol, "MA", SMA(period))
         try:
             short = params['short']
         except KeyError:
             short = Trending.DEF_SHORT_DAYS
         self.addIndicator(symbol, "short", EMA(short)) 
         try:
             long_ = params['long']
         except KeyError:
             long_ = Trending.DEF_LONG_DAYS
         self.addIndicator(symbol, "long", EMA(long_))
     try:
         backfill = params['backfill']
     except KeyError:
         backfill = period
     d = start_date - (backfill * ONE_DAY)
     self.updateIndicators(d, start_date)
     self.win_point = params['win']
     self.loss_point = params['loss']
     self.pre = 0
Пример #4
0
 def __init__(self,
              prices,
              step=60,
              use_wick=True,
              nb_of_candles=2,
              nb_of_bodies=2,
              trades=None,
              stop_loss=None,
              local_stop_loss=None):
     Strategy.__init__(self,
                       prices,
                       trades=trades,
                       step=step,
                       stop_loss=stop_loss,
                       local_stop_loss=local_stop_loss)
     self._use_wick = use_wick
     self._nb_of_candles = nb_of_candles
     self._nb_of_bodies = nb_of_bodies
     self._heikin_prices = pd.DataFrame({
         'OPEN': [],
         'HIGH': [],
         'LOW': [],
         'CLOSE': [],
         'COLOR': [],
         'PRICE': [],
         'TIMESTAMP': []
     })
     self.refresh_heikin_prices()
Пример #5
0
 def __init__(self, start_date, end_date, initial_position, market, params, h5file=None):
     Strategy.__init__(self, start_date, end_date, initial_position, market, params, h5file)
     for symbol in initial_position.keys():
         if symbol == "$":
             continue
         self.addIndicator(symbol, "value", SimpleValue())
         self.addSpecificIndicator(symbol, "peak", PeakTrough())
         date = getPrevTradingDay(market, start_date, symbol)
         #date = getNextTradingDay(start_date, symbol)
         self.peakDate = date
         self.troughDate = date
         ticker = market[symbol]
         if ticker[date] == None:
             self.max_value = 0
             self.min_value = 1000
         else:
             self.max_value = ticker[date].adjhigh
             self.min_value = ticker[date].adjlow
         self.updateSpecificIndicator(symbol, 'peak', start_date, (self.max_value, 1))
     self.updateIndicators(start_date)
     self.win_point = params['win']
     self.loss_point = params['loss']
     self.low_to_high = 0
     self.high_to_low = 0
     self.upTrend = 0
     self.downTrend = 0
    def __init__(self, start_date, end_date, initial_position, market, params, h5file=None):
        Strategy.__init__(self, start_date, end_date, initial_position, market, params, h5file)
        self.diff = {}
        for symbol in initial_position.keys():
            if symbol == "$":
                continue
	    self.diff[symbol] = [0.0]
            self.addIndicator(symbol, "value", SimpleValue()) 
            try:
                short = params['short']
            except KeyError:
                short = Trending.DEF_SHORT_DAYS
            self.addIndicator(symbol, "short", EMA(short)) 
            try:
                long_ = params['long']
            except KeyError:
                long_ = Trending.DEF_LONG_DAYS
            self.addIndicator(symbol, "long", EMA(long_))
            '''
            try:
                rsi = params['rsi']
            except KeyError:
                rsi = Trending.DEF_RSI_PERIOD
            self.addIndicator(symbol, "rsi", RSI(rsi))
            '''

        # Backfill the indicators 
        try:
            backfill = params['backfill']
        except KeyError:
            backfill = long_

        d = start_date - (backfill * ONE_DAY)
        self.updateIndicators(d, start_date)
Пример #7
0
 def __init__(self, start_date, end_date, initial_position, market, params, h5file=None):
     Strategy.__init__(self, start_date, end_date, initial_position, market, params, h5file)
     during = params['during']
     self.history = [1000.0 for x in xrange(during+1)]
     for symbol in initial_position.keys():
         if symbol == "$":
             continue
         self.addIndicator(symbol, "value", SimpleValue())
         try:
             short = params['short']
         except KeyError:
             short = Trending.DEF_SHORT_DAYS
         self.addIndicator(symbol, "short", EMA(short)) 
         try:
             long_ = params['long']
         except KeyError:
             long_ = Trending.DEF_LONG_DAYS
         self.addIndicator(symbol, "long", EMA(long_))
     try:
         backfill = params['backfill']
     except KeyError:
         backfill = long_
     d = start_date - (backfill * ONE_DAY)
     self.updateIndicators(d, start_date)
     self.win_point = params['win']
     self.loss_point = params['loss']
Пример #8
0
	def __init__(self, settings, watchlist, trademanager):
		Strategy.__init__(self, watchlist, trademanager)
		self.minprice = settings.getfloat("Strategy", "minprice")
		self.minvolume = settings.getfloat("Strategy", "minvolume")
		self.fastma = settings.getint("Strategy", "fastma")
		self.slowma = settings.getint("Strategy", "slowma")
		self.atrStop = self._getfloatsetting(settings, "Strategy", "atrStop")
		self.percentStop = self._getfloatsetting(settings, "Strategy", "percentStop")
Пример #9
0
 def __init__(self):
     Strategy.__init__(self)
     self.time_accumulated = 0
     self.bid = None
     self.time_change = 0
     self.parts_sold_today = 0
     self.bid_size = 0
     self.current_hour = datetime.today().hour
     self.transactions = market_controller.transactions()
     self.read_last_iteration_info()
	def __init__(self, settings, watchlist, tradeManager):
		Strategy.__init__(self, watchlist, tradeManager)
		
		self.minprice = settings.getfloat("Strategy", "minprice")
		self.minvolume = settings.getint("Strategy", "minvolume")
		self.mingap = settings.getfloat("Strategy", "mingap")
		self.dailysmatrendfilter = self._getintsetting(settings,"Strategy", "dailysmatrendfilter")
		self.target = self._getfloatsetting(settings, "Strategy", "target")
		self.minhour = settings.getint("Strategy", "minhour")
		self.maxhour = settings.getint("Strategy", "maxhour")
		self.donchianstop = settings.getint("Strategy", "donchianstop")
Пример #11
0
	def __init__(self, settings, watchlist, tradeManager):
		Strategy.__init__(self, watchlist, tradeManager)
		self.minprice = settings.getfloat("Strategy", "minprice")
		self.timescale = settings.getint("Strategy", "timescale")
		self.period = settings.getint("Strategy", "period")
		self.bandwidth = settings.getfloat("Strategy", "bandwidth")
		self.bandStop = self._getfloatsetting(settings, "Strategy", "bandStop")
		self.percentStop = self._getfloatsetting(settings, "Strategy","percentStop")
		self.sma = self._getintsetting(settings, "Strategy", "smafilter")
		self.exitAtOtherBand = self._getboolsetting(settings, "Strategy", "exitAtOtherBand")
		self.doLong = self._getboolsetting(settings, "Strategy", "doLong")
		self.doShort = self._getboolsetting(settings, "Strategy", "doShort")
Пример #12
0
 def __init__(self, near_term_option, next_term_option):
     Strategy.__init__(
         self, [near_term_option, next_term_option], name='Calendar Spread')
     # Check both options have the same underlying
     if near_term_option.ticker != next_term_option.ticker:
         raise ValueError(
             'Calendar options must refer to the same underlying')
     else:
         self.ticker = near_term_option.ticker
     # Check both options have the same strike
     if near_term_option.strike != next_term_option.strike:
         raise ValueError('Calendar options must refer to the same strike. '
                          'Try a diagonal spread instead')
     else:
         self.strike = near_term_option.strike
     # Check the options have different expiry dates
     if near_term_option.expiration == next_term_option.expiration:
         raise ValueError('Calendar options must have different expiry '
                          'dates')
     else:
         # Consider to swap input options if given near_term > next_term
         if near_term_option.expiration > next_term_option.expiration:
             self.near_term_opt = next_term_option
             self.next_term_opt = near_term_option
         else:
             self.near_term_opt = near_term_option
             self.next_term_opt = next_term_option
     # Check that one option is short and the other is long
     if((abs(near_term_option.amount) != abs(next_term_option.amount)) or
        (near_term_option.amount + next_term_option.amount != 0)):
         raise ValueError('Near term and next term option number must be '
                          'the same, but with different sign')
     else:
         # Next term option gives the sign of the calendar
         self.amount = next_term_option.amount
     # Check that both options are call or put
     if near_term_option.right != next_term_option.right:
         raise ValueError('Calendar options must be of the same kind')
     else:
         self.right = near_term_option.right
     # Get calendar debit value per each (near_term, next term) pair
     self.debit = (
         near_term_option.get_price() + next_term_option.get_price())
     # Get calendar greeks
     # TODO review if they can be summed in Passarelli's book (deltas can)
     self.delta = (
         near_term_option.get_delta() + next_term_option.get_delta())
     self.gamma = (
         near_term_option.get_gamma() + next_term_option.get_gamma())
     self.theta = (
         near_term_option.get_theta() + next_term_option.get_theta())
     self.vega = near_term_option.get_vega() + next_term_option.get_vega()
Пример #13
0
    def __init__(self, rest, params):
        Strategy.__init__(self, rest, debug=params['debug'])

        if self.debug:
            pprint('params: %s' % str(params))
        self.spread = params['spread']
        self.trade_size = params['trade_size']
        self.dump_on_lockdown = params['dump_on_lockdown']
        self.max_distance = params['max_distance']
        self.shading = params['shading']
        self.stop_loss = params.get('stop_loss')
        self.max_inactive_time = params.get('max_inactive_time')
        self.speak = params.get('speak')

        self.time_of_last_bid = 0.
Пример #14
0
    def __init__(self):
        Strategy.__init__(self)

        # Strategy parameters
        self.direction = None  # str. Initial long or short direction.
        self.start_zone = None  # str. Starting operating zone name.
        self.p0 = None  # float. Starting price as the middle of start zone.
        self.pls = None  # float. Price trailing percentage as indicator of trend reversal.
        self.ph = None  # float. Minimum swing price height.
        self.pt = None  # float. Universal price trailing amount.
        self.q_max = 0  # int. Max position quantity.
        self.qa = 0  # int. Oscillatory base quantity.
        self.q_offset = {zone_name: (0, 0) for zone_name in self.ZONE_NAMES}  # Oscillatory quantity offsets.
        self.g_risky = None  # float. Risky zone activate loss ratio.
        self.g0 = None  # float. Profit gain starting ratio for stop win.
        self.gt = None  # float. Profit gain trailing ratio for stop win.

        # Strategy states
        self._state = self.SWING_GRID_OSC
        self._long_short = None  # Binary trading state. 0: long, 1: short.
        self._state_cleanup = False  # If the current state in the cleanup stage.
        self._next_state_after_cleanup = None  # The next state after cleanup finishes.

        # SWING_GRID_OSC
        self._zones = {}  # Dict of zone objects.
        self._start_zone = None
        self._start_zone_mid_price = None
        self._active_zone = None  # Reference to the current active operating zone.
        self._dec_peak = None  # Peak price in Dec zone.

        # SWING_REVERSAL
        self._reversal_orders = []

        # SWING_RISKY_INIT & SWING_RISKY_OSC
        self._risky_base_val = 0.0
        self._risky_base_qty = 0
        self._risky_cut_qty = 0
        self._risky_cut_price = 0.0
        self._risky_init_order_qty = 0
        self._risky_init_orders = []
        self._risky_osc_zone = None

        # SWING_STOP
        self._max_gain = float('-inf')  # max profit for trailing close
        self._stop_orders = []
Пример #15
0
    def __init__(self,
                 start_date,
                 end_date,
                 initial_position,
                 market,
                 params,
                 h5file=None):
        Strategy.__init__(self, start_date, end_date, initial_position, market,
                          params, h5file)
        for symbol in initial_position.keys():
            if symbol == "$":
                continue

            self.addIndicator(symbol, "value", SimpleValue())
            try:
                short = params['short']
            except KeyError:
                short = Trending.DEF_SHORT_DAYS
            self.addIndicator(symbol, "short", EMA(short))
            try:
                long_ = params['long']
            except KeyError:
                long_ = Trending.DEF_LONG_DAYS
            self.addIndicator(symbol, "long", EMA(long_))
            try:
                rsi = params['rsi']
            except KeyError:
                rsi = Trending.DEF_RSI_PERIOD
            self.addIndicator(symbol, "rsi", RSI(rsi))

        # Backfill the indicators
        try:
            backfill = params['backfill']
        except KeyError:
            backfill = long_

        d = start_date - (backfill * ONE_DAY)
        self.updateIndicators(d, start_date)
Пример #16
0
 def __init__(self,config):
   Strategy.__init__(self,config)
   self.placer = Placer(config)
   self.picker = Picker(config)
Пример #17
0
 def __init__(self, search_strategy="hamm"):
     Strategy.__init__(self,
                       search_order="LRUD",
                       max_depth=20,
                       heuristic=None,
                       search_strategy=search_strategy)
 def __init__(self):
     Strategy.__init__(self)
     self.name = "Heuristic"
Пример #19
0
 def __init__(self, n=DEFAULT_N):
     '''
     Constructor
     '''
     Strategy.__init__(self)
     self._n = n  
    def __init__(self):
        self.difficulty = 2  # Either 1 or 2 or 3

        Strategy.__init__(self)
        self.name = "MiniMax"
Пример #21
0
 def __init__(self, config):
     Strategy.__init__(self, config)
     self.placer = Placer(config)
     self.picker = Picker(config)
Пример #22
0
 def __init__(self, color):
     Strategy.__init__(self, color)
 def __init__(self, game):
     Strategy.__init__(self, game)
     self._init_possibleMoves()
     self._init_legalMoves()
Пример #24
0
    def __init__(self, rest):
        Strategy.__init__(self, rest)

        self.initial_marking = 0.
        self.initialized = False
Пример #25
0
 def __init__(self):
     Strategy.__init__(self)
     self.target_vps_count = int(plebnet_settings.get_instance().strategy_vps_count())
Пример #26
0
 def __init__(self, logger):
     Strategy.__init__(self, logger)
     self.hour_volume = {}
     self.graph_trade = None
     self.graph_b1 = None
     self.graph_show_index = 0
Пример #27
0
 def __init__(self, search_order="LRUD"):
     Strategy.__init__(self, search_order=search_order)
Пример #28
0
 def __init__(self, data_handler):
     Strategy.__init__(self, data_handler)
     self.betas = []
     self.r_2 = []
     self.z_scores = []
     self.rs = []
Пример #29
0
 def __init__(self):
     Strategy.__init__(self, DummyRESTProtocol())
Пример #30
0
    def __init__(self, bars, balance_start, bankruptcy_at, multiplier, transaction_costs, slippage, timeperiod):

        Strategy.__init__(self, bars, balance_start, bankruptcy_at, multiplier, transaction_costs, slippage)

        pdta.SETTINGS.join = False
        self.indicator = pdta.MA(self.bars_pd, timeperiod)
 def __init__(self, logger):
     Strategy.__init__(self, logger)
     self.spreads = []
 def __init__(self):
     Strategy.__init__(self, constants.Strategies.RANDOM)
Пример #33
0
 def __init__(self, cash, prices, step=60, slow=10, fast=5, threshold=0):
     Strategy.__init__(self, cash, prices, step)
     self._slow = slow
     self._fast = fast
     self._ma = {}
     self._threshold = threshold
Пример #34
0
 def __init__(self):
     '''
     Constructor
     '''
     Strategy.__init__(self)
Пример #35
0
 def __init__(self):
     Strategy.__init__(self)
     self.name = "Random"
Пример #36
0
 def __init__(self, search_order="DLRU"):
     search_order = search_order[::-1]
     Strategy.__init__(self, search_order=search_order)