-
Notifications
You must be signed in to change notification settings - Fork 17
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
Ppu history #365
Ppu history #365
Conversation
Use the new `.calc_[be_price/size]()` methods when serializing to and from the `pps.toml` format and add an audit method which will warn about mismatched values and assign the clears table calculated values pre-write. Drop the `.lifo_update()` method and instead allow both `.size`/`.be_price` properties to exist (for non-ledger related uses of `Position`) alongside the new calc methods and only get fussy about *what* the properties are set to in the case of ledger audits. Also changes `Position.update()` -> `.add_clear()`.
The original implementation of `.calc_be_price()` wasn't correct since the real so called "price per unit" (ppu), is actually defined by a recurrence relation (which is why the original state-updated `.lifo_update()` approach worked well) and requires the previous ppu to be weighted by the new accumulated position size when considering a new clear event. The ppu is the price that above or below which the trader takes a win or loss on transacting one unit of the trading asset and thus it is the true "break even price" that determines making or losing money per fill. This patches fixes the implementation to use trailing windows of the accumulated size and ppu to compute the next ppu value for any new clear event as well as handle rare cases where the "direction" changes polarity (eg. long to short in a single order). The new method is `Position.calc_ppu()` and further details of the relation can be seen in the doc strings. This patch also includes a wack-ton of clean ups and removals in an effort to refine position management api for easier use in new backends: - drop `updaate_pps_conf()`, `load_pps_from_toml()` and rename `load_trands_from_ledger()` -> `load_pps_from_ledger()`. - extend `PpTable` to have a `.to_toml()` method which returns the active set of positions ready to be serialized to the `pps.toml` file which is collects from calling, - `PpTable.dump_active()` which now returns double dicts of the open/closed pp object maps. - make `Position.minimize_clears()` now iterate the clears table in chronological order (instead of reverse) and only drop fills prior to any zero-size state (the old reversed way can result incorrect history-size-retracement in cases where a position is lessened but not completely exited). - drop `Position.add_clear()` and instead just manually add entries inside `.update_from_trans()` and also add a `accum_size` and `ppu` field to ever entry thus creating a position "history" sequence of the ppu and accum size for every position and prepares for being and to show "position lifetimes" in the UI. - move fqsn getting into `Position.to_pretoml()`.
If we don't have a pos table built out already (in mem) we can't figure out the likely dst asset (since there's no pair entry to guide us) that we should use to search for withdrawal transactions; so move it later. Further this ports to the new api changes in `piker.pp`` that will land with #365.
If we don't have a pos table built out already (in mem) we can't figure out the likely dst asset (since there's no pair entry to guide us) that we should use to search for withdrawal transactions; so move it later. Further this ports to the new api changes in `piker.pp`` that will land with #365.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"could we maybe just drop the top level .size and be_price values and instead just arrange the clears table to make these rolling values more obvious?"
Sure, sounds good.
"it follows that maybe we should adjust the column order for each clears entry maybe to: dt, ppu, accum_size, price, size, cost, tid?"
Agreed.
... "my only concern is then the clears table entries will be a bit cramped horizontally?"
Mmmm not sure, id have to see an example.
Quick review of the code looks great.
If we don't have a pos table built out already (in mem) we can't figure out the likely dst asset (since there's no pair entry to guide us) that we should use to search for withdrawal transactions; so move it later. Further this ports to the new api changes in `piker.pp`` that will land with #365.
If we don't have a pos table built out already (in mem) we can't figure out the likely dst asset (since there's no pair entry to guide us) that we should use to search for withdrawal transactions; so move it later. Further this ports to the new api changes in `piker.pp`` that will land with #365.
If we don't have a pos table built out already (in mem) we can't figure out the likely dst asset (since there's no pair entry to guide us) that we should use to search for withdrawal transactions; so move it later. Further this ports to the new api changes in `piker.pp`` that will land with #365.
If we don't have a pos table built out already (in mem) we can't figure out the likely dst asset (since there's no pair entry to guide us) that we should use to search for withdrawal transactions; so move it later. Further this ports to the new api changes in `piker.pp`` that will land with #365.
Proper fixes and terminology to get us ready for historical position lifetimes as described in #345.
More to come in terms of explanation... or not 😂
pps.toml
format changes:.size
andbe_price
values ?Position
type internally as well and doesn't track all theclears (since that would be more msging overhead) so I think maybe having these is fine but we should probably
change
.be_price
->.ppu
?which would be easiest to read if we sort clears reverse chronological so that the most recent trades (and thus their
ppu
andaccum_size
entries would be closest to the top?dt, ppu, accum_size, price, size, cost, tid
?[ ] i was hoping to have an indent per account (mentioned it in Positioning system refinements: paper engine, file writing, toml style and perf #345 as part of a custom encoder) such that it's distinguishable which pps are grouped together by backend, my only concern is then the clears table entries will be a bit cramped horizontally?delaying this one again