Skip to content

Commit

Permalink
Revert "Towards #387: rename "sim" -> "xpmt" (experiment)" (#569)
Browse files Browse the repository at this point in the history
This reverts commit 17a8631.
  • Loading branch information
calina-c authored Jan 24, 2024
1 parent e3ceba9 commit 8ef8105
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 73 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ pdr

This will output something like:
```text
Usage: pdr xpmt|predictoor|trader|..
Usage: pdr sim|predictoor|trader|..
Main tools:
pdr xpmt YAML_FILE
pdr sim YAML_FILE
pdr predictoor APPROACH YAML_FILE NETWORK
pdr trader APPROACH YAML_FILE NETWORK
...
Expand Down Expand Up @@ -68,7 +68,7 @@ This repo implements all bots in Predictoor ecosystem. Here are each of the sub-
Main bots & user tools:
- `predictoor` - submit individual predictions
- `trader` - buy aggregated predictions, then trade
- `xpmt` - experiments / simulation flow
- `sim` - experiments / simulation flow

OPF-run bots & higher-level tools:
- `trueval` - report true values to contract
Expand Down
9 changes: 3 additions & 6 deletions READMEs/predictoor.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ Copy [`ppss.yaml`](../ppss.yaml) into your own file `my_ppss.yaml` and change pa

Let's simulate! In console:
```console
pdr xpmt my_ppss.yaml
pdr sim my_ppss.yaml
```

"xpmt" is short for "experiment". (The xpmt tool is evolving beyond just simulation.)


What it does:
1. Set simulation parameters.
1. Grab historical price data from exchanges and stores in `parquet_data/` dir. It re-uses any previously saved data.
Expand Down Expand Up @@ -87,7 +84,7 @@ Update `my_ppss.yaml` as desired.

Then, run a bot with modeling-on-the fly (approach 3). In console:
```console
pdr predictoor 3 my_ppss.yaml sapphire-testnet
pdr predictoor 3 my_ppss.yaml sapphire-testnet
```

Your bot is running, congrats! Sit back and watch it in action. It will loop continuously.
Expand All @@ -114,7 +111,7 @@ Update `my_ppss.yaml` as desired.

Then, run the bot. In console:
```console
pdr predictoor 3 my_ppss.yaml sapphire-mainnet
pdr predictoor 3 my_ppss.yaml sapphire-mainnet
```

This is where there's real $ at stake. Good luck!
Expand Down
4 changes: 1 addition & 3 deletions READMEs/trader.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ Copy [`ppss.yaml`](../ppss.yaml) into your own file `my_ppss.yaml` and change pa

Let's simulate! In console:
```console
pdr xpmt my_ppss.yaml
pdr sim my_ppss.yaml
```

"xpmt" is short for "experiment". (The xpmt tool is evolving beyond just simulation.)

What it does:
1. Set simulation parameters.
1. Grab historical price data from exchanges and stores in `parquet_data/` dir. It re-uses any previously saved data.
Expand Down
8 changes: 4 additions & 4 deletions pdr_backend/cli/cli_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
HELP_LONG = """Predictoor tool
Transactions are signed with envvar 'PRIVATE_KEY`.
Usage: pdr xpmt|predictoor|trader|..
Usage: pdr sim|predictoor|trader|..
Main tools:
pdr xpmt PPSS_FILE
pdr sim PPSS_FILE
pdr predictoor APPROACH PPSS_FILE NETWORK
pdr trader APPROACH PPSS_FILE NETWORK
pdr lake PPSS_FILE NETWORK
Expand Down Expand Up @@ -348,7 +348,7 @@ def print_args(arguments: Namespace):
print(f"{arg_k}={arg_v}")


XpmtArgParser = _ArgParser_PPSS
SimArgParser = _ArgParser_PPSS

PredictoorArgParser = _ArgParser_APPROACH_PPSS_NETWORK

Expand Down Expand Up @@ -383,7 +383,7 @@ def print_args(arguments: Namespace):
FundAccountsArgParser = _ArgParser_FUND_ACCOUNTS_PPSS_NETWORK

defined_parsers = {
"do_xpmt": XpmtArgParser("Run experiment / simulation", "xpmt"),
"do_sim": SimArgParser("Run simulation", "sim"),
"do_predictoor": PredictoorArgParser("Run a predictoor bot", "predictoor"),
"do_trader": TraderArgParser("Run a trader bot", "trader"),
"do_lake": LakeArgParser("Run the lake tool", "lake"),
Expand Down
8 changes: 4 additions & 4 deletions pdr_backend/cli/cli_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pdr_backend.predictoor.approach1.predictoor_agent1 import PredictoorAgent1
from pdr_backend.predictoor.approach3.predictoor_agent3 import PredictoorAgent3
from pdr_backend.publisher.publish_assets import publish_assets
from pdr_backend.xpmt.xpmt_engine import XpmtEngine
from pdr_backend.sim.sim_engine import SimEngine
from pdr_backend.trader.approach1.trader_agent1 import TraderAgent1
from pdr_backend.trader.approach2.trader_agent2 import TraderAgent2
from pdr_backend.trueval.trueval_agent import TruevalAgent
Expand Down Expand Up @@ -51,14 +51,14 @@ def _do_main():


@enforce_types
def do_xpmt(args, nested_args=None):
def do_sim(args, nested_args=None):
ppss = PPSS(
yaml_filename=args.PPSS_FILE,
network="development",
nested_override_args=nested_args,
)
xpmt_engine = XpmtEngine(ppss)
xpmt_engine.run()
sim_engine = SimEngine(ppss)
sim_engine.run()


@enforce_types
Expand Down
8 changes: 4 additions & 4 deletions pdr_backend/cli/test/test_cli_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def test_do_help_long(capfd):


def test_print_args(capfd):
XpmtArgParser = defined_parsers["do_xpmt"]
parser = XpmtArgParser
args = ["xpmt", "ppss.yaml"]
SimArgParser = defined_parsers["do_sim"]
parser = SimArgParser
args = ["sim", "ppss.yaml"]
parsed_args = parser.parse_args(args)

print_args(parsed_args)

out, _ = capfd.readouterr()
assert "pdr xpmt: Begin" in out
assert "pdr sim: Begin" in out
assert "Arguments:" in out
assert "PPSS_FILE=ppss.yaml" in out
16 changes: 8 additions & 8 deletions pdr_backend/cli/test/test_cli_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
do_lake,
do_predictoor,
do_publisher,
do_xpmt,
do_sim,
do_topup,
do_create_accounts,
do_view_accounts,
Expand Down Expand Up @@ -354,12 +354,12 @@ def test_do_trueval(monkeypatch):


@enforce_types
def test_do_xpmt(monkeypatch):
def test_do_sim(monkeypatch):
mock_f = Mock()
monkeypatch.setattr(f"{_CLI_PATH}.XpmtEngine.run", mock_f)
monkeypatch.setattr(f"{_CLI_PATH}.SimEngine.run", mock_f)

with patch("pdr_backend.xpmt.xpmt_engine.plt.show"):
do_xpmt(MockArgParser_PPSS_NETWORK().parse_args())
with patch("pdr_backend.sim.sim_engine.plt.show"):
do_sim(MockArgParser_PPSS_NETWORK().parse_args())

mock_f.assert_called()

Expand All @@ -379,10 +379,10 @@ def test_do_main(monkeypatch, capfd):
assert "Predictoor tool" in capfd.readouterr().out

mock_f = Mock()
monkeypatch.setattr(f"{_CLI_PATH}.XpmtEngine.run", mock_f)
monkeypatch.setattr(f"{_CLI_PATH}.SimEngine.run", mock_f)

with patch("pdr_backend.xpmt.xpmt_engine.plt.show"):
with patch("sys.argv", ["pdr", "xpmt", "ppss.yaml"]):
with patch("pdr_backend.sim.sim_engine.plt.show"):
with patch("sys.argv", ["pdr", "sim", "ppss.yaml"]):
_do_main()

assert mock_f.called
8 changes: 4 additions & 4 deletions pdr_backend/ppss/ppss.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pdr_backend.ppss.payout_ss import PayoutSS
from pdr_backend.ppss.predictoor_ss import PredictoorSS
from pdr_backend.ppss.publisher_ss import PublisherSS
from pdr_backend.ppss.xpmt_ss import XpmtSS
from pdr_backend.ppss.sim_ss import SimSS
from pdr_backend.ppss.trader_ss import TraderSS
from pdr_backend.ppss.trueval_ss import TruevalSS
from pdr_backend.ppss.web3_pp import Web3PP
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
self.lake_ss = LakeSS(d["lake_ss"])
self.predictoor_ss = PredictoorSS(d["predictoor_ss"])
self.trader_ss = TraderSS(d["trader_ss"])
self.xpmt_ss = XpmtSS(d["xpmt_ss"])
self.sim_ss = SimSS(d["sim_ss"])
self.publisher_ss = PublisherSS(network, d["publisher_ss"])
self.trueval_ss = TruevalSS(d["trueval_ss"])
self.dfbuyer_ss = DFBuyerSS(d["dfbuyer_ss"])
Expand Down Expand Up @@ -110,7 +110,7 @@ def __str__(self):
s += f"payout_ss={self.payout_ss}\n"
s += f"predictoor_ss={self.predictoor_ss}\n"
s += f"trader_ss={self.trader_ss}\n"
s += f"xpmt_ss={self.xpmt_ss}\n"
s += f"sim_ss={self.sim_ss}\n"
s += f"trueval_ss={self.trueval_ss}\n"
s += f"web3_pp={self.web3_pp}\n"
return s
Expand Down Expand Up @@ -184,7 +184,7 @@ def mock_ppss(
ppss.trader_ss = TraderSS(
{
"feed": onefeed,
"xpmt_only": {
"sim_only": {
"buy_amt": "10 USD",
},
"bot_only": {"min_buffer": 30, "max_tries": 10, "position_size": 3},
Expand Down
4 changes: 2 additions & 2 deletions pdr_backend/ppss/xpmt_ss.py → pdr_backend/ppss/sim_ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@


@enforce_types
class XpmtSS(StrMixin):
class SimSS(StrMixin):
__STR_OBJDIR__ = ["d"]

def __init__(self, d: dict):
self.d = d # yaml_dict["xpmt_ss"]
self.d = d # yaml_dict["sim_ss"]

# handle log_dir
assert self.log_dir == os.path.abspath(self.log_dir)
Expand Down
4 changes: 2 additions & 2 deletions pdr_backend/ppss/test/test_ppss.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _test_ppss(yaml_filename=None, yaml_str=None, network=None):
assert ppss.predictoor_ss.aimodel_ss.approach == "LIN"
assert ppss.payout_ss.batch_size >= 0
assert 1 <= ppss.predictoor_ss.s_until_epoch_end <= 120
assert isinstance(ppss.xpmt_ss.do_plot, bool)
assert isinstance(ppss.sim_ss.do_plot, bool)
assert 0.0 <= ppss.trader_ss.fee_percent <= 0.99
assert "USD" in ppss.trader_ss.buy_amt_str
assert ppss.trueval_ss.batch_size >= 0
Expand All @@ -48,7 +48,7 @@ def _test_ppss(yaml_filename=None, yaml_str=None, network=None):
assert "dfbuyer_ss" in s
assert "payout_ss" in s
assert "predictoor_ss" in s
assert "xpmt_ss" in s
assert "sim_ss" in s
assert "trader_ss" in s
assert "trueval_ss" in s
assert "web3_pp" in s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,51 @@

from enforce_typing import enforce_types

from pdr_backend.ppss.xpmt_ss import XpmtSS
from pdr_backend.ppss.sim_ss import SimSS

_D = {"do_plot": False, "log_dir": "logs", "test_n": 2}


@enforce_types
def test_xpmt_ss():
ss = XpmtSS(_D)
def test_sim_ss():
ss = SimSS(_D)

# yaml properties
assert not ss.do_plot
assert "logs" in ss.log_dir
assert ss.test_n == 2

# str
assert "XpmtSS" in str(ss)
assert "SimSS" in str(ss)


@enforce_types
def test_xpmt_ss_bad():
def test_sim_ss_bad():
bad = copy.deepcopy(_D)
bad["test_n"] = -3

with pytest.raises(ValueError):
XpmtSS(bad)
SimSS(bad)

bad = copy.deepcopy(_D)
bad["test_n"] = "lit"

with pytest.raises(ValueError):
XpmtSS(bad)
SimSS(bad)


@enforce_types
def test_log_dir(tmpdir):
# rel path given; needs an abs path
d = copy.deepcopy(_D)
d["log_dir"] = "logs"
ss = XpmtSS(d)
ss = SimSS(d)
target_log_dir = os.path.abspath("logs")
assert ss.log_dir == target_log_dir

# abs path given
d = copy.deepcopy(_D)
d["log_dir"] = os.path.join(tmpdir, "logs")
ss = XpmtSS(d)
ss = SimSS(d)
target_log_dir = os.path.join(tmpdir, "logs")
assert ss.log_dir == target_log_dir
2 changes: 1 addition & 1 deletion pdr_backend/ppss/test/test_trader_ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pdr_backend.ppss.trader_ss import TraderSS, inplace_make_trader_fast

_D = {
"xpmt_only": {
"sim_only": {
"buy_amt": "10 USD",
"fee_percent": 0.01,
"init_holdings": ["10000.0 USDT", "0 BTC"],
Expand Down
8 changes: 4 additions & 4 deletions pdr_backend/ppss/trader_ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def __init__(self, d: dict):
) # yaml_dict["trader_ss"]

# --------------------------------
# yaml properties: xpmt only
# yaml properties: sim only
@property
def buy_amt_str(self) -> Union[int, float]:
"""How much to buy. Eg 10."""
return self.d["xpmt_only"]["buy_amt"]
return self.d["sim_only"]["buy_amt"]

@property
def fee_percent(self) -> str:
return self.d["xpmt_only"]["fee_percent"] # Eg 0.001 is 0.1%.Trading fee
return self.d["sim_only"]["fee_percent"] # Eg 0.001 is 0.1%.Trading fee

@property
def init_holdings_strs(self) -> List[str]:
return self.d["xpmt_only"]["init_holdings"] # eg ["1000 USDT", ..]
return self.d["sim_only"]["init_holdings"] # eg ["1000 USDT", ..]

@property
def tradetype(self) -> str:
Expand Down
Loading

0 comments on commit 8ef8105

Please sign in to comment.