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

How to predict current decision #12

Open
JustinGuese opened this issue Sep 4, 2020 · 4 comments
Open

How to predict current decision #12

JustinGuese opened this issue Sep 4, 2020 · 4 comments

Comments

@JustinGuese
Copy link

Hey, so to predict the current timestamp what would I need to do?

@JustinGuese
Copy link
Author

JustinGuese commented Sep 4, 2020

adding in methods.py the following and calling it from a file similar to eval.py?

def predict_next(agent,data,window_size):
    state = get_state(data, len(data)+1, window_size + 1)
    # select an action
    action = agent.act(state)
    if action == 1:
        print("BUY!")
    elif action == 2: 
        print("SELL! (if you bought a stock")
    else:
        print("HOLD.")```

@BimwerxNZ
Copy link

BimwerxNZ commented Oct 29, 2020

Hi,

I've added predict_next to methods.py and created a similar script to eval.py - but get the following error:

Traceback (most recent call last):
File ".\predict.py", line 65, in
main(eval_stock, window_size, model_name)
File ".\predict.py", line 41, in main
profit, _ = predict_next(agent, data, window_size)
File "D:\Dev\StockPred\trading-bot-master\trading_bot\methods.py", line 112, in predict_next
state = get_state(data, len(data)+1, window_size + 1)
File "D:\Dev\StockPred\trading-bot-master\trading_bot\ops.py", line 26, in get_state
res.append(sigmoid(block[i + 1] - block[i]))
IndexError: list index out of range

Any suggestions?

Thanks in advance, great project!
predict.zip

  • apologies, I'm not well-versed in Python

@JustinGuese
Copy link
Author

Hey, I'll have to look that up in the next days, but yes I had the same error.
I think as a quick fix you could add sth along the lines of

#ops.py

def get_state(data, t, n_days):
    """Returns an n-day state representation ending at time t
    """
    #blocks = []
    #for feature in datan.columns:
    #feature = "Close"
    #data = list(datan[feature])
    if len(data) == 0:
        raise Exception("DATA IS ZERO!!! CHECK YFINANCE OUTPUT")
    d = t - n_days - 1
    block = []
    if d >= 0:
        block = data[d: t + 1] 
    else: 
        block = data[0:d] # pad with t0
    res = []
    for i in range(n_days - 1):
        x = sigmoid(block[i + 1] - block[i]) # x is number
        res.append(x)
    return np.array([res])

@BimwerxNZ
Copy link

BimwerxNZ commented Nov 3, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants