Discussing the article: "Fast trading strategy tester in Python using Numba" - page 6

 
bestvishes #:
Hi maxim, I think you are the smartest person on the forum, I hope to see a detailed description in the second article. grateful

Thanks for the flattering feedback, I will try to write something interesting for you.

 
def get_prices() -> pd.DataFrame:
Try:
# Load a comma-separated CSV file
p = pd.read_csv(f"files/{hyper_params['symbol']}.csv" )

# Check for required columns
required_columns = ['time', 'close' ]
for col in required_columns:
if col not in p.columns:
raise KeyError(f"Column'{col}' is missing from the file." )

# Convert the 'time' column to datetime format
p ['time'] = pd.to_datetime(p['time'], errors='coerce' )

# Set the time index
p. set_index('time', inplace=True )

# Leave only the 'close' column and remove rows with incorrect data
pFixed = p[[['close']].dropna( )

return pFixed
except Exception as e:
print(f"Error while processing data: {e}" )
return pd.DataFrame() #Return an empty DataFrame in case of an error
Files:
export_mt5.py  2 kb
 

I have some time and almost finished model training + hyperparameter optimisation in one bottle.

It will be possible to train many models at once, then optimise them, then select the best model with the best optimisation parameters, for example:

models = []
for i in range(20):
    print(f'Iteration: {i}')
    models.append(learnANDoptimize())

models.sort(key=lambda x: x[0][0]['score'])


index = -1
test_model(models[index][0][0]['dataframe'],
            [models[index][-1]],
            hyper_params['stop_loss'],
            hyper_params['take_profit'],
            hyper_params['forward'],
            hyper_params['backward'],
            hyper_params['markup'],
            True)

And output the result.

Then the model can be exported to the terminal with optimal hyperparameters. Or use the terminal optimiser itself.

I will start the article later, I haven't forgotten.