Scorum
betting_math.cpp
Go to the documentation of this file.
2 
3 namespace scorum {
4 namespace chain {
5 
7 
8 asset calculate_gain(const asset& bet_stake, const odds& odds)
9 {
10  FC_ASSERT(bet_stake.symbol() == SCORUM_SYMBOL, "Invalid symbol for stake");
11  auto result = bet_stake;
12  result *= odds;
13  result -= bet_stake;
14  return result;
15 }
16 
17 matched_stake_type
18 calculate_matched_stake(const asset& bet1_stake, const asset& bet2_stake, const odds& bet1_odds, const odds& bet2_odds)
19 {
20  FC_ASSERT(bet1_stake.symbol() == SCORUM_SYMBOL && bet1_stake.symbol() == bet2_stake.symbol(),
21  "Invalid symbol for stake");
22  FC_ASSERT((odds_fraction_type)bet1_odds == bet2_odds.inverted()
23  && (odds_fraction_type)bet2_odds == bet1_odds.inverted(),
24  "Odds for bet 1 ans bet 2 must make 1 in summ of it's probability");
25 
27 
28  auto r1 = bet1_stake * bet1_odds;
29  auto r2 = bet2_stake * bet2_odds;
30 
31  auto p1 = r1 - bet1_stake;
32  auto p2 = r2 - bet2_stake;
33 
34  if (r1 > r2)
35  {
36  result.bet1_matched = p2;
37  result.bet2_matched = bet2_stake;
38  }
39  else if (r1 < r2)
40  {
41  result.bet1_matched = bet1_stake;
42  result.bet2_matched = p1;
43  }
44  else
45  {
46  result.bet1_matched = bet1_stake;
47  result.bet2_matched = bet2_stake;
48  }
49 
50  return result;
51 }
52 }
53 }
odds_fraction_type inverted() const
Definition: odds.cpp:29
#define SCORUM_SYMBOL
Definition: config.hpp:102
asset calculate_gain(const asset &bet_stake, const odds &odds)
Definition: betting_math.cpp:8
matched_stake_type calculate_matched_stake(const asset &bet1_stake, const asset &bet2_stake, const odds &bet1_odds, const odds &bet2_odds)
utils::fraction< odds_value_type, odds_value_type > odds_fraction_type
Definition: odds.hpp:11
Definition: asset.cpp:15
asset_symbol_type symbol() const
Definition: asset.hpp:32