bugfixing

This commit is contained in:
MuslemRahimi 2025-02-06 10:12:49 +01:00
parent a2e22d2d6f
commit ec9f32b42f
4 changed files with 15 additions and 9 deletions

View File

@ -141,20 +141,16 @@ def compute_realized_volatility(data, window_size=20):
# Sort the final list by date in descending order # Sort the final list by date in descending order
rv_list = sorted(rv_list, key=lambda x: x['date'], reverse=True) rv_list = sorted(rv_list, key=lambda x: x['date'], reverse=True)
return rv_list return rv_list
if __name__ == '__main__': if __name__ == '__main__':
directory_path = "json/implied-volatility" directory_path = "json/implied-volatility"
total_symbols = get_tickers_from_directory(directory_path) total_symbols = stocks_symbols + etf_symbols
if len(total_symbols) < 100:
total_symbols = stocks_symbols + etf_symbols # Assuming these are defined elsewhere
for symbol in tqdm(total_symbols): for symbol in tqdm(total_symbols):
try: try:
with open(f"json/options-historical-data/companies/{symbol}.json", "r") as file: with open(f"json/options-historical-data/companies/{symbol}.json", "r") as file:
data = orjson.loads(file.read()) data = orjson.loads(file.read())
rv_list = compute_realized_volatility(data) rv_list = compute_realized_volatility(data)
if rv_list: if rv_list:

View File

@ -70,8 +70,8 @@ def aggregate_data_by_date(symbol):
for entry in data.get('history', []): for entry in data.get('history', []):
date = entry.get('date') date = entry.get('date')
# Skip entries older than one year # Skip entries older than one year
if date < one_year_ago_str: #if date < one_year_ago_str:
continue # continue
volume = entry.get('volume', 0) or 0 volume = entry.get('volume', 0) or 0
open_interest = entry.get('open_interest', 0) or 0 open_interest = entry.get('open_interest', 0) or 0

View File

@ -57,6 +57,8 @@ def save_json(data, symbol, directory="json/hottest-contracts/companies"):
with open(f"{directory}/{symbol}.json", 'wb') as file: with open(f"{directory}/{symbol}.json", 'wb') as file:
file.write(orjson.dumps(data)) file.write(orjson.dumps(data))
def parse_option_symbol(option_symbol): def parse_option_symbol(option_symbol):
match = re.match(r"([A-Z]+)(\d{6})([CP])(\d+)", option_symbol) match = re.match(r"([A-Z]+)(\d{6})([CP])(\d+)", option_symbol)
if not match: 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) file_path = os.path.join(symbol_dir, contract_file)
with open(file_path, 'rb') as f: with open(file_path, 'rb') as f:
data = orjson.loads(f.read()) 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: if 'history' not in data:
continue continue

View File

@ -48,7 +48,7 @@ class ChainItem:
intrinio.ApiClient().set_api_key(api_key) intrinio.ApiClient().set_api_key(api_key)
intrinio.ApiClient().allow_retries(True) 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' before = '2100-12-31'
N_year_ago = datetime.now() - timedelta(days=365) N_year_ago = datetime.now() - timedelta(days=365)
include_related_symbols = False include_related_symbols = False
@ -301,7 +301,7 @@ async def process_symbol(symbol):
expiration_list = get_contracts_from_directory(symbol) expiration_list = get_contracts_from_directory(symbol)
#check existing contracts and delete expired ones #check existing contracts and delete expired ones
check_contract_expiry(symbol) #check_contract_expiry(symbol)
print(f"Found {len(expiration_list)} expiration dates") print(f"Found {len(expiration_list)} expiration dates")
contract_list = await get_data(symbol, expiration_list) contract_list = await get_data(symbol, expiration_list)