blankly-finance / blankly

🚀 💸 Easily build, backtest and deploy your algo in just a few lines of code. Trade stocks, cryptos, and forex across exchanges w/ one package.
https://package.blankly.finance
GNU Lesser General Public License v3.0
2.03k stars 261 forks source link

Backtesting time interval not being correctly calculated #215

Closed unmais closed 1 year ago

unmais commented 1 year ago

Description

file: backtest_controller.py, line: 508

        if to is not None:
            start = time.time() - time_interval_to_seconds(to)
            end = time.time()

The current time should be checked once and then its value used as a constant for backtesting time calculation. Otherwise the resulting interval (end - start) will always be slightly longer than the user expects. Proposed change:

    if to is not None:
        end = time.time()
        start = end - time_interval_to_seconds(to)
EmersonDove commented 1 year ago

Hey @unmais thanks for opening an issue. I'm happy to accept a pull request for this change just be aware this will have microseconds of difference from the current calculation.