text_plain_output_1.png
from kaggle_secrets import UserSecretsClient

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import requests

value_strategy = pd.read_csv('/kaggle/input/algorithmic-trading-dataset/value_strategy_1.csv.csv')
recommended_trades = pd.read_csv('/kaggle/input/algorithmic-trading-dataset/recommended_trades_1.csv.csv')
momentum_srategy = pd.read_csv('/kaggle/input/algorithmic-trading-dataset/momentum_strategy_1.csv.csv')
trades = pd.read_csv('/kaggle/input/sp-500-stocks/sp_500_stocks.csv')

import requests
from kaggle_secrets import UserSecretsClient
user_secrets = UserSecretsClient()
IEX_CLOUD_API_TOKEN = 'Tpk_ddf77a77f6e7464390bb2adc85a2be11'
secret_value_0 = user_secrets.get_secret('IEX_CLOUD_API_TOKEN')
symbol = 'AAPL'
api_url = f'https://sandbox.iexapis.com/stable/stock/{symbol}/quote?token={IEX_CLOUD_API_TOKEN}'
data = requests.get(api_url).json()
data

trades[trades['Ticker'] == 'VIAC']
trades.drop(index=trades[trades['Ticker'] == 'VIAC'].index, inplace=True)

my_columns = ['Ticker', 'Price', 'One-Year Price Return', 'Number of Shares to Buy']
trades_data = pd.DataFrame(columns=my_columns)
for symbol_string in trades['Ticker']:
    batch_api_call_url = f'https://sandbox.iexapis.com/v1/stock/market/batch/?types=stats,quote&symbols={symbol_string}&token={IEX_CLOUD_API_TOKEN}'
    data = requests.get(batch_api_call_url).json()
    for symbol in symbol_string.split(','):
        trades_data = trades_data.append(pd.Series([symbol, data[symbol]['quote']['latestPrice'], data[symbol]['stats']['year1ChangePercent'], 'N/A'], index=my_columns), ignore_index=True)
trades_data

hqm_columns = ['Ticker', 'Price', 'Market Capitalization', 'Number of Shares to Buy', 'One-Year Price Return', 'One-Year Return Percentile', 'Six-Month Price Return', 'Six-Month Return Percentile', 'Three-Month Price Return', 'Three-Month Return Percentile', 'One-Month Price Return', 'One-Month Return Percentile', 'HQM Score']
hqm_dataframe = pd.DataFrame(columns=hqm_columns)

for symbol_string in trades['Ticker']:
    batch_api_call_url = f'https://sandbox.iexapis.com/stable/stock/market/batch/?types=stats,quote&symbols={symbol_string}&token={IEX_CLOUD_API_TOKEN}'
    data = requests.get(batch_api_call_url).json()
    for symbol in symbol_string.split(','):
        hqm_dataframe = hqm_dataframe.append(pd.Series([symbol, data[symbol]['quote']['latestPrice'], data[symbol]['quote']['marketCap'], 'N/A', data[symbol]['stats']['year1ChangePercent'], 'N/A', data[symbol]['stats']['month6ChangePercent'], 'N/A', data[symbol]['stats']['month3ChangePercent'], 'N/A', data[symbol]['stats']['month1ChangePercent'], 'N/A', 'N/A'], index=hqm_columns), ignore_index=True)
hqm_dataframe.columns

hqm_dataframe.head()