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

NormalizePriceToBrokerage Improvements #103

Open
4 tasks done
AlexCatarino opened this issue Apr 3, 2024 · 1 comment
Open
4 tasks done

NormalizePriceToBrokerage Improvements #103

AlexCatarino opened this issue Apr 3, 2024 · 1 comment
Labels
bug Something isn't working enhancement New feature or request

Comments

@AlexCatarino
Copy link
Member

Expected Behavior

Receive a message when the NormalizePriceToBrokerage method changes the price.

Actual Behavior

We are not notified about the change.

Potential Solution

Implement the same logic from Lean.

Reproducing the Problem

User algorithm placed the following trades:

Buy Leg: SPXW 240401P05150000, Strike: 5150.0, Bid: 0.0, Ask: 0.05, Last Price: 0.05
Sell Leg: SPXW 240401P05200000, Strike: 5200.0, Bid: 0.1, Ask: 0.2, Last Price: 0.1
Quantity: 1
Limit Price: -0.12
Time: 20240401 14:11:00.672 UTC

Reproduceable by the following algorithm:

class CrawlingFluorescentYellowGorilla(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2024,3,28)
        self.SetCash(100000)

        index = self.AddIndex("SPX").Symbol
        self.legs = [
            Leg.Create(Symbol.CreateOption(index, "SPXW", Market.USA, OptionStyle.European, OptionRight.Put, 5150, datetime(2024,4,1)), 1),
            Leg.Create(Symbol.CreateOption(index, "SPXW", Market.USA, OptionStyle.European, OptionRight.Put, 5200, datetime(2024,4,1)), -1)
        ]
        [self.AddIndexOptionContract(leg.Symbol) for leg in self.legs]

        def callback():
            self.tickets = self.ComboLimitOrder(self.legs, 1, -0.12)

        self.Schedule.On(self.DateRules.On(2024,4,1), self.TimeRules.At(14,11, TimeZones.Utc), callback)

However, the order arrived with limit price of -0.1, so there was a rounding from -0.12 to -0.1.
The rounding was not made by LEAN as we observe when we run a backtest with this code, so the NormalizePriceToBrokerage method rounded it down.

This method uses the GetMinTick method to look for the minimum price variation in the Contract. This information comes from Interactive Brokers. We should log both when NormalizePriceToBrokerage, and GetMinTick value.

If the minimum value is 0.05 for SPXW under $3, their API has a bug.

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
@AlexCatarino AlexCatarino added bug Something isn't working enhancement New feature or request labels Apr 3, 2024
@AlexCatarino
Copy link
Member Author

For combo orders, we could assume the minimum tick is 0.01.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant