Passing a list of option strikes to helper function

darkrai
Hello , i want to calculate option greeks in realtime using tick data . I'm stuck on the helper function where i need to pass both the option values from tick data as well as their strike price to calculate the greek .

Can u point out where all i will need to make changes in code to add this list of strike prices so that i can iterate over ticks and the list simultaneously in a for loop to calculate .
  • SRIJAN
    SRIJAN edited January 4
    Make a dictionary with keys as the strikes' call and put. The value of each key should be a dictionary with all the required data,like price etc. Means,we are creating a dictionary of dictionaries.To start,just put the values as empty strings or None. Fetch data from websocket for each instrument,and fill the values in the dictionary. Now you have a dictionary with all the strikes' call and put and their respective values. Now just iterate over the whole dictionary like:
    for key,value in dict.items():
    pass
  • darkrai
    after i run the tick streaming on the list of option instruments and print it , the sequence of instruments changes everytime . is this normal ?
  • SRIJAN
    SRIJAN edited January 5
    Yes. Filter the data of specific instrument by specifying the instrument token. Like, 17850CE instrument token is 10135554. So,

    for tick in ticks:
    if tick['instruement_token']==10135554:
    _17000_CE_ltp=tick['last_price']
  • darkrai
    Thanx a ton , the dictionary solution was beautiful . The function is giving proper output , only thing havnt tested during market hours . Even though ive specified the threaded=true argument i'm worried the connection might close in realtime as the Greek calculator function requires a few seconds .
  • darkrai
    while True:
    def on_ticks(ws, ticks):
    print("i am from while True -> on ticks: feed_data module called!")
    plt.style.use('fivethirtyeight')
    index = count()
    def animate(i):
    x.append(next(index))
    y1.append(ATMdelta(ticks,strikes_list))
    plt.cla()
    plt.plot(x, y1, label='Channel 1')
    plt.legend(loc='upper left')
    plt.tight_layout()
    ani = FuncAnimation(plt.gcf(), animate, interval=1000)
    plt.tight_layout()
    plt.show()

    def ATMdelta(ticks,strikes_list):
    Calculates the greek
    -----------------------------------------------------------------------------
    i also want to display the live graph of delta .... should the plotting function also be inside helper function or should it be within on_ticks
  • SRIJAN
    SRIJAN edited January 8
    Nothing should be inside on_ticks except receiving ticks or the helper function. On_ticks is just to receive ticks. All the required calculation should be done in helper thread. I wish your system works properly during market hours. o:)
  • darkrai
    connection closed . not working for 2nd tick onwards .ill have to run the helper function (which processes the popped tick from the queue )on another thread . . i saw this solution on a multithreading discussion thread ... can u show me how the while true: loop will look like ? for eg. should i create the new_thread for helper func outside the on_tick function within the while loop ? plz help im noob
  • darkrai
    ps : thread target =helper function ...... ignore the tick_function ...
Sign In or Register to comment.