0

When I run my code using print(xdata[0:1, 0:1, :])I got the fist line of array but when i run using print(state) I got a line of array which contain in xdata but I don't know why I got that .

def load_data(test=False):
    #prices = pd.read_pickle('data/OILWTI_1day.pkl')
    #prices = pd.read_pickle('data/EURUSD_1day.pkl')
    #prices.rename(columns={'Value': 'close'}, inplace=True)
    prices = pd.read_pickle('D:\data/XBTEUR_1day.pkl')
    prices.rename(columns={'Open': 'open', 'High': 'high', 'Low': 'low', 'Close': 'close', 'Volume (BTC)': 'volume'}, inplace=True)

    x_train = prices.iloc[-2000:-300,]
    x_test= prices.iloc[-2000:,]
    if test:
        return x_test
    else:
        return x_train

def init_state(indata, test=False):
    close = indata['close'].values
    diff = np.diff(close)
    diff = np.insert(diff, 0, 0)
    sma15 = SMA(indata, timeperiod=15)
    sma60 = SMA(indata, timeperiod=60)
    rsi = RSI(indata, timeperiod=14)
    atr = ATR(indata, timeperiod=14)

    #--- Preprocess data
    xdata = np.column_stack((close, diff, sma15, close-sma15, sma15-sma60, rsi, atr))

    xdata = np.nan_to_num(xdata)
    if test == False:
        scaler = preprocessing.StandardScaler()
        xdata = np.expand_dims(scaler.fit_transform(xdata), axis=1)
        joblib.dump(scaler, 'D:\data/scaler.pkl')
    elif test == True:
        scaler = joblib.load('D:\data/scaler.pkl')
        xdata = np.expand_dims(scaler.fit_transform(xdata), axis=1)
    state = xdata[0:1, 0:1, :]

    return state, xdata, close

indata = load_data(test=True)
A = init_state(indata, test=False)
print(xdata[0:1, 0:1, :])

1 Answer 1

1

You are not storing your return values in a reasonable way. You store all three values to A, and then access xdata. It's unclear why the latter is even defined at the global scope, and if it is, it's just some left-over from elsewhere. Use state, xdata, close = init_state(...) instead of A = ..., and everything should work like exepected.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much you save my time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.