hkjc 0.3.2__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hkjc
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Library for scrapping HKJC data and perform basic analysis
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: cachetools>=6.2.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hkjc"
3
- version = "0.3.2"
3
+ version = "0.3.4"
4
4
  description = "Library for scrapping HKJC data and perform basic analysis"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -27,7 +27,7 @@ def _process_single_qp_trade(banker: int, covered: List[int], odds_pla: List[flo
27
27
  return (banker, covered, win_prob, exp_value, ave_odds)
28
28
 
29
29
 
30
- def generate_all_qp_trades(date: str, venue_code: str, race_number: int, rebate: float = 0.12, harville_fit=True) -> pl.DataFrame:
30
+ def generate_all_qp_trades(date: str, venue_code: str, race_number: int, rebate: float = 0.12, harville_fit=False) -> pl.DataFrame:
31
31
  """Generate all possible qp tickets for the specified race.
32
32
 
33
33
  Args:
@@ -35,7 +35,7 @@ def generate_all_qp_trades(date: str, venue_code: str, race_number: int, rebate:
35
35
  venue_code (str): Venue code, e.g., 'ST' for Shatin, 'HV' for Happy Valley.
36
36
  race_number (int): Race number.
37
37
  rebate (float, optional): The rebate percentage. Defaults to 0.12.
38
- harville_fit (bool, optional): Whether to fit the odds using Harville model. Defaults to True.
38
+ harville_fit (bool, optional): Whether to fit the odds using Harville model. Defaults to False.
39
39
 
40
40
  Returns:
41
41
  pl.DataFrame: DataFrame with all possible trades and their metrics.
@@ -48,11 +48,12 @@ def generate_all_qp_trades(date: str, venue_code: str, race_number: int, rebate:
48
48
 
49
49
  if harville_fit:
50
50
  ho = HarvilleOptimizer(N)
51
- fit_res = ho.fit(1/odds['WIN'], 1/odds['QIN'],
52
- 1/odds['QPL'], 1/odds['PLA'])
51
+ prob = {k: np.nan_to_num(1/v, 0) for k,v in odds.items()}
52
+ fit_res = ho.fit(prob['WIN'], prob['QIN'],
53
+ prob['QPL'], prob['PLA'])
53
54
  if fit_res['success']:
54
- odds['PLA'] = 1/fit_res['b_fitted']
55
- odds['QPL'] = 1/fit_res['Q_fitted']
55
+ odds['PLA'] = np.nan_to_num(1/fit_res['b_fitted'], posinf=0)
56
+ odds['QPL'] = np.nan_to_num(1/fit_res['Q_fitted'], posinf=0)
56
57
 
57
58
  results = [_process_single_qp_trade(banker, covered, odds['PLA'], odds['QPL'], rebate)
58
59
  for banker in tqdm(candidates, desc="Processing bankers")
@@ -64,7 +65,7 @@ def generate_all_qp_trades(date: str, venue_code: str, race_number: int, rebate:
64
65
  return df
65
66
 
66
67
 
67
- def generate_pareto_qp_trades(date: str, venue_code: str, race_number: int, rebate: float = 0.12, groupby: List[str] = []) -> pl.DataFrame:
68
+ def generate_pareto_qp_trades(date: str, venue_code: str, race_number: int, rebate: float = 0.12, groupby: List[str] = [], harville_fit=False) -> pl.DataFrame:
68
69
  """Generate qp tickets that are Pareto optimal for the specified race.
69
70
 
70
71
  Args:
@@ -73,11 +74,12 @@ def generate_pareto_qp_trades(date: str, venue_code: str, race_number: int, reba
73
74
  race_number (int): Race number.
74
75
  rebate (float, optional): The rebate percentage. Defaults to 0.12.
75
76
  groupby (List[str], optional): Columns to group by when determining Pareto optimality. Defaults to [] (global optimal).
77
+ harville_fit (bool, optional): Whether to fit the odds using Harville model. Defaults to False.
76
78
 
77
79
  Returns:
78
80
  pl.DataFrame: DataFrame with all Pareto trades and their metrics.
79
81
  """
80
- df = generate_all_qp_trades(date, venue_code, race_number, rebate)
82
+ df = generate_all_qp_trades(date, venue_code, race_number, rebate, harville_fit=harville_fit)
81
83
  pareto_df = _pareto_filter(df, groupby=groupby, by=[
82
84
  'WinProb', 'ExpValue'], maximize=True)
83
85
  return pareto_df
@@ -97,7 +97,7 @@ wheels = [
97
97
 
98
98
  [[package]]
99
99
  name = "hkjc"
100
- version = "0.3.2"
100
+ version = "0.3.4"
101
101
  source = { editable = "." }
102
102
  dependencies = [
103
103
  { name = "cachetools" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes