<jupyter_start><jupyter_text>GARCH Let's just play around a little bit<jupyter_code>import numpy as np
import pandas as pd

# local modules
from data_cleaning.import_data import import_data
from utils.plots import *
from utils.statistics import *

# autoreload modules when code is run
%load_ext autoreload
%autoreload 2
fx_pairs =[
    'USDRUB',
    'USDZAR',
    'USDBRL',
    'EURUSD',
    'USDJPY',
    'GBPUSD'
]
dfs = { pair : import_data(fx_pair=pair) for pair in fx_pairs }
dfs['GBPUSD']['test'] = np.maximum(0, 100*(dfs['GBPUSD']['px_ask'] - dfs['GBPUSD']['px_bid']) / ((dfs['GBPUSD']['px_ask'] + dfs['GBPUSD']['px_bid'])/2))
dfs['GBPUSD'].tail(5)
dfs['GBPUSD'].tail(5)<jupyter_output><empty_output><jupyter_text>Descriptive Statistics<jupyter_code>pd.set_option('display.max_rows', None)
for pair, df in dfs.items():
    description = (100*df['log_ret']).describe(percentiles=None)
    print(pair.upper())
    print(description)
    print(f"Skewness : {df['log_ret'].skew():.3f}")
    print(f"Excess kurtosis: {df['log_ret'].kurtosis()-3:.3f}")
    print(f"Mean (normalized) bid-ask spread: {df['normalized_bid_ask_spread'].mean(skipna=True):.3f}")
    print(f"Number of observations: {len(df.dropna()):.0f}")
    print('---------------------------')
for key in dfs.keys():
    df = dfs[key]
    df.dropna(inplace=True)
    print(f"{key} has sample start: {df.index[0]}  --> {len(df)} observations")
    
get_desctiptive_stats(df,plots=True)<jupyter_output><empty_output><jupyter_text>Plots  Returns<jupyter_code>plot_returns(df=df)<jupyter_output><empty_output><jupyter_text>Implied Vol<jupyter_code>plot_iv(df=df,months_out='3m')
plot_grid(df_dict=dfs, series='v1m',cols=2)<jupyter_output><empty_output><jupyter_text>Bid-ask spreads (pips)<jupyter_code>plot_grid(df_dict=dfs, series='normalized_bid_ask_spread',cols=2)<jupyter_output><empty_output><jupyter_text>I get that sometimes they can get out of wack, but a spread of <-500 on EURUSD seems odd...<jupyter_code># lowest EURUSD bid-ask spread
timestamp = dfs['EURUSD'].dropna()['bid_ask_spread_pips'].idxmin()
dfs['EURUSD'].dropna().loc[timestamp]
# highest USDRUB bid-ask spread
timestamp = dfs['USDRUB'].dropna()['bid_ask_spread_pips'].idxmax()
dfs['USDRUB'].dropna().loc[timestamp]<jupyter_output><empty_output><jupyter_text>Returns and IV grid<jupyter_code>plot_returns_and_vol(df_dict=dfs, vol_period='1m')<jupyter_output><empty_output><jupyter_text>Return distribution<jupyter_code>plot_return_distribution(df_dict=dfs, bins = 200)
mu, std = stats.norm.fit(df['log_ret'].dropna()) 
print(mu)
print(std)
degrees_of_freedom, loc, scale = stats.t.fit(df['log_ret'].dropna()) 

degrees_of_freedom
loc
scale
df['log_ret']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17432879735196763, 'fraction_numerical': 0.010297903641044501, 'mean_word_length': 7.0, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '89809', 'license': 'MIT', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1067, 'n_words': 159, 'path': 'tradingstrategy/garch_descriptive.ipynb', 'repo_name': 'frederikbachdk/Financial-Econometrics', 'size': '2719'}