This exploratory notebook is a good starting point to help you make your first steps in the challenge.

We remind that the aim of the 2021 QRT Challenge Data is to determine the link between two types of assets: liquids and illiquids. We provide returns of 100 illiquid assets and the aim is to predict, for the same day, the sign of the return of 100 liquid assets.

In the following, we propose a very simple approach that determines for each liquid asset, the illiquid asset with maximum correlation. Thus we measures the $\beta$ (see definition here) between these assets which will be used for prediction.

This notebook is very straightforward, but if you have any question or comment, please ask it in the forum.

In [1]:

```
import numpy as np
import pandas as pd
from tqdm.notebook import tqdm
```

In [2]:

```
X_train = pd.read_parquet('./X_train.parquet')
Y_train = pd.read_csv('./y_train.csv', index_col=0)
X_test = pd.read_parquet('./X_test.parquet')
X_train.head()
```

Out[2]:

We transform the data so that each line corresponds to a specific day

In [3]:

```
idx_ret_features = np.where(X_train.columns.str.contains('RET'))[0]
init_ret_features = X_train.columns[idx_ret_features]
target_ret_features = 'RET_' + X_train['ID_TARGET'].unique()
returns = {}
for day in tqdm(X_train.ID_DAY.unique()):
u = X_train.loc[X_train.ID_DAY == day]
a = u.iloc[0, idx_ret_features]
b = Y_train[X_train.ID_DAY == day]['RET_TARGET']
b.index = 'RET_' + u.ID_TARGET
returns[day] = pd.concat([a, b])
returns = pd.DataFrame(returns).T.astype(float)
returns.head()
```

Out[3]:

We compute the $\beta$ between all assets. This matrix will determine the linear link between all assets.

This step is not necessary and could be done in the next step, but it is a good way to introduce the use of a matrix shrinkage, greatly used in finance when dealing with noisy data. See here for more information.

In [4]:

```
from sklearn.covariance import oas
features = returns.columns
cov = pd.DataFrame(oas(returns.fillna(0))[0], index=features, columns=features)
beta = cov / np.diag(cov)
beta.head()
```

Out[4]:

For each target asset (liquid assets), we determine the illiquid asset that has maximum correlation and we save the id and the associated beta coefficient.

In [5]:

```
proj_matrix = beta.T.loc[init_ret_features, target_ret_features]
corr = returns.corr().loc[init_ret_features, target_ret_features]
coeffs = {}
for id_target in tqdm(target_ret_features):
x = proj_matrix[id_target]
c = corr[id_target]
id_init_max = c.abs().idxmax()
j = id_target.replace('RET_', '')
coeffs[j] = (id_init_max, x[id_init_max])
```

We thus simply make the predictions on the test data set using the pairs we saved and the beta.

If there is missing values, we replace them with the mean.

In [6]:

```
pred = {}
for idx, row in tqdm(X_test.iterrows()):
j = row['ID_TARGET']
i, val = coeffs[j]
x = row[i]
if np.isnan(x):
x = row[init_ret_features].mean()
p = x * val
pred[idx] = p
pred = pd.Series(pred, name="RET_TARGET")
# The NaNs are filled by the mean of the prediction of that day
pred_mean_day = pred.groupby(X_test['ID_DAY']).transform('mean')
pred = pred.fillna(pred_mean_day)
pred = np.sign(pred)
```

In [7]:

```
pred.name = "RET_TARGET"
pred = pred.astype(int)
pred.to_csv('./benchmark.csv')
```