Home Forums General Questions How to find strike gap for a stock/index dynamically in options trading ?

How to find strike gap for a stock/index dynamically in options trading ?

  • Author
    Posts
    • So while working on dynamic strike selection (ATM/ITM/OTM) in my sma cross over algo, but I am stuck on strike gap.

      Right now I am hardcoding values like 50 for NIFTY and 100 for BANKNIFTY, but I want to make it dynamic for any stock.

      Is there a way to calculate strike gap from data instead of hardcoding it?

    • Yes, so there’s no direct API that gives you “strike gap”.

      The one way to do that calculate it from available strikes from the any source like script master file.

      So, the simple idea is Strike gap = difference between consecutive strikes

      Can understand with simple steps:

      Fetch option chain / instruments
      Take available strikes
      Sort them
      Find difference
      Can also refer below code:

      def get_strike_gap(strikes):
          strikes = sorted(set(strikes))
          if len(strikes) < 2:
              return None
          gaps = [strikes[i+1] - strikes[i] for i in range(len(strikes)-1)]
          # Most common gap
          gap = min(gaps)
          return gap
      
      # Sample - Inplace of this have the stricks from instrument/option chain
      strikes = [19800, 19850, 19900, 19950, 20000]
      
      gap = get_strike_gap(strikes)
      print("Strike Gap:", gap)
      • Author↳ Replying to @Algodelta Support

        Appreciate your response this clears all my confusion and with code it’s easy to resolve the problem.

        Thanks a lot.

Viewing 1 reply thread
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top