将字典值转换成单独的变量?蟒蛇

时间:2020-06-17 22:09:29

标签: python dictionary finance computational-finance

所以我有这段代码来搜索波动性最高的期权。

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]))

然后打印出以下结果: 符号:'F',行使价:1.5000,卖出价:4.900000,出价:4.800000,Delta:0.990127,IV:9.900301

我的问题是,如何将该输出保存到单独的变量中? 注意,“ strike_price”,“ ask_price”,“ bid_price”,“ delta”和“ implied_volatility”的变量必须为整数,但“ symbol”必须为字符串。

这是我需要的结果:

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

0 个答案:

没有答案