Closed fightthepower closed 4 years ago
I think I don't completely understand what you are asking. The code you show should do you what you want, shouldn't it? What is not working at the moment?
The above code is just a pseudo code to get my idea through.
When I run the code I am getting this error
0%| | 1/504 [00:00<00:18, 26.62it/s]
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The problem is pred
is an array with 1320 elements and that is the cause of above error. I want to iterate my prediction value like b.price('JNUG') > jnug_ma
simultaneously on the given day.
My ML algo takes previous day close, open and high to get a prediction for current day
Long if ml prediction is greater than zero and current day close is greater than current day ma
Short if ml prediction is less than zero and current day close is less than current day ma
So I assume you want to do regression on multiple symbols prices (hence 1320 elements). A way to do this, if your training logic is already in place, would be to iterate through your predictions and allocate 1/number_of_predictions of capital to it. Assuming you zip your symbols and predictions:
for symbol, pred in preds:
if pred < 0:
b.short(symbol, percent=1/len(preds)
if pred > 0:
b.long(symbol, percent=1/len(preds)
Does this help?
Hey thank you for replying. It is not symbols and I was confused of how data is parsed in simple-back , this helped debug the problem
b.prices['JNUG',-2:]['close'].shape
b.prices['JNUG']['close'].shape
and rewrote those lies
d = {'close': b.prices['JNUG',-1:]['close'], 'open': b.prices['JNUG',-1:]['open'],'high': b.prices['JNUG',-1:]['high']}
df = pd.DataFrame(d).dropna()
if df.empty:
continue
pred = reg.predict(df)
Thank you for taking your time :+1:
I have a ML model which takes three inputs and outputs a single value , similar to this
Here instead of iterating through
b.prices['JNUG']['close']
alone I want to also use my newly created datadf
and its values for prediction and trading.How can I do this in simple-back preferably without writing any oop code?