<jupyter_start><jupyter_text>***VIX CBOE Volatility Index aka The Fear Gauge***      - Traders use VIX as the benchmark of volatility in the marketplace    - The index attempts to measure the degree of market uncertainty in marketplace    - VIX represents the 30 Day EXPECTED volatility of the S&P500 and uses CBOE SPX listed options as inputs    - Forward looking indicator    - VIX is expressed in percentage terms as an annualized 1 standard deviation of returns of the S&P500 index    - Option prices of the SPX can be used to derive the volatility of the underlying    ***We can use VIX as the market indicator for our weather emoticons***     - Since 1990 VIX has floated between 9 and approx 82    - 5 Year VIX negative correlation to SPX (-.72) and Bitcoin (-.17)    - We need to define thresholds of the VIX that correspond to the weather emoticons.    - We can use IQR to define these thresholds in v1.0    - The 5 year VIX mean value is 20.      - The 5 year interquartile ranges are as follows 25%[15], 50% [18.50], 75% [23.71]    ***EMOTICON LOGIC***        - Weather emoticons = [Sunny, Partly Sunny, Cloudy, Rain]    - Sunny [VIX < 15]    - Partly Sunny [VIX > 15.1 < 18.49]    - Cloudy [VIX > 18.50 < 23.70]    - Rain [VIX > 23.71 < 24.99]    - Lightning [VIX > 25]<jupyter_code>import numpy as np
import pandas as pd
import pandas_datareader.data as web
import datetime as dt
import matplotlib.pyplot as plt
# Using yahoo datareader 

start = dt.datetime(2018, 3, 29)
end = dt.datetime(2022, 3, 29)

#Get end of day closing prices using yahoo datareader

test = ['^VIX','^GSPC', 'BTC-USD']

test_df = web.DataReader(test,'yahoo',start,end)['Adj Close'].dropna()
test_df.head()
# Converting prices to percentage change to prove correlation

test_df.plot()
test_change = test_df.pct_change().dropna()
test_change.head()
test_change.plot()
# Summary statistics on dataset. IQR's will be used to assign emoticons

test_df.describe(include='all')
# Corrlelation of assets

test_change.corr()
# We will normalize prices from 0 to 1

test_df.plot()
#newest yahoo API 
import yfinance as yahoo_finance
import datetime
# Using yfinance api

ticker = '^VIX'

start_time = datetime.datetime(2014, 3, 29)

#end_time = datetime.datetime(2022, 3, 29)
end_time = datetime.datetime.now().date().isoformat()
def get_data(ticker, start_time, end_time):

    # yahoo gives only daily historical data
    connected = False
    while not connected:
        try:
            ticker_df = web.get_data_yahoo(ticker, start=start_time, end=end_time)
            connected = True
            print('connected to yahoo')
        except Exception as e:
            print("type error: " + str(e))
            time.sleep( 5 )
            pass   

    # use numerical integer index instead of date    
    ticker_df = ticker_df.reset_index()
    print(ticker_df.head(5))
    return ticker_df
df = get_data(ticker, start_time, end_time)
def normalize_data(df):
    # df on input should contain only one column with the price data (plus dataframe index)
    min = df.min()
    max = df.max()
    x = df 
    
    # time series normalization part
    # y will be a column in a dataframe
    y = (x - min) / (max - min)
    
    return y
df['norm'] = normalize_data(df['Adj Close'])
print(df.tail())
# plot price
plt.figure(figsize=(15,5))
plt.plot(df['Date'], df['Adj Close'])
plt.title('Price chart (Adj Close) ' + ticker)
plt.show()

# plot normalized price chart
plt.figure(figsize=(15,5))
plt.title('Normalized price chart ' + ticker)
plt.plot(df['Date'], df['norm'])

plt.show()
ticker1='^GSPC'
df1 = get_data(ticker1, start_time, end_time)
df1['norm'] = normalize_data(df1['Adj Close'])

# plot normalized price chart
plt.figure(figsize=(15,5))
plt.title('Normalized price chart ' + ticker + ' ' + ticker1)
plt.plot(df['Date'], df['norm'])
plt.plot(df1['Date'], df1['norm'])

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11014344262295082, 'fraction_numerical': 0.03048155737704918, 'mean_word_length': 3.572599531615925, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '591595', 'license': 'CC0-1.0', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1249, 'n_words': 443, 'path': 'research/bobby_emoticon_method.ipynb', 'repo_name': '312FinTech/Fintech-Forecast-App', 'size': '3904'}