Files
OpenBB/openbb_terminal/cryptocurrency/tools/tools_helpers.py
jose-donato a12e0946da Starts crypto tools menu (#1668)
* started crypto tools menu

* allow zero float

* added obb script

Co-authored-by: Chavithra <chavithra@gmail.com>
Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
Co-authored-by: minhhoang1023 <40023817+minhhoang1023@users.noreply.github.com>
2022-04-14 14:24:42 +07:00

59 lines
1.3 KiB
Python

def change_variation(change: float) -> float:
"""Helper to convert change variation
Parameters
----------
change: float
percentage change
Returns
-------
float:
converted value
"""
return (100 + change) / 100
def calculate_hold_value(changeA: float, changeB: float, proportion: float) -> float:
"""Calculates hold value of two different coins
Parameters
----------
changeA: float
price change of crypto A in percentage
changeB: float
price change of crypto B in percentage
proportion: float
percentage of first token in pool
Returns
-------
float:
hold value
"""
return (change_variation(changeA) * proportion) / 100 + (
(change_variation(changeB) * (100 - proportion)) / 100
)
def calculate_pool_value(changeA, changeB, proportion):
"""Calculates pool value of two different coins
Parameters
----------
changeA: float
price change of crypto A in percentage
changeB: float
price change of crypto B in percentage
proportion: float
percentage of first token in pool
Returns
-------
float:
pool value
"""
return pow(change_variation(changeA), proportion / 100) * pow(
change_variation(changeB), (100 - proportion) / 100
)