Skip to content

Commit

Permalink
Refactor prepare_for_run
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcintra committed Dec 26, 2023
1 parent 3e50307 commit 7cfc496
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions scripts/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pstats
import pdb
from datetime import datetime
from multiprocessing import cpu_count
from src.sim import run_scenario
from src.logging import get_logger

Expand Down Expand Up @@ -32,6 +33,5 @@ def without_analysis(num_iter, ncpu):

if __name__ == "__main__":
num_iter = 10
ncpu = 5
with_analysis(num_iter, ncpu)
with_analysis(num_iter, cpu_count())
# without_analysis(num_iter, ncpu)
10 changes: 5 additions & 5 deletions src/sim/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def generate_markets(self) -> pd.DataFrame:
int(end.timestamp()),
self.coins,
)
logger.debug("Using %d 1Inch quotes from %s to %s", quotes.shape[0], start, end)
logger.info("Using %d 1Inch quotes from %s to %s", quotes.shape[0], start, end)

self.markets: MarketsType = {}
for pair in self.pairs:
Expand Down Expand Up @@ -176,7 +176,7 @@ def prepare_for_run(self) -> None:
# Equilibrate pool prices
arbitrageur = Arbitrageur() # diff arbitrageur
profit, count = arbitrageur.arbitrage(self.cycles, sample)
logger.debug(
logger.info(
"Equilibrated prices with %d arbitrages with total profit %d", count, profit
)

Expand All @@ -185,13 +185,13 @@ def prepare_for_run(self) -> None:
to_liquidate = controller.users_to_liquidate()
n = len(to_liquidate)
if n > 0:
logger.debug("%d users were loaded underwater.", n)
logger.info("%d users were loaded underwater.", n)

# Check that only a small portion of debt is liquidatable at start
damage = 0
for pos in to_liquidate:
damage += pos.debt
logger.debug("Liquidating %s: with debt %d.", pos.user, pos.debt)
logger.info("Liquidating %s: with debt %d.", pos.user, pos.debt)
pct = round(damage / controller.total_debt() * 100, 2)
args = (
"%.2f%% of debt was incorrectly loaded with sub-zero health (%d crvUSD)",
Expand All @@ -201,7 +201,7 @@ def prepare_for_run(self) -> None:
if pct > 1:
logger.warning(*args)
else:
logger.debug(*args)
logger.info(*args)

controller.after_trades(do_liquidate=True) # liquidations

Expand Down
1 change: 1 addition & 0 deletions src/sim/scenarios/baseline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def simulate(
scenario_template = pickle.load(f)
else:
scenario_template = Scenario(config, market_name)
scenario_template.prepare_for_run()

logger.info(
"Running %d simulations with %d steps at frequency %s",
Expand Down
1 change: 0 additions & 1 deletion src/sim/scenarios/baseline/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __call__(
logger.info("STARTING new simulation %d", i)

scenario.generate_pricepaths() # produce new stochastic prices
scenario.prepare_for_run()

processor = SingleSimProcessor(scenario, self.metrics)

Expand Down

0 comments on commit 7cfc496

Please sign in to comment.