<jupyter_start><jupyter_text>Predicting stock prices with Autogluon project  Data exploration<jupyter_code>import pandas as pd
from io import StringIO<jupyter_output><empty_output><jupyter_text>Parameter definition Let's use Apple (AAPL) as an example, with a lookback period of 3 years<jupyter_code># Parameters
ticker = 'AAPL'
lookback_months = 36<jupyter_output><empty_output><jupyter_text>Data Gathering We'll get the data from `query1.finance.yahoo.com` providing above params, via a regular http request  Sample data url: https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1550793600&period2=1645488000&interval=1d&events=history&includeAdjustedClose=true<jupyter_code>import time
import datetime
from dateutil.relativedelta import relativedelta
import pandas as pd
import os
import boto3


def get_data_df(ticker, period1, period2, suffix=''):
    int_period1 = int(time.mktime(period1.timetuple()))
    int_period2 = int(time.mktime(period2.timetuple()))
    interval = '1d' # 1d, 1m    
    url = f'https://query1.finance.yahoo.com/v7/finance/download/{ticker}?period1={int_period1}&period2={int_period2}&interval={interval}&events=history&includeAdjustedClose=true'
    print(url)
    df = pd.read_csv(url)
    df = df.rename(columns={'Adj Close': 'Adj_Close'})
    return df

period2 = datetime.date.today()
period1 = period2 - relativedelta(months=lookback_months)

df = get_data_df(ticker, period1, period2)
df<jupyter_output>https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1550793600&period2=1645488000&interval=1d&events=history&includeAdjustedClose=true<jupyter_text>Exploration<jupyter_code>df.head()<jupyter_output><empty_output><jupyter_text>Let's plot the evolution of the Adjusted Close price through time<jupyter_code>df.plot(x='Date', y='Adj_Close', figsize=(10,5))<jupyter_output><empty_output><jupyter_text>For this stock, we can observe an ascending behavior in general. Prices between 40 and 140 aprox Let's check the data distribution<jupyter_code>df.describe()
df.hist(figsize=(15,10))<jupyter_output><empty_output><jupyter_text>We can observe that all numeric fields have a similar distribution, bimodal in this example.This could be very dependent on the stockExcept for the volume, which follows a log normal distribution Let's check the Gold (GLD) stock distribution for the same period<jupyter_code>df_gld = get_data_df('GLD', period1, period2)
df_gld.describe()
df_gld.plot(x='Date', y='Adj_Close', figsize=(10,5))<jupyter_output><empty_output><jupyter_text>Gold also has an ascending behavior in general<jupyter_code>df_gld.hist(figsize=(15,10))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10892586989409984, 'fraction_numerical': 0.036308623298033284, 'mean_word_length': 7.905723905723906, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '215682', 'license': 'MIT', 'n_tokens_mistral': 975, 'n_tokens_neox': 910, 'n_words': 192, 'path': 'machine-learning-engineering/prj-capstone-stocks/data_exploration.ipynb', 'repo_name': 'edgarinvillegas/my-ml-playground', 'size': '2644'}