diff --git a/app/cron_implied_volatility.py b/app/cron_implied_volatility.py index 66608cb..04f207b 100644 --- a/app/cron_implied_volatility.py +++ b/app/cron_implied_volatility.py @@ -141,20 +141,16 @@ def compute_realized_volatility(data, window_size=20): # Sort the final list by date in descending order rv_list = sorted(rv_list, key=lambda x: x['date'], reverse=True) - return rv_list if __name__ == '__main__': directory_path = "json/implied-volatility" - total_symbols = get_tickers_from_directory(directory_path) - if len(total_symbols) < 100: - total_symbols = stocks_symbols + etf_symbols # Assuming these are defined elsewhere + total_symbols = stocks_symbols + etf_symbols for symbol in tqdm(total_symbols): try: with open(f"json/options-historical-data/companies/{symbol}.json", "r") as file: data = orjson.loads(file.read()) - rv_list = compute_realized_volatility(data) if rv_list: diff --git a/app/cron_options_historical_volume.py b/app/cron_options_historical_volume.py index d96d8f5..99288f1 100644 --- a/app/cron_options_historical_volume.py +++ b/app/cron_options_historical_volume.py @@ -70,8 +70,8 @@ def aggregate_data_by_date(symbol): for entry in data.get('history', []): date = entry.get('date') # Skip entries older than one year - if date < one_year_ago_str: - continue + #if date < one_year_ago_str: + # continue volume = entry.get('volume', 0) or 0 open_interest = entry.get('open_interest', 0) or 0 diff --git a/app/cron_options_hottest_contracts.py b/app/cron_options_hottest_contracts.py index dabc15e..4a992aa 100644 --- a/app/cron_options_hottest_contracts.py +++ b/app/cron_options_hottest_contracts.py @@ -57,6 +57,8 @@ def save_json(data, symbol, directory="json/hottest-contracts/companies"): with open(f"{directory}/{symbol}.json", 'wb') as file: file.write(orjson.dumps(data)) + + def parse_option_symbol(option_symbol): match = re.match(r"([A-Z]+)(\d{6})([CP])(\d+)", option_symbol) if not match: @@ -143,6 +145,14 @@ def get_hottest_contracts(base_dir="json/all-options-contracts"): file_path = os.path.join(symbol_dir, contract_file) with open(file_path, 'rb') as f: data = orjson.loads(f.read()) + + #only consider contracts that didn't expire yet + expiration_date, _, _ = parse_option_symbol(contract_file.replace(".json","")) + + # Check if the contract is expired + if expiration_date < today: + continue + if 'history' not in data: continue diff --git a/app/cron_options_single_contract.py b/app/cron_options_single_contract.py index 38a29d7..a793604 100644 --- a/app/cron_options_single_contract.py +++ b/app/cron_options_single_contract.py @@ -48,7 +48,7 @@ class ChainItem: intrinio.ApiClient().set_api_key(api_key) intrinio.ApiClient().allow_retries(True) -after = datetime.today().strftime('%Y-%m-%d') +after = (datetime.today()- timedelta(days=365)).strftime('%Y-%m-%d') before = '2100-12-31' N_year_ago = datetime.now() - timedelta(days=365) include_related_symbols = False @@ -301,7 +301,7 @@ async def process_symbol(symbol): expiration_list = get_contracts_from_directory(symbol) #check existing contracts and delete expired ones - check_contract_expiry(symbol) + #check_contract_expiry(symbol) print(f"Found {len(expiration_list)} expiration dates") contract_list = await get_data(symbol, expiration_list)