|
23 | 23 | from nautilus_trader.backtest.engine import BacktestEngine
|
24 | 24 | from nautilus_trader.backtest.engine import BacktestEngineConfig
|
25 | 25 | from nautilus_trader.config import LoggingConfig
|
26 |
| -from nautilus_trader.examples.algorithms.twap import TWAPExecAlgorithm |
27 |
| -from nautilus_trader.examples.strategies.ema_cross_twap import EMACrossTWAP |
28 |
| -from nautilus_trader.examples.strategies.ema_cross_twap import EMACrossTWAPConfig |
| 26 | +from nautilus_trader.examples.strategies.ema_cross_long_only import EMACrossLongOnly |
| 27 | +from nautilus_trader.examples.strategies.ema_cross_long_only import EMACrossLongOnlyConfig |
29 | 28 | from nautilus_trader.model.currencies import USD
|
30 | 29 | from nautilus_trader.model.data import BarType
|
31 | 30 | from nautilus_trader.model.enums import AccountType
|
|
51 | 50 | engine = BacktestEngine(config=config)
|
52 | 51 |
|
53 | 52 | # Add a trading venue (multiple venues possible)
|
54 |
| - NASDAQ = Venue("XNAS") |
| 53 | + NYSE = Venue("NYSE") |
55 | 54 | engine.add_venue(
|
56 |
| - venue=NASDAQ, |
| 55 | + venue=NYSE, |
57 | 56 | oms_type=OmsType.NETTING,
|
58 | 57 | account_type=AccountType.CASH,
|
59 | 58 | base_currency=USD,
|
60 |
| - starting_balances=[Money(10_000_000.0, USD)], |
| 59 | + starting_balances=[Money(1_000_000.0, USD)], |
61 | 60 | )
|
62 | 61 |
|
63 | 62 | # Add instruments
|
64 |
| - TSLA_NASDAQ = TestInstrumentProvider.equity(symbol="TSLA") |
65 |
| - engine.add_instrument(TSLA_NASDAQ) |
| 63 | + TSLA_NYSE = TestInstrumentProvider.equity(symbol="TSLA", venue="NYSE") |
| 64 | + engine.add_instrument(TSLA_NYSE) |
66 | 65 |
|
67 | 66 | # Add data
|
68 | 67 | loader = DatabentoDataLoader()
|
69 |
| - trades = loader.from_dbn_file( |
70 |
| - path=TEST_DATA_DIR / "databento" / "temp" / "tsla-xnas-20240107-20240206.trades.dbn.zst", |
71 |
| - instrument_id=TSLA_NASDAQ.id, |
72 |
| - ) |
73 |
| - engine.add_data(trades) |
| 68 | + |
| 69 | + filenames = [ |
| 70 | + "tsla-dbeq-basic-trades-2024-01.dbn.zst", |
| 71 | + "tsla-dbeq-basic-trades-2024-02.dbn.zst", |
| 72 | + "tsla-dbeq-basic-trades-2024-03.dbn.zst", |
| 73 | + ] |
| 74 | + |
| 75 | + for filename in filenames: |
| 76 | + trades = loader.from_dbn_file( |
| 77 | + path=TEST_DATA_DIR / "databento" / "temp" / filename, |
| 78 | + instrument_id=TSLA_NYSE.id, |
| 79 | + ) |
| 80 | + engine.add_data(trades) |
74 | 81 |
|
75 | 82 | # Configure your strategy
|
76 |
| - config = EMACrossTWAPConfig( |
77 |
| - instrument_id=TSLA_NASDAQ.id, |
78 |
| - bar_type=BarType.from_str("TSLA.XNAS-5-MINUTE-LAST-INTERNAL"), |
79 |
| - trade_size=Decimal(100), |
| 83 | + config = EMACrossLongOnlyConfig( |
| 84 | + instrument_id=TSLA_NYSE.id, |
| 85 | + bar_type=BarType.from_str("TSLA.NYSE-1-MINUTE-LAST-INTERNAL"), |
| 86 | + trade_size=Decimal(500), |
80 | 87 | fast_ema_period=10,
|
81 | 88 | slow_ema_period=20,
|
82 |
| - twap_horizon_secs=10.0, |
83 |
| - twap_interval_secs=2.5, |
84 | 89 | )
|
85 | 90 |
|
86 | 91 | # Instantiate and add your strategy
|
87 |
| - strategy = EMACrossTWAP(config=config) |
| 92 | + strategy = EMACrossLongOnly(config=config) |
88 | 93 | engine.add_strategy(strategy=strategy)
|
89 | 94 |
|
90 |
| - # Instantiate and add your execution algorithm |
91 |
| - exec_algorithm = TWAPExecAlgorithm() |
92 |
| - engine.add_exec_algorithm(exec_algorithm) |
93 |
| - |
94 | 95 | time.sleep(0.1)
|
95 | 96 | input("Press Enter to continue...")
|
96 | 97 |
|
|
106 | 107 | "display.width",
|
107 | 108 | 300,
|
108 | 109 | ):
|
109 |
| - print(engine.trader.generate_account_report(NASDAQ)) |
| 110 | + print(engine.trader.generate_account_report(NYSE)) |
110 | 111 | print(engine.trader.generate_order_fills_report())
|
111 | 112 | print(engine.trader.generate_positions_report())
|
112 | 113 |
|
|
0 commit comments