Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created September 13, 2021 00:43
Show Gist options
  • Select an option

  • Save marcosan93/b3498f3770a7eacc9036573c0e46ef1f to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/b3498f3770a7eacc9036573c0e46ef1f to your computer and use it in GitHub Desktop.
def getPositions(val, thres=.01, short=True):
"""
Provided a specific sentiment value, will return 1, 0, or -1 representing
buy, hold, or sell respectively. The threshold will determined how high or low the score
needs to be to trigger a buy or sell, otherwise it will be a hold.
"""
# Sentiment score threshold
thres = .01
# Getting positions
if val > thres:
return 1
elif val < -thres and short:
return -1
else:
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment