Created
February 26, 2022 05:00
-
-
Save marcosan93/4a3b2b0a19d50cf271624f27b6491c92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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