Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created February 26, 2022 05:00
Show Gist options
  • Save marcosan93/4a3b2b0a19d50cf271624f27b6491c92 to your computer and use it in GitHub Desktop.
Save marcosan93/4a3b2b0a19d50cf271624f27b6491c92 to your computer and use it in GitHub Desktop.
def sentimentPositions(val, thresh=0.1, short=True):
"""
Returns position as 1, -1, or 0 for Buy, Sell,
and Do Nothing respectively based on the given
sentiment value and threshold.
"""
if val > thresh:
return 1
elif val < -thresh and short:
return -1
else:
return 0
def fbpPositions(pred_df, short=True):
"""
Gets positions based on the predictions and the actual values.
"""
if pred_df['open'] < pred_df['yhat_lower']:
return 1
elif pred_df['open'] > pred_df['yhat_upper'] and short:
return -1
else:
return 0
def overallPosition(df):
"""
Returns the position if both values in the DF are the same.
Otherwise, the position will be to do nothing.
"""
if df['sentiment_positions']==df['fbp_positions']:
return df['sentiment_positions']
else:
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment