Files
aiomql/examples/sample_backtester.py
T

29 lines
1.2 KiB
Python
Raw Normal View History

2024-10-28 06:36:10 +01:00
import logging
from datetime import datetime, UTC
2024-11-04 00:32:51 +01:00
from aiomql.lib.backtester import BackTester
2024-10-28 06:36:10 +01:00
from aiomql.core import Config
2024-11-16 09:26:10 +01:00
from aiomql.contrib.strategies import FingerTrap
2024-10-28 06:36:10 +01:00
from aiomql.contrib.symbols import ForexSymbol
2024-11-04 00:32:51 +01:00
from aiomql.core.backtesting import BackTestEngine
2024-10-28 06:36:10 +01:00
2024-11-16 09:26:10 +01:00
def back_tester():
Config(mode="backtest")
2024-11-11 05:56:08 +01:00
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
syms = ["Volatility 75 Index", "Volatility 100 Index", "Volatility 25 Index", "Volatility 10 Index"]
2024-10-28 06:36:10 +01:00
symbols = [ForexSymbol(name=sym) for sym in syms]
2024-11-16 09:26:10 +01:00
strategies = [FingerTrap(symbol=symbol) for symbol in symbols]
2024-11-04 00:32:51 +01:00
start = datetime(2024, 5, 1, tzinfo=UTC)
stop_time = datetime(2024, 5, 2, tzinfo=UTC)
end = datetime(2024, 5, 7, tzinfo=UTC)
2024-11-16 09:26:10 +01:00
back_test_engine = BackTestEngine(start=start, end=end, speed=3600, stop_time=stop_time,
close_open_positions_on_exit=True, assign_to_config=True, preload=True,
account_info={"balance": 350})
2024-11-04 00:32:51 +01:00
backtester = BackTester(backtest_engine=back_test_engine)
backtester.add_strategies(strategies=strategies)
2024-11-16 09:26:10 +01:00
backtester.execute()
2024-10-28 06:36:10 +01:00
2024-11-16 09:26:10 +01:00
back_tester()