max_pain_chart #23

Open
ntorres wants to merge 2 commits from max_pain_chart into max_pain_deribit
Collaborator

Here we have a replicate for the deribit’s max pain chart.

Using pyqtgprah and the following classes BarGraphItem (OI calls/puts by strikes), ScatterPlotItem (Intrinsic value by strikes) and InfiniteLine (Max pain’s strike price): commit

Math and logic for the intrinsic_values and max_pain’s strike price) in a separate function: commit

How to test it? (same as #13)

Before start: in order to get this working with uv, you must use my tractor fork and this branch: aio_abandons, the reason is that I cherry-pick the uv_migration that guille made, for some reason that a didn’t dive into, my system needs tractor using uv too. quite hacky I guess.

  1. uv lock

  2. uv run --no-dev python examples/max_pain.py

  3. A message should be display, enter one of the expiration date available.

image
Here we have a replicate for the [deribit's max pain chart](https://www.deribit.com/statistics/BTC/metrics/options). Using pyqtgprah and the following classes `BarGraphItem` (OI calls/puts by strikes), `ScatterPlotItem` (Intrinsic value by strikes) and `InfiniteLine` (Max pain's strike price): [commit](https://pikers.dev/pikers/piker/commit/988f9c9455cc12630d31dd4a48b5210dcbfd291a) Math and logic for the `intrinsic_values` and `max_pain`'s strike price) in a separate function: [commit](https://pikers.dev/pikers/piker/commit/f0fd447af777085e15d623c6fc781ec131b30975) ### How to test it? (same as #13) **Before start:** in order to get this working with `uv`, you must use my `tractor` fork and this branch: `aio_abandons`, the reason is that I `cherry-pick` the `uv_migration` that guille made, for some reason that a didn’t dive into, my system needs tractor using uv too. quite hacky I guess. 1. `uv lock` 2. `uv run --no-dev python examples/max_pain.py` 3. A message should be display, enter one of the expiration date available. ![image](/attachments/bf3ed69c-20f7-4805-8c8d-60220b928d1d)
ntorres added 2 commits 2025-02-04 01:40:44 +00:00
f0fd447af7 Extract logic from get_max_pain()
All the max pain math now is in this two functions:

- get_total_intrinsic_values(): calculate the total value for all strike_prices and stores then in a dict[str, Decimal]

- `get_intrinsic_value_and_max_pain()` given the `intrinsic_values` dict, returns the `max_pain` strike price and the `total_intrinsic_value` for that `strike_price`
d2b6e9c00e Add Plot
Here is the `plot_graph()` that is in char of the bars and scatter plot items.

Also all the necessary code  for the graph to be shown.
ntorres force-pushed max_pain_chart from d2b6e9c00e to 54e5f4bb4e 2025-02-04 03:30:35 +00:00 Compare
ntorres force-pushed max_pain_chart from 54e5f4bb4e to 833a4f1d1c 2025-02-04 20:31:15 +00:00 Compare
ntorres force-pushed max_pain_chart from 833a4f1d1c to dc2e41e550 2025-02-04 20:53:13 +00:00 Compare
ntorres force-pushed max_pain_chart from dc2e41e550 to 988f9c9455 2025-02-05 16:50:17 +00:00 Compare
ntorres force-pushed max_pain_chart from 988f9c9455 to 490aaa3874 2025-02-18 00:11:39 +00:00 Compare
ntorres force-pushed max_pain_chart from 490aaa3874 to b9321dbb49 2025-02-24 21:27:02 +00:00 Compare

@ntorres REALLY good work here for a first prototype!

i have a few things to report and a terminal UX thing i’d like to add as well as obviously the regular code-style and convention stuff we always run everyone through ;)

  • if you pass the expiry to the input() prompt with ' quotes it’ll crash like so,

Available expiration dates for btc-option:
['25APR25', '26APR25', '27APR25', '2MAY25', '9MAY25', '16MAY25', '30MAY25', '27JUN25', '25JUL25', '26SEP25', '26DEC25', '27MAR26']
Please enter a valid expiration date: '2MAY25'

  File "/home/goodboy/repos/piker/.py312/lib/python3.12/site-packages/tractor/_rpc.py", line 272, in _errors_relayed_via_ipc
    yield  # run RPC invoke body
    ^^^^^
  File "/home/goodboy/repos/piker/.py312/lib/python3.12/site-packages/tractor/_rpc.py", line 554, in _invoke
    await _invoke_non_context(
  File "/home/goodboy/repos/piker/.py312/lib/python3.12/site-packages/tractor/_rpc.py", line 216, in _invoke_non_context
    result = await coro
             ^^^^^^^^^^
  File "/home/goodboy/repos/piker/examples/max_pain.py", line 237, in max_pain_daemon
    maybe_open_oi_feed(
  File "/home/goodboy/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/goodboy/repos/piker/piker/brokers/deribit/api.py", line 940, in maybe_open_oi_feed
    key=f'{instruments[0].base}',
           ~~~~~~~~~~~^^^
IndexError: list index out of range
  • instead for expiry selection we should use a terminal selection UX like fzf or something similar offered as a python pkg

  • possibly integrate our existing piker search <fqme> machinery to be able to fuzzy search both the symbol and expiry from either a running daemon or already existing symbology-caches?

@ntorres REALLY good work here for a first prototype! i have a few things to report and a terminal UX thing i'd like to add as well as obviously the regular code-style and convention stuff we always run everyone through ;) - [ ] if you pass the expiry to the `input()` prompt with `'` quotes it'll crash like so, ```python Available expiration dates for btc-option: ['25APR25', '26APR25', '27APR25', '2MAY25', '9MAY25', '16MAY25', '30MAY25', '27JUN25', '25JUL25', '26SEP25', '26DEC25', '27MAR26'] Please enter a valid expiration date: '2MAY25' File "/home/goodboy/repos/piker/.py312/lib/python3.12/site-packages/tractor/_rpc.py", line 272, in _errors_relayed_via_ipc yield # run RPC invoke body ^^^^^ File "/home/goodboy/repos/piker/.py312/lib/python3.12/site-packages/tractor/_rpc.py", line 554, in _invoke await _invoke_non_context( File "/home/goodboy/repos/piker/.py312/lib/python3.12/site-packages/tractor/_rpc.py", line 216, in _invoke_non_context result = await coro ^^^^^^^^^^ File "/home/goodboy/repos/piker/examples/max_pain.py", line 237, in max_pain_daemon maybe_open_oi_feed( File "/home/goodboy/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/lib/python3.12/contextlib.py", line 210, in __aenter__ return await anext(self.gen) ^^^^^^^^^^^^^^^^^^^^^ File "/home/goodboy/repos/piker/piker/brokers/deribit/api.py", line 940, in maybe_open_oi_feed key=f'{instruments[0].base}', ~~~~~~~~~~~^^^ IndexError: list index out of range ``` - [ ] instead for expiry selection we should use a terminal selection UX like [fzf](https://github.com/junegunn/fzf) or something similar offered as a python pkg - [ ] possibly integrate our existing `piker search <fqme>` machinery to be able to fuzzy search both the symbol and expiry from either a running daemon or already existing symbology-caches?
This pull request can be merged automatically.
You are not authorized to merge this pull request.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b max_pain_chart max_pain_deribit
git pull origin max_pain_chart

Step 2:

Merge the changes and update on Gitea.
git checkout max_pain_deribit
git merge --no-ff max_pain_chart
git push origin max_pain_deribit
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: pikers/piker#23
There is no content yet.