Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in "Aarons_portfolio_optimization_example" #311

Open
gabrielp18 opened this issue Sep 8, 2023 · 1 comment
Open

Bug in "Aarons_portfolio_optimization_example" #311

gabrielp18 opened this issue Sep 8, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@gabrielp18
Copy link

gabrielp18 commented Sep 8, 2023

When trying to run this part:

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.

@zhumingpassional zhumingpassional added the bug Something isn't working label Nov 1, 2023
@rajathk2003
Copy link

Are you still facing the issue or has this been fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants