Skip to content

Instantly share code, notes, and snippets.

@DamnWidget
Created December 14, 2012 16:21
Show Gist options
  • Save DamnWidget/4286638 to your computer and use it in GitHub Desktop.
Save DamnWidget/4286638 to your computer and use it in GitHub Desktop.
nre refactored function inside an object
def _exposure_adjust(self):
"""
Calculates de overall effect of this bet to exposures & stakes
"""
adjustments = {
'exposure_win': Decimal('0.0'),
'exposure_place': Decimal('0.0'),
'stake_win': Decimal('0.0'),
'stake_place': Decimal('0.0'),
'stake_sp': Decimal('0.0'),
'bet_exposure': Decimal('0.0'),
'bet_payout': Decimal('0.0')
}
exposure_place = 0
if not self.is_each_way:
stake = self.stake
else:
# retrieve each-way betting details
result_count, result = self._get_each_way_details()
if result_count == 0:
raise BetAcceptFailed
stake = self.stake / 2
odds_price = ((self.price - 1) / result['place_odds_divisor'])
exposure_place = odds_price * stake
adjustments['stake_place'] = stake
adjustments['exposure_place'] = exposure_place
exposure_win = (self.price - 1) * stake + exposure_place
bet_exposure = exposure_win.quantize(1 / 10 ** 2)
if self.is_starting_price:
if self.price > 0:
adjustments['bet_exposure'] = bet_exposure
adjustments['stake_sp'] = self.stake
else:
adjustments['exposure_win'] = exposure_win
adjustments['stake_win'] = stake
adjustments['bet_exposure'] = bet_exposure
adjustments['bet_payout'] = bet_exposure
return adjustments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment