Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaz001 committed Nov 14, 2023
1 parent 064e5f9 commit 599a4e0
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 2 deletions.
Binary file added docs/images/probqueuemodel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/probqueuemodel2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/probqueuemodel3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/probqueuemodel_log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ You can find more examples in `examples <https://github.com/nkaz001/hftbacktest/
tutorials/Impact of Order Latency
tutorials/GLFT Market Making Model and Grid Trading
tutorials/Making Multiple Markets
tutorials/Probability Queue Models
tutorials/examples

.. toctree::
Expand Down
48 changes: 46 additions & 2 deletions docs/order_fill.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,35 @@ The order queue position will be advanced only if a trade happens at the price.
ProbQueueModel
--------------
Based on a probability model according to your current queue position, the decrease in quantity happens at both the head
and tail of the queue.
Based on a probability model according to your current queue position, the decrease in quantity happens at both before
and after the queue position.
So your queue position is also advanced according to the probability.
This model is implemented as described in

* https://quant.stackexchange.com/questions/3782/how-do-we-estimate-position-of-our-order-in-order-book
* https://rigtorp.se/2013/06/08/estimating-order-queue-position.html

By default, three variations are provided. These three models have different probability profiles.

.. image:: images/probqueuemodel.png

The function f = log(1 + x) exhibits a different probability profile depending on the total quantity at the price level,
unlike power functions.

.. image:: images/probqueuemodel_log.png

.. image:: images/probqueuemodel2.png
.. image:: images/probqueuemodel3.png

When you set the function f, it should be as follows.

* The probability at 0 should be 0 because if the order is at the head of the queue, all decreases should happen after
the order.
* The probability at 1 should be 1 because if the order is at the tail of the queue, all decreases should happen before
the order.

You can see the comparison of the models :doc:`here <tutorials/Probability Queue Models>`.

LogProbQueueModel
~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -254,6 +275,29 @@ LogProbQueueModel2
asset_type=Linear
)
ProbQueueModel3
---------------
This model is a variation of the `ProbQueueModel`_ that changes the probability calculation to
1 - f(front / (front + back)) from f(back) / (f(front) + f(back)).

PowerProbQueueModel3
~~~~~~~~~~~~~~~~~~~~

.. code-block:: python
from hftbacktest import PowerProbQueueModel3
hbt = HftBacktest(
data,
tick_size=0.01,
lot_size=0.001,
maker_fee=-0.00005,
taker_fee=0.0007,
order_latency=IntpOrderLatency(latency_data),
queue_model=PowerProbQueueModel3(3)
asset_type=Linear
)
Implement a custom probability queue position model
---------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/data_utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ Data Utilities
:maxdepth: 4

hftbacktest.data.utils.binancefutures
hftbacktest.data.utils.binancehistmktdata
hftbacktest.data.utils.snapshot
hftbacktest.data.utils.tardis
hftbacktest.data.utils.difforderbooksnapshot
7 changes: 7 additions & 0 deletions docs/reference/hftbacktest.data.utils.binancehistmktdata.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
hftbacktest.data.utils.binancehistmktdata module
================================================

.. automodule:: hftbacktest.data.utils.binancehistmktdata
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
hftbacktest.data.utils.difforderbooksnapshot module
===================================================

.. automodule:: hftbacktest.data.utils.difforderbooksnapshot
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/reference/queue_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ Queue Models
:show-inheritance:

.. autoclass:: hftbacktest.models.queue.LogProbQueueModel2
:members:
:show-inheritance:

.. autoclass:: hftbacktest.models.queue.ProbQueueModel3
:members:
:show-inheritance:

.. autoclass:: hftbacktest.models.queue.PowerProbQueueModel3
:members:
:show-inheritance:
Loading

0 comments on commit 599a4e0

Please sign in to comment.