Skip to content
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

Unintended complex numbers output #19

Open
OfferLifted opened this issue Jun 6, 2024 · 5 comments
Open

Unintended complex numbers output #19

OfferLifted opened this issue Jun 6, 2024 · 5 comments

Comments

@OfferLifted
Copy link

Just as a heads up in the v2 alpha branch in smm/quote_generators/plain.py.
You allow negative numbers as input.

    def generate_orders(self, skew: float, spread: float) -> List:
        if skew > 0.0:
            return self.generate_positive_skew_quotes(skew, spread)
        elif skew <= 0.0:
            return self.generate_negative_skew_quotes(skew, spread)

Negative skew values will be used in:

        half_spread = spread / 2
        aggressiveness = self.params["aggressiveness"] * (skew**0.5)

        best_bid_price = self.mid - (half_spread * (1.0 - aggressiveness))
        best_ask_price = best_bid_price   spread

This will cause unintended issues. Best shown by an example.

skew = -0.99
with_skew_var = 0.5 * (skew**0.5)

print("with skew var", with_skew_var)
print("with skew var",type(with_skew_var))


without_skew_var = 0.5 * (-0.99**0.5)
print("\n")
print("without skew var", without_skew_var)
print("without skew var",type(without_skew_var))

Output:

with skew var (3.0462704501111267e-17 0.49749371855331j)
with skew var <class 'complex'>


without skew var -0.49749371855331
without skew var <class 'float'>

Afaik interprets python the one with the skew variable used as: (-0.99)**0.5.
While interpreting the one without the var used as: -(0.99**0.5).
Raising a negative number to a fractional exponent results in a complex number rather than the expected float.

Have you not yet encountered this? I haven't looked at the skew calcs in depth yet and I know it's still a WIP maybe the current skew calcs will never output negative skew or the skew value is coming from somewhere else idk.

@OfferLifted
Copy link
Author

Something else to note.

        clipped_r = 0.5   nbclip(skew, 0.0, 0.5)  # NOTE: Geometric ratio cant exceed 1.0

        bid_sizes = self.max_position * generate_geometric_weights(
            num=self.total_orders // 2, r=clipped_r, reverse=True
        )

        ask_sizes = self.max_position * generate_geometric_weights(
            num=self.total_orders // 2,
            r=0.5   (clipped_r ** (2   aggressiveness)),
            reverse=True,
        )

This clipped ratio value will be 1 if skew >= 0.5. Which is fine for bid_sizes however in ask_sizes you add 0.5 clipped_r squared by some value. If clipped ratio == 1 which it will be for skew >= 0.5. The geometric ratio in ask_sizes will be 1.5 so exceeding 1.0. This might cause issues down the line.

@beatzxbt
Copy link
Owner

beatzxbt commented Jun 6, 2024

oop, im surprised i didnt encounter these in my few hours of running it...

will make fixes for this, many thanks for point it out!

@OfferLifted
Copy link
Author

No worries. I had a brief look at your feature calcs. Not sure if you're running the same ones live but there are some that cannot return negative values. Like the weighted mids and stuff can only return negative values if there are negative prices. So that might be why you didn't encounter the negative skew one as perhaps the skew never got negative because half of the features only output postive values?

Anyways I'll have a deeper look at everything later.

@beatzxbt
Copy link
Owner

beatzxbt commented Jun 6, 2024

yeah there is missing stuff to in the feature calcs, the mids are supposed to be np.log(wmid/mid), not just plain wmid/mid...

all still WIP of course but clearly theres a lot more missing stuff than expected (found some more unintended behaviour in the quote gen, will push soon).

thanks again!

@beatzxbt
Copy link
Owner

beatzxbt commented Jun 6, 2024

addressed the issue here (and more missing stuffs): 80900f2

hope this fixes it, will close this issue once i get time to run it live and monitor quoting logic w/feat values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants