Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaz001 committed Feb 14, 2024
1 parent f952495 commit 3269334
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# -- Project information -----------------------------------------------------

project = 'hftbacktest'
copyright = '2023, nkaz001'
copyright = '2024, nkaz001'
author = 'nkaz001'

# The full version, including alpha/beta/rc tags
Expand Down
36 changes: 36 additions & 0 deletions docs/debugging_backtesting_and_live_discrepancies.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Debugging Backtesting and Live Discrepancies
============================================

Plotting both live and backtesting values on a single chart is a good initial step. It's strongly recommended to include
the equity curve and position plots for comparison purposes. Additionally, visualizing your alpha, order prices, etc can
facilitate the identification of discrepancies.

[Image]

If the backtested strategy is correctly implemented in live trading, two significant factors may contribute to any
observed discrepancies.

1. Latency:
Latency, encompassing both feed and order latency, plays a crucial role in ensuring accurate backtesting results. It's
highly recommended to collect data yourself to accurately measure feed latency on your end. Alternatively, if obtaining
data from external sources, it's essential to verify that the feed latency aligns with your latency.

Order latency, measured from your end, can be collected by logging order actions or regularly submitting orders away
from the mid-price and subsequently canceling them to measure and record order latency.

It's still possible to artificially decrease latencies to assess improvements in strategy performance due to enhanced
latency. This allows you to evaluate the effectiveness of higher-tier programs or liquidity provider programs, as well
as quantify the impact of investments made in infrastructure improvement. Understanding whether a superior
infrastructure provides a competitive advantage is beneficial.

2. Queue Model:
Selecting an appropriate queue model that accurately reflects live trading results is essential. You can either develop
your own queue model or utilize existing ones. Hftbacktest offers three primary queue models such as PowerProbQueueModel
series, allowing for adjustments to align with your results. For further information, refer to
`ProbQueueModel <https://hftbacktest.readthedocs.io/en/latest/order_fill.html#probqueuemodel>`_.

One crucial point to bear in mind is the backtesting conducted under the assumption of no market impact. A market order,
or a limit order that take liquidity, can introduce discrepancies, as it may cause market impact and consequently make
execution simulation difficult. Moreover, if your limit order size is too large, partial fills and their market impact
can also lead to discrepancies. It's advisable to begin trading with a small size and align the results first. Gradually
increasing your trading size while observing both live and backtesting results is recommended.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ You can find more examples in `examples <https://github.com/nkaz001/hftbacktest/
Latency Models <latency_models>
Order Fill <order_fill>
JIT Compilation Overhead <jit_compilation_overhead>
Debugging Backtesting and Live Discrepancies <debugging_backtesting_and_live_discrepancies>

.. toctree::
:maxdepth: 2
Expand Down
18 changes: 18 additions & 0 deletions docs/order_fill.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ LogProbQueueModel2
asset_type=Linear
)
PowerProbQueueModel2
~~~~~~~~~~~~~~~~~~~~

.. code-block:: python
from hftbacktest import PowerProbQueueModel2
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=PowerProbQueueModel2(3)
asset_type=Linear
)
ProbQueueModel3
---------------
This model is a variation of the `ProbQueueModel`_ that changes the probability calculation to
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/queue_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Queue Models
:members:
:show-inheritance:

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

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

0 comments on commit 3269334

Please sign in to comment.