trevorstephens / gplearn

Genetic Programming in Python, with a scikit-learn inspired API
http://gplearn.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.59k stars 281 forks source link

How to define a custom metric function using outside data? #254

Closed xuantianfengwu closed 2 years ago

xuantianfengwu commented 2 years ago

Here everyone,

I met a problem when using gplearn. My application senario is as below:

  1. I would like to build a trading strategy using M features as input, so my train_X shape is (N_train, M)
  2. I would like to predict y using gplearn as the signal, and I don't have an ideal y at the beginning, I just want to get the best-performance y during the generation learning process.
  3. Because of the reason in point 2, my custom metric function will use features such as [stoploss price, high price, low price] and so on to calculate the final net_value performance of the signals(y), which are not contained in my train_X.

However, I met problem when trying to find an elegent way to pass necessary features into the custom metric function.

The way I use now is by using a global variable, which I don't think is a good idea:

image

Does anyone have an elegant way to deal with my scenario?