Created
June 15, 2020 14:19
-
-
Save nemesifier/3287ca6b05bfd2ee6abcc0cea66918d4 to your computer and use it in GitHub Desktop.
Calculate average entry of a trade
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 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