Exemple #1
0
    def handle_race(self, ex, race):
        if race['event'] == TO_BE_PLACED or race['n_runners'] < 3:
            return

        runners = race['selection']
        if np.all(self.hm.get_runs(runners) >= self.min_races):
            prices = ex.get_market_prices(race['market_id'])
            prices = dict(map(lambda x: (x['selection'], x), prices))
            odds = np.array(
                map(lambda r: prices[r]['back_prices'][0]['price'], runners))
            implied = get_implied_from_odds(odds)
            p = self.hm.pwin_trapz(runners)

            rel = p / implied - 1.0
            t = 0.05

            p[rel < -t] = implied[rel < -t] * 0.95
            p[rel > t] = implied[rel > t] * 1.05

            w = risk.nwin1_l2reg(p, odds, self.risk_aversion)

            returns = risk.nwin1_bet_returns(w, odds)
            if np.any(returns <= -self.max_expsoure):
                logging.warning('Maximum exposure limit of %.2f reached!' %
                                self.max_expsoure)
                logging.warning(
                    'Ignoring bets w=%s runners=%s with potential returns=%s' %
                    (w.tolist(), runners, returns.tolist()))
            else:
                logging.info(
                    'Betting on market_id=%s: |exposure|=%.2f collateral=%.2f'
                    % (race['market_id'], np.sum(np.abs(w)), np.min(returns)))
                bets = ({
                    'selection_id': prices[r]['selection_id'],
                    'amount': w[i],
                    'data': {
                        'p': p[i],
                        'implied': implied[i]
                    }
                } for i, r in enumerate(runners))
                ex.place_exchange_bets(race['market_id'], bets)

        if 'ranking' in race:
            self.hm.fit_race(race)
    def handle_race(self, ex, race):
        if race['event'] == TO_BE_PLACED or race['n_runners'] < 3:
            return

        runners = race['selection']
        if np.all(self.hm.get_runs(runners) >= self.min_races):
            prices = ex.get_market_prices(race['market_id'])
            prices = dict(map(lambda x: (x['selection'], x), prices))
            odds = np.array(map(lambda r: prices[r]['back_prices'][0]['price'], runners))
            implied = get_implied_from_odds(odds)
            p = self.hm.pwin_trapz(runners)

            rel = p / implied - 1.0
            t = 0.05

            p[rel < -t] = implied[rel < -t] * 0.95
            p[rel > t] = implied[rel > t] * 1.05

            w = risk.nwin1_l2reg(p, odds, self.risk_aversion)

            returns = risk.nwin1_bet_returns(w, odds)
            if np.any(returns <= -self.max_expsoure):
                logging.warning('Maximum exposure limit of %.2f reached!' % self.max_expsoure)
                logging.warning('Ignoring bets w=%s runners=%s with potential returns=%s'
                                % (w.tolist(), runners, returns.tolist()))
            else:
                logging.info('Betting on market_id=%s: |exposure|=%.2f collateral=%.2f' %
                             (race['market_id'], np.sum(np.abs(w)), np.min(returns)))
                bets = ({'selection_id': prices[r]['selection_id'],
                         'amount': w[i],
                         'data': {
                             'p': p[i],
                             'implied': implied[i]
                         }
                        } for i, r in enumerate(runners))
                ex.place_exchange_bets(race['market_id'], bets)

        if 'ranking' in race:
            self.hm.fit_race(race)
Exemple #3
0
 def calculate_collateral(group):
     return np.min(
         risk.nwin1_bet_returns(group.amount.values, group.odds.values))
 def calculate_collateral(group):
     return np.min(risk.nwin1_bet_returns(group.amount.values, group.odds.values))