Convert dictionary values into separate variables? Python

101 views Asked by At

So I have this code which searches for an option with the highest volatility.

import config 
import robin_stocks as r 

r.login(config.USERNAME,config.PASSWORD)


#specify criteria to search for options of a given symbol and its exp date
symbol = 'F'
expirationDate = '2020-06-19'


search_option = r.find_options_for_stock_by_expiration(symbol,expirationDate,optionType='call')

#identify option with highest implied volatility

highest_IV, highest_idx = 0, None
for idx, option in enumerate(search_option):
    if option['implied_volatility'] and highest_IV < float(option['implied_volatility']):
        highest_IV = float(option['implied_volatility'])
        highest_idx = idx
if highest_idx is not None:
    print("Symbol: {chain_symbol}, Strike Price: {strike_price}, Ask: {ask_price}, Bid: {bid_price}, Delta: {delta}, IV: {implied_volatility}".format(**search_option[highest_idx]))

It then prints out the following result: Symbol: 'F', Strike Price: 1.5000, Ask: 4.900000, Bid: 4.800000, Delta: 0.990127, IV: 9.900301

My question is, how can I save this output into separate variables? Note, the variables for 'strike_price', 'ask_price', 'bid_price', 'delta' and 'implied_volatility' have to be integers, but 'symbol', has to be a string.

This is the result that I need:

symbol_for_order = F
strike_price_for_order = 1.5000
ask_price_for_order = 4.900000
....
0

There are 0 answers