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

calc abs max short guess #202

Merged
merged 19 commits into from
Dec 18, 2024
Merged

calc abs max short guess #202

merged 19 commits into from
Dec 18, 2024

Conversation

dpaiton
Copy link
Contributor

@dpaiton dpaiton commented Oct 16, 2024

improves the function for calculating the absolute max short.

We use a linear approximation that passes the test 99.67% of the time (7441/7465 passed). There is an additional loop to ensure the remaining tests pass. Future work should be to fix the linear estimate to remove this loop -- it should not be required if the theory & code are correct.

Additional changes:

  • removed the solidity comparison test for calculate_absolute_max_short. This was failing in cases when solidity was successful and erroneous. The new (rust) starting point obtained by the approximate estimate can succeed when the old (solidity) function fails, and it can also result in a lower final value than the solidity version. Follow-up PRs will add more tests that concretely demonstrate tolerances for final solvency after opening the max short. Once we are happy with the Rust version, we can port the code back over to Solidity & add back the parity tests.
  • improved docstrings & comments for format & variable consistency
  • renamed calculate_spot_price to calculate_spot_price_down and added a *_up version -- this is helpful for over/under estimating the price in the approximation code.
  • made functions for calculating the minimum share reserves and the total fees paid when opening a short to dry up duplicate versions.
  • added a new check and cleaned up error messaging/comments in solvency_after_short
  • modified final liquidity provision in preamble to ensure short is possible given exposure from earlier random trades.
  • modified some tests ensure a short is possible before conducting the test

Derivation of approximate function

image
image
image
image
image

@dpaiton dpaiton force-pushed the dpaiton/calc-abs-max-short branch 3 times, most recently from 0cbfffe to 4cc1f81 Compare November 25, 2024 18:11
@dpaiton dpaiton changed the title calc abs max short calc abs max short guess Nov 26, 2024
@dpaiton dpaiton force-pushed the dpaiton/calc-abs-max-short branch from 57159bb to 12f2a29 Compare December 3, 2024 22:45
@dpaiton dpaiton marked this pull request as ready for review December 3, 2024 22:53
@dpaiton dpaiton mentioned this pull request Dec 10, 2024
7 tasks
@dpaiton dpaiton force-pushed the dpaiton/calc-abs-max-short branch from 9fbc55d to 89d3725 Compare December 16, 2024 16:36
@dpaiton dpaiton force-pushed the dpaiton/calc-abs-max-short branch from 6d6e635 to ee792ad Compare December 17, 2024 19:06
Copy link
Contributor

@jrhea jrhea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work!

@dpaiton dpaiton merged commit 7b44c25 into main Dec 18, 2024
8 checks passed
@dpaiton dpaiton deleted the dpaiton/calc-abs-max-short branch December 18, 2024 00:03
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

Successfully merging this pull request may close these issues.

2 participants