Test.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:RU-CCN 作者: JoshGlue 项目源码 文件源码
def random_investing():
    profit = 0
    stocks_invested = 0
    stocks_iterated = 0
    y = []
    state = env.reset()
    while stocks_iterated < stocks_to_iterate:
        action = np.random.choice(np.array(VALID_ACTIONS))
        next_state, reward, done, _ = env.step(action)

        if done:
            profit += reward
            stocks_invested += reward != 0
            y.append(profit / (stocks_invested or 1))
            state = env.reset()
            stocks_iterated += 1
            print(
                "Stock {}/{} , Profit: {}".format(stocks_iterated, stocks_to_iterate, profit / (stocks_invested or 1)))
        else:
            state = next_state
    x_new = np.linspace(x.min(),x.max(),smoothing)
    y = np.array(y)

    y_smooth = spline(x, y, x_new)
    return [plt.plot(x_new, y_smooth, linewidth=2, label='Random'),profit / (stocks_invested or 1)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号