trading-bot icon indicating copy to clipboard operation
trading-bot copied to clipboard

How to predict current decision

Open JustinGuese opened this issue 3 years ago • 4 comments

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

JustinGuese avatar Sep 04 '20 15:09 JustinGuese

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.")```

JustinGuese avatar Sep 04 '20 15:09 JustinGuese

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

BimwerxNZ avatar Oct 29 '20 08:10 BimwerxNZ

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])

JustinGuese avatar Nov 03 '20 09:11 JustinGuese

Very kind of you to respond,  thanks so much.On 3/11/2020 22:20, Justin Güse [email protected] wrote: 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])

—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.

BimwerxNZ avatar Nov 03 '20 11:11 BimwerxNZ