simulation piq issues/questions
marquestrading opened this issue · 2 comments
(Great framework, thanks for making it open source)
Two issues regarding simulation:
Issue 1
If there are two unmatched bets at the same price, the piq of the second bet is not updated until the first bet is matched so the piq of the second bet is incorrect. Suppose we are processing the simulation for bet 1:
In simulatedorder.py
_calculate_process_traded() updates the _piq and returns traded_size even when the bet is not matched.
_process_traded() treats this as matched amount and deducts this from traded[traded_price]
When we then process bet 2, traded[traded_price] is 0, so the piq is not updated (but piq should change as amount has traded at this price)
Can _calculate_process_traded() return 0.0 instead for unmatched bets? Sorry have only recently started looking at flumine so Im not entirely sure about the downstream impact this change might have.
Issue 2
When config.simulation_available_prices = True, suppose a bet a comes in and matches your bet, simulation sets the matched price incorrectly. Suppose:
there are no bets at 1.01 and 1.02
you have a simulation back bet at 1.01 for 100GBP
somebody lays at 1.02 for 200 GBP, simulation sets the matched price to 1.02 instead of 1.01
I think it might be because in _process_available() we are passing in update["price"], instead of the order price?
if update["price"] >= price:
self._calculate_process_available(
publish_time, update["price"], update["size"]
)
Apologies if I have missed something. I see there is issue#538 for smart matching but I dont see these issues in there. Please let me know if you need more information
You are correct regarding Issue 2 and is an easy fix, Issue 1 isn't that simple due to the way the logic is currently coded.
I don't want to complicate things here mainly due to the fact it is in the simulation hot path, maybe after a coffee I will come up with something simple.
FYI join the slack as I am sometimes slow to respond to GitHub issues.
Great thank you. Yep, will post on the slack going forward