<jupyter_start><jupyter_text>Settings<jupyter_code>from os import listdir
from os.path import isfile, join

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib inline
main_path = 'C:\\Data\\UCL\\@MSc Project - Data and Sources\\Sentiment results\\Portfolios\\New'<jupyter_output><empty_output><jupyter_text>Load the data<jupyter_code>files = [
    'RETURNS_LONGS_S&P 500_Rating_1M.csv', 'RETURNS_SHORTS_S&P 500_Rating_1M.csv',
    'RETURNS_LONGS_S&P 500_Rating_3M_Diff.csv', 'RETURNS_SHORTS_S&P 500_Rating_3M_Diff.csv'
]
data = {f: pd.read_csv(join(main_path, f), index_col=0) for f in files}<jupyter_output><empty_output><jupyter_text>Get months return<jupyter_code>min_dim = min([dataset.shape[1] for dataset in data.values()])

month_returns = {
    key: dataset.iloc[:,-min_dim:].mean(axis=0) for (key, dataset) in data.items()
}

month_returns_df = pd.DataFrame(month_returns)
month_returns_df.columns = ['1M_L', '1M_S', 'D3M_L', 'D3M_S']
return_1M = month_returns_df.T.iloc[:2,:].sum(axis=0)
return_D3M = month_returns_df.T.iloc[2:,:].sum(axis=0)<jupyter_output><empty_output><jupyter_text>**t-test**$$    t = \frac{\bar{X}_1 - \bar{X}_2}{s_p\sqrt{\frac{1}{T}+\frac{1}{T}}},$$where$$    s_p = \sqrt{\frac{(T-1)s_1^2 + (T-1)s_2^2}{2T-2}}$$<jupyter_code>T=return_1M.shape[0]

s_p = np.sqrt((T * (return_1M.var() + return_D3M.var()) ) / (2*T - 2))

t = (return_1M.mean() - return_D3M.mean()) / (s_p * np.sqrt(2/T))

t
return_1M.var()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17828947368421053, 'fraction_numerical': 0.03355263157894737, 'mean_word_length': 6.208530805687204, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '630532', 'license': 'MIT', 'n_tokens_mistral': 701, 'n_tokens_neox': 680, 'n_words': 98, 'path': 'Exploration/Diff in returns (LONG-SHORT).ipynb', 'repo_name': 'stancld/MSc-Project', 'size': '1520'}