Skip to content

Instantly share code, notes, and snippets.

@nemesifier
Created June 15, 2020 14:19
Show Gist options
  • Save nemesifier/3287ca6b05bfd2ee6abcc0cea66918d4 to your computer and use it in GitHub Desktop.
Save nemesifier/3287ca6b05bfd2ee6abcc0cea66918d4 to your computer and use it in GitHub Desktop.
Calculate average entry of a trade
def avg_position(positions):
assert type(positions) in (list, tuple)
total_value = 0
total_quantity = 0
for position in positions:
quantity, price = position
total_quantity += quantity
total_value += quantity / price
return total_quantity / total_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment