Skip to content

Unintended complex numbers output #19

@OfferLifted

Description

@OfferLifted

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions