0
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'

So the code searches for an option with the highest implied volatility.

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("Strike Price: {strike_price}, Ask: {ask_price}, Bid: {bid_price}, Delta: {delta}, IV: {implied_volatility}, Order ID: {id}".format(**search_option[highest_idx]))

It then gives me this output:

Strike Price: 1.5000, Ask: 4.900000, Bid: 4.800000, Delta: 0.990127, IV: 9.900301, Order ID: 08bd63f8-2716-4d0a-af09-b2980b933a20

My only problem is, how can I save this output into separate variables? So it should look something like:

order_strike = 1.5000
order_ask = 4.900000
order_bid = 4.800000
.....

Note: strike, ask, bid, delta and implied volatility have to be integers but order ID has to be a string.

I tried tackling the problem by adding the following code:

    order_strike = option.get('strike_price')
    order_ask = option.get('ask_price')
    order_bid = option.get('bid_price')
    order_delta = option.get('delta')
    order_IV = option.get('implied_volatility')
    order_id = option.get('id')


    print('Strike: ', order_strike)
    print('Ask Price: ', order_ask)
    ....
    ....

But I got this output instead (which clearly does not match the output found in search_option, i.e, Strike: 1.500 etc.):

Strike:  17.0000
Ask Price:  0.010000
Bid Price: 0.000000
Delta: 0.012675
IV:  5.472782
ID: dbcccdb0-cbaa-49f7-b57d-df171bf1e9cf

Any ideas?

Kam Halil
  • 35
  • 7
  • `option` is the wrong option. – user2357112 Jun 18 '20 at 09:36
  • I tried subsituting option with search_option in the get() code and it gave me this: order_strike = search_option.get('strike_price') AttributeError: 'list' object has no attribute 'get' – Kam Halil Jun 18 '20 at 09:38

0 Answers0