Skip to content

Instantly share code, notes, and snippets.

@gpamfilis
Created August 27, 2017 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpamfilis/4b230bb5e23215c19c45524537355061 to your computer and use it in GitHub Desktop.
Save gpamfilis/4b230bb5e23215c19c45524537355061 to your computer and use it in GitHub Desktop.
__author__ = 'George Pamfilis'
import numpy as np
from itertools import combinations
from scipy.misc import comb
class Coupon(object):
def __init__(self, game_odds, game_system):
self.game_system = game_system
self.game_odds = game_odds
self.game_combinations = []
self.probabilities_outcome = np.ones(np.shape(game_odds)[0])
self.number_of_columns = []
self.return_per_columns = []
self.min_investment = 0.25
self.coupon_multiplier = 1.
self.multiplier_of_system = np.ones(np.shape(game_system)[0])
self.additional_columns = 0
def combine_events(self):
if np.shape(self.game_system)[0] == 0:
print('System Cannot be None,[]!!')
elif np.shape(self.game_system)[0] == 1:
self.game_combinations = np.array(list(combinations(self.game_odds * self.probabilities_outcome,
self.game_system[0])))
else:
for i in range(np.shape(self.game_system)[0]):
comb_of_one_sys = list(combinations(self.game_odds * self.probabilities_outcome, self.game_system[i]))
for j in range(np.shape(comb_of_one_sys)[0]):
comb_of_one_sys[j] = list(comb_of_one_sys[j])
self.game_combinations.append(comb_of_one_sys[j])
return dict(combos=self.game_combinations, columns=np.shape(self.game_combinations)[0])
def return_per_column(self):
g = 0
for k in range(np.shape(self.game_system)[0]):
f = comb(np.shape(self.game_odds)[0], self.game_system[k])
self.additional_columns = self.additional_columns + (f * self.multiplier_of_system[k])
g = g + f
cost = self.min_investment * self.additional_columns * self.coupon_multiplier
for j in range(np.shape(self.game_combinations)[0]):
self.game_combinations[j] = np.prod(self.game_combinations[j]) * self.min_investment * \
self.coupon_multiplier
start = np.zeros(np.shape(self.game_system)[0])
end = np.zeros(np.shape(self.game_system)[0])
mults = np.zeros(np.shape(self.game_system)[0])
for i in range(np.shape(self.game_system)[0]):
mults[i] = comb(np.shape(self.game_odds)[0], self.game_system[i], exact=True)
end[i] = np.sum(mults[0:i + 1])
for i in range(np.shape(self.game_system)[0] - 1):
start[i + 1] = end[i]
n = 0
for sys in range(np.shape(self.game_system)[0]):
for i in range(int(start[n]), int(end[n])):
self.game_combinations[i] = self.game_combinations[i] * self.multiplier_of_system[sys]
n += 1
coupon_returns = np.sum(self.game_combinations)
return dict(coupon_cost=cost, coupon_return=coupon_returns, revenue=coupon_returns-cost)
if __name__ == '__main__':
print("The coupon cost is the number of columns times the cost of each column")
for i in range(1, 5):
print("[---] system: {0}".format(i))
game = Coupon(np.array([1.17, 1.5, 1.8, 1.7, 2.7, 1.46]), [i])
events = game.combine_events()
print("coupon cost: 0.25*{0} = ".format(events["columns"]), events["columns"]*0.25)
print(game.return_per_column())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment