pskrunner14 / trading-bot

Stock Trading Bot using Deep Q-Learning
MIT License
951 stars 334 forks source link

How to predict current decision #12

Open JustinGuese opened 4 years ago

JustinGuese commented 4 years ago

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

JustinGuese commented 4 years ago

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 commented 3 years ago

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, modelname) 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

JustinGuese commented 3 years ago

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 commented 3 years ago

Very kind of you to respond,  thanks so much.On 3/11/2020 22:20, Justin Güse notifications@github.com 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.