βœ–

Home Forums General Questions How to dynamically select ATM/ITM/OTM strike for any stock in my algo?

How to dynamically select ATM/ITM/OTM strike for any stock in my algo?

  • Author
    Posts
    • πŸ“ Question Details

      I am building an options trading algo and I am stuck on strike selection.

      Right now I am manually setting strikes, but I want to make it dynamic β€” like ATM, 1 step ITM, 1 step OTM based on live price.

      Also different stocks have different strike gaps, so getting confused how to handle that properly.

      How do you guys usually do this?

    • Ok, so don’t hardcode strikes β€” you calculate them using spot price and stick gap (step size).

      As each stock has different strike gaps
      ATM is just nearest rounded strike
      ITM/OTM = shift from ATM
      Simple approach in steps:

      Get latest spot price
      Round to nearest strike gap β†’ ATM
      Add/subtract gap β†’ ITM/OTM
      Can also refer the example code below:

      def get_strikes(spot, strike_gap):
          atm = round(spot / strike_gap) * strike_gap
      
          strikes = {
              "ATM": atm,
              "OTM_CE": atm + strike_gap,
              "ITM_CE": atm - strike_gap,
              "OTM_PE": atm - strike_gap,
              "ITM_PE": atm + strike_gap,
          }
      
          return strikes
      
      # Sample
      spot_price = 19876 # Since spot price from the socket
      strike_gap = 50  # NIFTY = 50, BANKNIFTY = 100
      
      strikes = get_strikes(spot_price, strike_gap)
      
      print(strikes)
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.

⏳

Pending Approval

⚠️

Delete This?

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

Scroll to Top