You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
train_df = data_split(df, start=config.TRAIN_START_DATE,
end=config.TRAIN_END_DATE)
stock_dimension = len(train_df.tic.unique())
state_space = stock_dimension
print(f"Stock Dimension: {stock_dimension}, State Space: {state_space}")
env_kwargs = {
"hmax": hmax,
"initial_amount": initial_amount,
"transaction_cost_pct": transaction_cost_pct,
"state_space": state_space,
"stock_dim": stock_dimension,
"tech_indicator_list": config.INDICATORS,
"action_space": stock_dimension,
"reward_scaling": reward_scaling
}
# use cached model if you are iterating on evaluation code
if use_cached_model and os.path.exists("saved_models/a2c_model.pt"):
trained_a2c = A2C.load("saved_models/a2c_model.pt")
else:
e_train_gym = StockPortfolioEnv(df=train_df, **env_kwargs)
agent = DRLAgent(env=e_train_gym)
A2C_PARAMS = {
"n_steps": 10,
"ent_coef": 0.005,
"learning_rate": 0.0004
}
model_a2c = agent.get_model(model_name="a2c", model_kwargs=A2C_PARAMS)
trained_a2c = agent.train_model(
model=model_a2c,
tb_log_name='a2c',
total_timesteps=40000
)
# save trained_a2c model
trained_a2c.save("saved_models/a2c_model.pt")
# evaluate on test data
test_df = data_split(
df,
start=config.TEST_START_DATE,
end=config.TEST_END_DATE
)
e_test_gym = StockPortfolioEnv(df=test_df, **env_kwargs)
df_daily_return, df_actions = DRLAgent.DRL_prediction(
model=trained_a2c,
environment=e_test_gym,
)
df_daily_return["method"] = "a2c"
I got the following error:
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
The text was updated successfully, but these errors were encountered:
When trying to run this part:
I got the following error:
The text was updated successfully, but these errors were encountered: