i’m trying to adjust and apply my own trading strategies on Finrl meta environment and ensmeble agent method. in this process i decide to add some new features which are produced by a neuran network to capture unseen temporal dynamics in the dataset. after applying default feature engineering suggested by finrl itself and my new features my dataset have these columns:
INDICATORS = ['macd','rsi_30','cci_30','dx_30','wr_30','atr_30','chop_30','mfi_30','boll_ub','boll_lb','close_30_sma','close_60_sma']
MYNN = ['NN0','NN1','NN2','NN3','NN4']
df_columns = ['date','open','high','low','close','volume','tic','day','macd','rsi_30','cci_30','dx_30','wr_30','atr_30','chop_30','mfi_30','boll_ub','boll_lb','close_30_sma','close_60_sma','vix','turbulence','NN0','NN1','NN2','NN3','NN4']
stock_dimension = len(df_final.tic.unique())
state_space = 1 + 2*stock_dimension + (len(INDICATORS)+len(MYNN ))*stock_dimension
print(f"Stock Dimension: {stock_dimension}, State Space: {state_space}")
#Stock Dimension: 27, State Space: 514
so my state space is 514. but when i add my features, in the environment the _initialize_state function make states with shape of 442 instead of 514. after this i got the error that said “could not broadcast input array from shape (442,) into shape (514,)”.
here is the _initialize_state function that i adjust but i cant understand why its not working:
def _initiate_state(self):
if self.initial:
# For Initial State
if len(self.df.tic.unique()) > 1:
# for multiple stock
state = (
[self.initial_amount]
+ self.data.close.values.tolist()
+ self.num_stock_shares
+ sum(
(self.data[tech].values.tolist() for tech in self.tech_indicator_list),
[],
)
+ sum((self.data[feature].values.tolist() for feature in self.new_features_list), [])
)
else:
# for single stock
state = (
[self.initial_amount]
+ [self.data.close]
+ [0] * self.stock_dim
+ sum(([self.data[tech]] for tech in self.tech_indicator_list), [])
+ sum(([self.data[feature]] for feature in self.new_features_list), [])
)
else:
# Using Previous State
if len(self.df.tic.unique()) > 1:
# for multiple stock
state = (
[self.previous_state[0]]
+ self.data.close.values.tolist()
+ self.previous_state[(self.stock_dim + 1) : (self.stock_dim * 2 + 1)]
+ sum(
(self.data[tech].values.tolist() for tech in self.tech_indicator_list),
[],
)
+ sum((self.data[feature].values.tolist() for feature in self.new_features_list), [])
)
else:
# for single stock
state = (
[self.previous_state[0]]
+ [self.data.close]
+ self.previous_state[(self.stock_dim + 1) : (self.stock_dim * 2 + 1)]
+ sum(([self.data[tech]] for tech in self.tech_indicator_list), [])
+ sum(([self.data[feature]] for feature in self.new_features_list), [])
)
print(f"Initialized state shape: {len(state)} (Expected: {self.state_space})")
return state
i’ll be grateful if you can guide me on this problem…
in short i want my agents can see new features that i make, so these new features must be involve in state initialization step.
alee stvr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.