Compare commits
No commits in common. "8bc4b296a8a2f8dc54028f18e9af147edc3c2c8f" and "190a6f9a73585d290b4fcdf9ac3b4f1c3c09bf02" have entirely different histories.
8bc4b296a8
...
190a6f9a73
@ -1,19 +1,18 @@
|
||||
from datetime import datetime
|
||||
from dotenv import load_dotenv
|
||||
from ibkr import Client
|
||||
from ibkr.option_type import CALL, PUT
|
||||
from os import getenv
|
||||
from tastytrade import Tastytrade
|
||||
|
||||
load_dotenv()
|
||||
|
||||
ibkr_host = getenv('IBKR_HOST')
|
||||
ibkr_port = getenv('IBKR_PORT')
|
||||
ibkr_host = getenv("IBKR_HOST")
|
||||
ibkr_port = getenv("IBKR_PORT")
|
||||
ibkr_client = Client(host = ibkr_host, port = ibkr_port)
|
||||
|
||||
tastytrade_account = getenv('TASTYTRADE_ACCOUNT')
|
||||
tastytrade_username = getenv('TASTYTRADE_USERNAME')
|
||||
tastytrade_password = getenv('TASTYTRADE_PASSWORD')
|
||||
tastytrade_account = getenv("TASTYTRADE_ACCOUNT")
|
||||
tastytrade_username = getenv("TASTYTRADE_USERNAME")
|
||||
tastytrade_password = getenv("TASTYTRADE_PASSWORD")
|
||||
tastytrade_client = Tastytrade(tastytrade_username, tastytrade_password)
|
||||
tastytrade_client.login()
|
||||
|
||||
@ -30,32 +29,3 @@ def contract_filter(contract):
|
||||
# The weekly symbol for SPX (SPXW) is required in order to distinguish from monthly options.
|
||||
option_chain = ibkr_client.get_option_chain('SPX', datetime.now(), sub_symbol = 'SPXW', contract_filter = contract_filter)
|
||||
print(option_chain)
|
||||
|
||||
target_delta = 0.10
|
||||
|
||||
def closest_strike_by_delta(target_delta, option_chain, option_type):
|
||||
options = option_chain[option_chain['Type'] == option_type].copy()
|
||||
options['Delta Distance'] = abs(options['Delta'] - (target_delta * (1 if option_type == CALL else -1)))
|
||||
return options.loc[options['Delta Distance'].idxmin()]
|
||||
|
||||
# Find the strikes that minimize the distance to the target delta.
|
||||
closest_call_strike = closest_strike_by_delta(target_delta, option_chain, CALL)
|
||||
closest_put_strike = closest_strike_by_delta(target_delta, option_chain, PUT)
|
||||
|
||||
# Do the same for the long strikes.
|
||||
target_long_call_strike = closest_call_strike['Strike'] + 50
|
||||
target_long_put_strike = closest_put_strike['Strike'] - 50
|
||||
|
||||
def closest_strike_by_strike(target_strike, option_chain, option_type):
|
||||
options = option_chain[option_chain['Type'] == option_type].copy()
|
||||
options['Strike Distance'] = abs(options['Strike'] - target_strike)
|
||||
return options.loc[options['Strike Distance'].idxmin()]
|
||||
|
||||
closest_long_call_strike = closest_strike_by_strike(target_long_call_strike, option_chain, CALL)
|
||||
closest_long_put_strike = closest_strike_by_strike(target_long_put_strike, option_chain, PUT)
|
||||
|
||||
# The requested iron condor.
|
||||
print('Short Call Strike:', closest_call_strike['Strike'])
|
||||
print('Long Call Strike:', closest_long_call_strike['Strike'])
|
||||
print("Short Put Strike:", closest_put_strike['Strike'])
|
||||
print('Long Put Strike:', closest_long_put_strike['Strike'])
|
Loading…
Reference in New Issue
Block a user