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

Asked by Sejpalsinh Jadeja · SOLVED
1 reply 1,444 views Jump to solution Reply
Sejpalsinh Jadeja Original Post
AlgoDelta Team

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?

Posted Apr 24
Reply

    1 Reply

    Support AlgoDelta
    Support AlgoDelta AlgoDelta Support ·

    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)
    Verified Solution
    • Thanks for the answer, this is exactly what I want to find and with code it’s very helpful. – Sejpalsinh Jadeja Team Jun 17
    Markdown supported · ```json for code blocks · paste or drop screenshots

    Be specific and kind. Never share API keys, passwords or personal account details.

    Welcome to the community

    Log in or create your account in under a minute.

    1. 1Mobile
    2. 2E-mail
    3. 3Password
    +91

    Have a password?

    By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.