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

Pool state updated within policy function #75

Open
markusbkoch opened this issue Mar 7, 2021 · 1 comment
Open

Pool state updated within policy function #75

markusbkoch opened this issue Mar 7, 2021 · 1 comment
Assignees

Comments

@markusbkoch
Copy link

Congrats on the work, everyone - this looks very good and will be super useful to the TE and Balancer communities.

I'd like to suggest an improvement: IIUC, the combination of the object oriented nature of your architecture plus the current logic defined in p_action_decoder is causing the pools state to be updated within the policy function and not the state update function.

eg

def p_join_pool(params, step, history, current_state, action):
"""
Join a pool by providing liquidity for all token_symbols.
"""
pool = current_state['pool']

...
pool['tokens'][symbol].balance += amount
pool['pool_shares'] = Decimal(pool['pool_shares']) + pool_amount_out

I verified this initial impression by commenting out this line and observing that the simulation returned the same results:

The implication is that all state update functions within the partial state update block read the updated pool state instead of the state at the previous substep as would be expected. Which doesn't break anything for this particular model because all other state variables are essentially metrics.

It might seem like a nitpick, but the separation of policy functions and state update functions and the purposes of each one is an issue we frequently face when introducing cadCAD concepts. cadCAD's flexibility enables us to do basically anything as long as we know what we're doing, but standardizing this sort of thing is IMO key to increasing the library's user base. More importantly, future versions might count on this best practice being the norm and introduce what would be breaking changes from this model's perspective.

My suggestion would be to split the current p_action_decoder into:

  1. a policy function that reads from action_df and returns action metadata
  2. a state update function that actually performs the updates

This would in turn require including a second partial state update block for computing metrics like the spot price

@randomshinichi randomshinichi self-assigned this Mar 11, 2021
@randomshinichi
Copy link
Collaborator

Not a nitpick - I've always felt that cadCAD should be stricter about some things. What things exactly, while not restricting flexibility too much? I have no idea. I think a good place to start thinking would be some form of standardization to allow cadCAD models to plug into other cadCAD models @markusbkoch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants