def import_data(config_obj, caller: int = BACKTEST): """ Imports CSV data and loads it. :param config_obj: Configuration QDialog object (from configuration.py) :param caller: Caller that'll determine who called this function -> OPTIMIZER or BACKTEST """ inner_dict = config_obj.optimizer_backtest_dict[caller] action = 'backtest' if caller == BACKTEST else 'optimization' inner_dict['infoLabel'].setText("Importing data...") filePath, _ = QFileDialog.getOpenFileName(config_obj, 'Open file', helpers.ROOT_DIR, "CSV (*.csv)") if filePath == '': inner_dict['infoLabel'].setText("Data not imported.") inner_dict['downloadProgress'].setValue(0) else: inner_dict['data'] = helpers.load_from_csv(filePath, descending=False) inner_dict['dataType'] = "Imported" inner_dict['dataInterval'] = inner_dict[ 'dataIntervalComboBox'].currentText() inner_dict['infoLabel'].setText("Imported data successfully.") inner_dict['dataLabel'].setText( f'Using imported data to conduct {action}.') inner_dict['downloadProgress'].setValue(100) setup_calendar(config_obj=config_obj, caller=caller)
def test_load_from_csv(descending: bool, expected: List[Dict[str, Union[str, float]]]): """ Test load from CSV function works as intended. :param descending: Boolean whether data is in descending format or not. :param expected: Expected data to return from function. """ data_path = os.path.join(ROOT_DIR, 'tests', 'data/small_csv_data.csv') loaded_data = load_from_csv(data_path, descending=descending) assert loaded_data == expected, f"Expected: {expected} Got: {loaded_data}"
def import_data(self): """ Imports CSV data and loads it. """ self.backtestInfoLabel.setText("Importing data...") filePath, _ = QFileDialog.getOpenFileName(self, 'Open file', helpers.ROOT_DIR, "CSV (*.csv)") if filePath == '': self.backtestInfoLabel.setText("Data not imported.") return self.data = helpers.load_from_csv(filePath, descending=False) self.dataType = "Imported" self.backtestInfoLabel.setText("Imported data successfully.") self.backtestDataLabel.setText('Currently using imported data to conduct backtest.') self.setup_calendar()
def import_data(config_obj, caller: int = BACKTEST): """ Imports CSV data and loads it. :param config_obj: Configuration QDialog object (from configuration.py) :param caller: Caller that'll determine who called this function -> OPTIMIZER or BACKTEST """ config_obj.optimizer_backtest_dict[caller]['infoLabel'].setText("Importing data...") filePath, _ = QFileDialog.getOpenFileName(config_obj, 'Open file', helpers.ROOT_DIR, "CSV (*.csv)") if filePath == '': config_obj.optimizer_backtest_dict[caller]['infoLabel'].setText("Data not imported.") else: config_obj.optimizer_backtest_dict[caller]['data'] = helpers.load_from_csv(filePath, descending=False) config_obj.optimizer_backtest_dict[caller]['dataType'] = "Imported" config_obj.optimizer_backtest_dict[caller]['infoLabel'].setText("Imported data successfully.") config_obj.optimizer_backtest_dict[caller]['dataLabel'].setText('Using imported data to conduct backtest.') setup_calendar(config_obj=config_obj, caller=caller)
""" Test backtester object. """ import os from datetime import datetime import pytest from algobot.enums import LONG, SHORT, STOP, TRAILING from algobot.helpers import convert_all_dates_to_datetime, load_from_csv from algobot.traders.backtester import Backtester data_path = os.path.join(os.path.dirname(__file__), 'data', '1INCHUSDT_data_1m.csv') test_data = load_from_csv(path=data_path, descending=False) convert_all_dates_to_datetime(test_data) @pytest.fixture(scope='function', name='backtester') def get_backtester(): """ Sets up a backtester object and returns it as a fixture. """ backtester = Backtester( startingBalance=1000, data=test_data, strategies=[], strategyInterval='15m', symbol="1INCHUSDT", marginEnabled=True,
import os import unittest from datetime import datetime import pytest from algobot.enums import LONG, SHORT, STOP, TRAILING from algobot.helpers import convert_all_dates_to_datetime, load_from_csv from algobot.traders.backtester import Backtester test_data = load_from_csv( path=f'{os.path.dirname(__file__)}/1INCHUSDT_data_1m.csv', descending=False) convert_all_dates_to_datetime(test_data) class TestBacktester(unittest.TestCase): def setUp(self) -> None: """ Sets up a backtester object. """ self.backtester = Backtester( startingBalance=1000, data=test_data, strategies=[], strategyInterval='15m', symbol="1INCHUSDT", marginEnabled=True, ) self.backtester.apply_take_profit_settings({ 'takeProfitType': TRAILING,