<jupyter_start><jupyter_text>Query TSLA Data from Yahoo Finance<jupyter_code>import random
import numpy as np
import pandas as pd
import seaborn as sns
import yfinance as yf
import matplotlib.pyplot as plt
from datetime import timedelta, datetime

#https://mrjbq7.github.io/ta-lib/func.html
from talib import RSI, BBANDS, MACD, MOM, EMA, MA, T3, WMA, BETA, LINEARREG, STDDEV<jupyter_output><empty_output><jupyter_text>Here we will request daily data for TSLA and SPY tickers from yahoo finance.<jupyter_code>random.seed(123)

# TSLA
tsla = yf.Ticker('TSLA')
tsla_df = tsla.history(period='2y', interval='1d')

# SPY
spy = yf.Ticker('SPY')
spy_df = spy.history(period='2y', interval='1d')<jupyter_output><empty_output><jupyter_text>Using the TA-Lib library, we can compute technical indicators to use as features in our forecasting model.<jupyter_code>"""TECHNICAL ANALYSIS"""

# MACD
macd, macdsignal, macdhist = MACD(tsla_df['Close'], fastperiod=12, slowperiod=26, signalperiod=9)

# Momentum
momentum = MOM(tsla_df['Close'], timeperiod=10)

# RSI
rsi = RSI(tsla_df['Close'], timeperiod=14)

# Bollinger Bands
upperband, middleband, lowerband = BBANDS(tsla_df['Close'], timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)

# EMA (Exponential Moving Average)
ema = EMA(tsla_df['Close'], timeperiod=30)

# MA 10 day (Moving Average)
ma10 = MA(tsla_df['Close'], timeperiod=10, matype=0)

# MA 21 day (Moving Average)
ma21 = MA(tsla_df['Close'], timeperiod=21, matype=0)

# MA 50 day (Moving Average)
ma50 = MA(tsla_df['Close'], timeperiod=50, matype=0)

# T3 (Triple Exponential Moving Average)
t3 = T3(tsla_df['Close'], timeperiod=5, vfactor=0)

# WMA (Weighted Moving Average)
wma = WMA(tsla_df['Close'], timeperiod=30)

# Beta
beta = BETA(tsla_df['High'], tsla_df['Low'], timeperiod=5)

# Linear Reg
lm = LINEARREG(tsla_df['Close'], timeperiod=14)

# Standard Deviation
sd = STDDEV(tsla_df['Close'], timeperiod=5, nbdev=1)
# Add TA indicators to TSLA
indicators = [macd, macdsignal, macdhist, momentum, rsi, ema, ma10, ma21, ma50, sd]
names = ['MACD','MACD_SIGNAL','MACD_HIST','MOMENTUM','RSI','EMA','MA10','MA21','MA50','STD_DEV']

for i, name in zip(indicators, names):
    tsla_df = pd.concat((tsla_df, i), axis=1)
    tsla_df = tsla_df.rename(columns={0:name})
# Organize df
tsla_df = tsla_df.rename(columns={'Close':'TSLA'})
tsla_df = tsla_df[['TSLA', 'Volume', 'Dividends', 'Stock Splits',
       'MACD', 'MACD_SIGNAL', 'MACD_HIST', 'MOMENTUM', 'RSI', 'EMA','MA10','MA21','MA50','STD_DEV']]

# Add SPY
tsla_df = tsla_df.merge(spy_df['Close'], how='left', left_index=True, right_index=True).rename(columns={'Close':'SPY'})
# Output data
tsla_df.to_csv('TSLA_raw.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15906562847608455, 'fraction_numerical': 0.028550241008527995, 'mean_word_length': 7.005934718100891, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '486947', 'license': 'MIT', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1083, 'n_words': 237, 'path': 'query_tsla_data.ipynb', 'repo_name': 'jrbarclay37/TSLA-Forecasting', 'size': '2697'}