Skip to content

Commit

Permalink
Merge pull request #435 from kakulukia/warmup-before
Browse files Browse the repository at this point in the history
adding the warmup candles in front of the test period
  • Loading branch information
saleh-mir authored Apr 14, 2024
2 parents 666a8bc + 7aa998a commit 0786ede
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions jesse/research/candles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
from typing import Union


def get_candles(exchange: str, symbol: str, timeframe: str, start_date: str, finish_date: str) -> np.ndarray:
def get_candles(
exchange: str,
symbol: str,
timeframe: str,
start_date: str,
finish_date: str,
warmup_candles: int = 0
) -> np.ndarray:
"""
Returns candles from the database in numpy format
Expand All @@ -13,7 +20,8 @@ def get_candles(exchange: str, symbol: str, timeframe: str, start_date: str, fin
:param timeframe: str
:param start_date: str
:param finish_date: str
:param warmup_candles: int
:return: np.ndarray
"""
import arrow
Expand All @@ -33,6 +41,9 @@ def get_candles(exchange: str, symbol: str, timeframe: str, start_date: str, fin
start_date = jh.date_to_timestamp(start_date)
finish_date = jh.date_to_timestamp(finish_date) - 60_000

if warmup_candles > 0:
start_date -= warmup_candles * jh.timeframe_to_one_minutes(timeframe) * 60_000

# validate
if start_date == finish_date:
raise ValueError('start_date and finish_date cannot be the same.')
Expand Down

0 comments on commit 0786ede

Please sign in to comment.