diff --git a/packages/packages.json b/packages/packages.json index f5cdcbf7f..0a6e0ec40 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -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", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index 246b800fb..4396e55d4 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -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 diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index d9a3129f8..052d95608 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -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: {} --- diff --git a/strategies/kelly_criterion.py b/strategies/kelly_criterion.py index 388f459f2..cbe4cc4f9 100644 --- a/strategies/kelly_criterion.py +++ b/strategies/kelly_criterion.py @@ -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]: @@ -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( @@ -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 = []