feat(PFW): compute_probe_amount and compute_average_price_impact#230
Conversation
e2d93f4 to
4ca80b9
Compare
dianacarvalho1
left a comment
There was a problem hiding this comment.
Thank you @tamaralipows ! 🙏🏼 it looks good to me! only have 1 question for my understanding
| if price_impact <= 0.0 { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
in which case is this possible? 🤔
There was a problem hiding this comment.
The pool has a flat pricing curve (e.g. stable-swap pools within their peg range). A verrryyy real example: WETH-ETH unwrapping.
| /// Returns `None` when the probe exceeds `config.max_probe × total_amount`, | ||
| /// signalling that splitting is not worthwhile. | ||
| #[allow(dead_code)] | ||
| fn compute_probe_amount( |
There was a problem hiding this comment.
why isn't this a method of the Algorithm struct? same for the compute_average_price_impact
There was a problem hiding this comment.
I've left them free because neither function needs &self - they're pure computations with explicit inputs. Keeping them as free functions also makes tests simpler: you can call them directly without constructing a full PathFrankWolfeAlgorithm (which in turn requires setting up BellmanFordAlgorithm).
I can also see the organization benefit of moving them into the algorithm though - so please see commit c8308f7 and let me know if you like that better!
Troshchk
left a comment
There was a problem hiding this comment.
Thank you!
I have a general question: why do we degrade the pools on the first path, as if the full trade already went through? Why would not we use max_probe, for example?
63984f1 to
f78e247
Compare
b7756e3 to
4f20708
Compare
@Troshchk There is more context about this in the story. This is actually a core property of the Frank-Wolfe method. In particular this line:
Keep in mind this step doesn't determine the split amount - it only finds candidate paths. We degrade by the full amount because that's what Frank-Wolfe requires: evaluate the descent direction at the current allocation (initially 100% on path 1). If we degraded by less, BF would see a less-stressed pool and might miss better alternatives or pick the wrong one. The actual split fraction is decided afterwards by golden-section line search (step 2f), which finds the optimal balance between the existing allocation and the new candidate. So this full degradation is just "where should I look next?", not "how much should I send there?" |
louise-poole
left a comment
There was a problem hiding this comment.
Small error message feedback, otherwise approved! Looks good 🚀
c6b06ac to
7ff2d81
Compare
louise-poole
left a comment
There was a problem hiding this comment.
Nice! Happy with this 👍
7ff2d81 to
6e651ca
Compare
9057f63 to
02f0623
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eAlgorithm Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ount Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
02f0623 to
4ac233d
Compare
No API Breaking Changes DetectedThe PR title signals breaking changes, but |
|
This PR is included in version 0.75.0 🎉 |
Task
Context: In the PFW algorithm, after we route the full trade through the best single path (via BF), we want to know: is there a second path worth splitting to? We can't just re-run BF at the full trade amount - BF would find the same path again because nothing changed. Instead, we:
Note: This part of the task is not relevant yet, but we should keep in mind that when calling these methods: