Skip to content

Commit

Permalink
Merge pull request #171 from valory-xyz/feat/max-bet
Browse files Browse the repository at this point in the history
Add a max bet parameter for the bankroll's adjustment
  • Loading branch information
Adamantios authored Dec 6, 2023
2 parents e0aee95 + be4a72b commit 5a7fcd9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"skill/valory/decision_maker_abci/0.1.0": "bafybeibqncxj2gijdrglaeg5f3sjpsde4hw3vlltfz3lrxidt4lcu5lrxu",
"skill/valory/trader_abci/0.1.0": "bafybeihb3u5asle3i43uffzs4johkxu2qnswiewjugzhxtlthmb4py6j4y",
"contract/valory/market_maker/0.1.0": "bafybeid5jnetbsusgxkpqzwyiqlwut55xktfbeloipxcemcuu5oopmqtl4",
"agent/valory/trader/0.1.0": "bafybeidcovbb3efuufbeldvmhn3khpl57nq6srhwakxzj4h56duggyz3tm",
"service/valory/trader/0.1.0": "bafybeia6qr63f3favmxkqfcfyd5b5ydyom6o7qtiyrz4oq3yjar2b62znq",
"agent/valory/trader/0.1.0": "bafybeiejzq4tqdsjzrinmmcvsahsdzztefc73wvobnrpggxslp3p3lg76u",
"service/valory/trader/0.1.0": "bafybeigmzt3cscoacgasxwb26qwppwdfp6uhumnk2cmyygmrrrprlymk2m",
"contract/valory/erc20/0.1.0": "bafybeiepg5ymxhtylgijs3mf3lezz6cwcsougbrv2gr4xcq3bp5wxusi64",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeifgq5zgxcwzdlwixu5lfe34a4m4ddqqv7xzxhir47yn7tavg3fdki",
"contract/valory/mech/0.1.0": "bafybeieo65rtidzgrx22la7z7azoqbisd35hnoqfw7l3xxctotvctjlkju",
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ models:
agent_balance_threshold: ${int:10000000000000000}
refill_check_interval: ${int:10}
tool_punishment_multiplier: ${int:1}
file_hash_to_strategies_json: ${list:[["bafybeiauu6lecgrxlqlexaorsnpbzj6beto7kagdx6zawqx6z5fo5wmxhy",["bet_amount_per_threshold"]],["bafybeid7xyoqfskjumerc7tj2ykmfprem63oyxj5hyy2ts2zckfq7zutte",["kelly_criterion"]]]}
file_hash_to_strategies_json: ${list:[["bafybeiauu6lecgrxlqlexaorsnpbzj6beto7kagdx6zawqx6z5fo5wmxhy",["bet_amount_per_threshold"]],["bafybeidbmi5zgp2ygprb3br6xpfvmty474cy3eeib5ynslispp4iijwpoe",["kelly_criterion"]]]}
strategies_kwargs: ${list:[["bet_kelly_fraction",1.0],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":0,"0.7":0,"0.8":0,"0.9":0,"1.0":0}]]}
---
public_id: valory/p2p_libp2p_client:0.1.0
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeidcovbb3efuufbeldvmhn3khpl57nq6srhwakxzj4h56duggyz3tm
agent: valory/trader:0.1.0:bafybeiejzq4tqdsjzrinmmcvsahsdzztefc73wvobnrpggxslp3p3lg76u
number_of_agents: 4
deployment: {}
---
Expand Down
29 changes: 18 additions & 11 deletions strategies/kelly_criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@

from typing import Dict, Any, List, Union

REQUIRED_FIELDS = (
# the fraction of the calculated kelly bet amount to use for placing the bet
"bet_kelly_fraction",
"bankroll",
"win_probability",
"confidence",
"selected_type_tokens_in_pool",
"other_tokens_in_pool",
"bet_fee",
"floor_balance",
REQUIRED_FIELDS = frozenset(
{
# the fraction of the calculated kelly bet amount to use for placing the bet
"bet_kelly_fraction",
"bankroll",
"win_probability",
"confidence",
"selected_type_tokens_in_pool",
"other_tokens_in_pool",
"bet_fee",
"floor_balance",
}
)
OPTIONAL_FIELDS = frozenset({"max_bet"})
ALL_FIELDS = REQUIRED_FIELDS.union(OPTIONAL_FIELDS)
DEFAULT_MAX_BET = 8e17


def check_missing_fields(kwargs: Dict[str, Any]) -> List[str]:
Expand All @@ -45,7 +50,7 @@ def check_missing_fields(kwargs: Dict[str, Any]) -> List[str]:

def remove_irrelevant_fields(kwargs: Dict[str, Any]) -> Dict[str, Any]:
"""Remove the irrelevant fields from the given kwargs."""
return {key: value for key, value in kwargs.items() if key in REQUIRED_FIELDS}
return {key: value for key, value in kwargs.items() if key in ALL_FIELDS}


def calculate_kelly_bet_amount(
Expand Down Expand Up @@ -102,10 +107,12 @@ def get_bet_amount_kelly( # pylint: disable=too-many-arguments
other_tokens_in_pool: int,
bet_fee: int,
floor_balance: int,
max_bet: int = DEFAULT_MAX_BET,
) -> Dict[str, Union[int, List[str]]]:
"""Calculate the Kelly bet amount."""
# keep `floor_balance` xDAI in the bankroll
bankroll_adj = bankroll - floor_balance
bankroll_adj = min(bankroll_adj, max_bet)
bankroll_adj_xdai = wei_to_native(bankroll_adj)
info = [f"Adjusted bankroll: {bankroll_adj_xdai} xDAI."]
error = []
Expand Down

0 comments on commit 5a7fcd9

Please sign in to comment.