Munging for excess returns (relative to the universe). Can't do much without it, IMHO

All,

I did not want to hijack the thread where this was posted.

“Relative returns” are important. In this regard, I think the only way to make results MORE consistent across different market regimes and to figure out if any strategy (machine learning or not) has found something of value is to compare your returns to the returns of the universe. Or determine if your system is maybe not as good as it looks initially, if the results look good but are not better than the market over that period.

Not just to compare, but also to let your strategy learn without the noise of the market drowning out what could otherwise be seen to be effective with whatever algorithms you are using.

P123 does not have an option for excess returns relative to the universe in DataMiner downloads, that I am aware of. But all of the stock returns for the universe are in the DataMiner download. And that can be used to munged excess returns with Python:

import pandas as pd

//Read the CSV file
df = pd.read_csv(your path)

//Ensure that the “Date” column is a datetime object
df[‘Date’] = pd.to_datetime(df[‘Date’])

//Calculate the mean returns for each date
mean_returns = df.groupby(‘Date’)[‘Future 1wkRet’].mean()

//Subtract the mean returns for each date from the individual returns
df[‘ExcessReturn’] = df.groupby(‘Date’)[‘Future 1wkRet’].transform(lambda x: x - x.mean())

//Now, df[‘ExcessReturn’] contains the excess returns for each ticker and date

//Define the file path for the desktop
file_path = ‘~/Desktop/DataMiner/xs/Twoxs.csv’

//Write the DataFrame to the CSV file
df.to_csv(file_path, index=False)
print(f’Excess returns have been saved to {file_path}')

Seriously, it probably will not work for you without it–whether a machine is trying to find it for you or you are trying to find it yourself (visually) in a graphic output.

Jim