Skip to content

Commit

Permalink
fix: add current fear greed index timestamp check
Browse files Browse the repository at this point in the history
  • Loading branch information
daneisburgh committed Mar 4, 2024
1 parent f984ca8 commit 746efe5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions invaas/schwab/schwab_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def create_options_orders(self):
owned_options, owned_call_options, owned_put_options = self.__get_owned_options()

(
current_fear_greed_index_timestamp,
current_fear_greed_index,
previous_max_fear_greed_index,
previous_min_fear_greed_index,
Expand Down Expand Up @@ -174,7 +175,11 @@ def get_sell_dte(owned_option, current_dte, expire_date):
self.logger.info(f"Max strike distiance: {int(max_strike_distance_pct*100)}%")
print()

if owned_options_bought_today < max_buy_amount:
if current_fear_greed_index_timestamp < (datetime.now(timezone.utc) - timedelta(minutes=15)):
self.logger.info("Fear and greed index not updated recently")
elif owned_options_bought_today >= max_buy_amount:
self.logger.info("Reached max allowed owned options bought today")
else:
for index, row in df_options_chain.iterrows():
call_ask_price = row.C_ASK * 100
put_ask_price = row.P_ASK * 100
Expand Down Expand Up @@ -270,7 +275,14 @@ def __get_fear_greed_index_data(self, historical_periods: int):
df["fear_greed_index"].rolling(window=historical_periods, min_periods=historical_periods).min()
)

current_fear_greed_index_timestamp = df.index[-1]
current_fear_greed_index = round(df.fear_greed_index.values[-1])

self.logger.info(
f"Current fear greed index timestamp: {current_fear_greed_index_timestamp.strftime('%Y-%m-%d %H:%M:%S')}"
)
self.logger.info(f"Current fear greed index: {current_fear_greed_index}")

previous_max_fear_greed_index = round(df.previous_max_fear_greed_index.values[-1])
previous_min_fear_greed_index = round(df.previous_min_fear_greed_index.values[-1])

Expand All @@ -286,11 +298,15 @@ def __get_fear_greed_index_data(self, historical_periods: int):
if previous_run_min_fear_greed_index < previous_min_fear_greed_index:
previous_min_fear_greed_index = previous_run_min_fear_greed_index

self.logger.info(f"Current fear greed index: {current_fear_greed_index}")
self.logger.info(f"Previous max fear greed index: {previous_max_fear_greed_index}")
self.logger.info(f"Previous min fear greed index: {previous_min_fear_greed_index}")

return (current_fear_greed_index, previous_max_fear_greed_index, previous_min_fear_greed_index)
return (
current_fear_greed_index_timestamp,
current_fear_greed_index,
previous_max_fear_greed_index,
previous_min_fear_greed_index,
)

def __get_cboe_vix_data(self):
vix_ticker = "^VIX"
Expand Down

0 comments on commit 746efe5

Please sign in to comment.