Moved interest calculation to an enum
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# flake8: noqa: F401
|
||||
from freqtrade.enums.backteststate import BacktestState
|
||||
from freqtrade.enums.interestmode import InterestMode
|
||||
from freqtrade.enums.rpcmessagetype import RPCMessageType
|
||||
from freqtrade.enums.runmode import NON_UTIL_MODES, OPTIMIZE_MODES, TRADING_MODES, RunMode
|
||||
from freqtrade.enums.selltype import SellType
|
||||
|
30
freqtrade/enums/interestmode.py
Normal file
30
freqtrade/enums/interestmode.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from enum import Enum, auto
|
||||
from decimal import Decimal
|
||||
|
||||
one = Decimal(1.0)
|
||||
four = Decimal(4.0)
|
||||
twenty_four = Decimal(24.0)
|
||||
|
||||
|
||||
class FunctionProxy:
|
||||
"""Allow to mask a function as an Object."""
|
||||
|
||||
def __init__(self, function):
|
||||
self.function = function
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.function(*args, **kwargs)
|
||||
|
||||
|
||||
class InterestMode(Enum):
|
||||
"""Equations to calculate interest"""
|
||||
|
||||
# Interest_rate is per day, minimum time of 1 hour
|
||||
HOURSPERDAY = FunctionProxy(
|
||||
lambda borrowed, rate, hours: borrowed * rate * max(hours, one)/twenty_four
|
||||
)
|
||||
|
||||
# Interest_rate is per 4 hours, minimum time of 4 hours
|
||||
HOURSPER4 = FunctionProxy(
|
||||
lambda borrowed, rate, hours: borrowed * rate * (1 + max(0, (hours-four)/four))
|
||||
)
|
Reference in New Issue
Block a user