Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add monte-carlo scenario generator to simulator. #154

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bancor_research/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def read_price_feeds(price_feeds_path: str):
price_feeds.columns = [col.lower() for col in price_feeds.columns]
return price_feeds

__version__ = "2.0.3"
__version__ = "3.0.8"
11 changes: 0 additions & 11 deletions bancor_research/bancor_simulator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,4 @@
# --------------------------------------------------------------------------------------------------------------------
"""Spec and agent-based simulation modules for Bancor v3."""

import warnings

import bancor_research.bancor_simulator.v3.spec

with warnings.catch_warnings():
warnings.simplefilter("ignore", FutureWarning)
warnings.simplefilter("ignore", DeprecationWarning)

warnings.filterwarnings("ignore", category=FutureWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning)

__version__ = "2.0.2"
22 changes: 12 additions & 10 deletions bancor_research/bancor_simulator/v3/spec/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,12 @@ def trade_bnt_for_tkn(
direction,
)

if tkn_name in state.rolling_trade_fees:
state.rolling_trade_fees[tkn_name].append(trade_fee)
else:
state.rolling_trade_fees[tkn_name] = []
state.rolling_trade_fees[tkn_name].append(trade_fee)
if trade_fee > 0:
if tkn_name in state.rolling_trade_fees:
state.rolling_trade_fees[tkn_name].append(trade_fee)
else:
state.rolling_trade_fees[tkn_name] = []
state.rolling_trade_fees[tkn_name].append(trade_fee)

bnt_collected_by_vortex = vortex_collection(
bnt_trading_liquidity,
Expand Down Expand Up @@ -275,11 +276,12 @@ def trade_tkn_for_bnt(
direction,
)

if tkn_name in state.rolling_trade_fees:
state.rolling_trade_fees[tkn_name].append(trade_fee)
else:
state.rolling_trade_fees[tkn_name] = []
state.rolling_trade_fees[tkn_name].append(trade_fee)
if trade_fee > 0:
if tkn_name in state.rolling_trade_fees:
state.rolling_trade_fees[tkn_name].append(trade_fee)
else:
state.rolling_trade_fees[tkn_name] = []
state.rolling_trade_fees[tkn_name].append(trade_fee)

bnt_collected_by_vortex = vortex_collection(
bnt_trading_liquidity,
Expand Down
17 changes: 17 additions & 0 deletions bancor_research/bancor_simulator/v3/spec/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,25 @@ def __init__(self, balance: Decimal = Decimal("0")):

def add(self, value: Decimal):
self.validate_balance()
new_balance = self.balance + self.validate(value)
assert new_balance >= 0, ValueError(
"Balance must be non-negative. Cannot complete operation."
)
self.balance += self.validate(value)

def subtract(self, value: Decimal):
self.validate_balance()
new_balance = self.balance - self.validate(value)
assert new_balance >= 0, ValueError(
"Balance must be non-negative. Cannot complete operation."
)
self.balance -= self.validate(value)

def set(self, value: Decimal):
self.validate_balance()
assert self.validate(value) >= 0, ValueError(
"Balance must be non-negative. Cannot complete operation."
)
self.balance = self.validate(value)

def validate(self, value) -> Decimal:
Expand Down Expand Up @@ -710,6 +721,12 @@ def set_staked_balance(self, tkn_name: str, value: Decimal):
"""
self.tokens[tkn_name].staking_ledger.set(value)

def set_master_vault_balance(self, tkn_name: str, value: Decimal):
"""
Set the master_vault_balance balance to a given amount.
"""
self.tokens[tkn_name].master_vault.set(value)

def set_protocol_wallet_balance(self, tkn_name: str, value: Decimal):
"""
Set the protocol_wallet balance to a given amount.
Expand Down
2 changes: 1 addition & 1 deletion bancor_research/bancor_simulator/v3/spec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def enable_trading(state: State, tkn_name: str) -> State:
else:
log = f"Bootstrap requirements *not* met for {tkn_name}"
state.logger.info(log)
raise Exception(log)
print(log)

return state

Expand Down
1 change: 1 addition & 0 deletions bancor_research/scenario_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# --------------------------------------------------------------------------------------------------------------------
# Licensed under the MIT LICENSE. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------------------------------
from .monte_carlo_generator import MonteCarloGenerator
Loading