Hourly Trend System with Simulated Market and Limit Orders
Summary
This example assembles a futures trend-following system on hourly data and shows how to choose among vanilla accounting, simulated market orders, and simulated limit orders. The system combines raw data, trading rules, forecast scaling and combination, position sizing, portfolio construction, and an account stage. When no simulation data source is supplied, it uses a database-backed futures data provider; configuration is loaded separately.
The example illustrates a key backtesting distinction: order simulation can model how orders fill, while vectorized profit-and-loss calculations do not provide the same order-level simulation. It contains no strategy results, parameter evaluation, or evidence that one execution mode performs better. Practical conclusions depend on the configured rules, data, and simulator assumptions, so these choices should be validated against the intended trading setup.
Key ideas
- The example applies a modular futures trading system to hourly data.
- It supports simulated market orders, simulated limit orders, and vanilla accounting.
- The system separates forecasting, position sizing, portfolio construction, and account handling.
- Order simulation can represent execution details omitted by vectorized profit-and-loss calculations.
- The code provides no performance comparison or validation of simulator assumptions.
Tags
Full text
# hourly_with_order_simulation.py
```py
### THIS IS AN EXAMPLE OF HOW TO USE A PROPER ORDER SIMULATOR RATHER THAN VECTORISED
### P&L, FOR A SIMPLE TREND SYSTEM USING HOURLY DATA WITH MARKET ORDERS
import matplotlib
matplotlib.use("TkAgg")
from syscore.constants import arg_not_supplied
# from sysdata.sim.csv_futures_sim_data import csvFuturesSimData
from sysdata.sim.db_futures_sim_data import dbFuturesSimData
from sysdata.config.configdata import Config
from systems.forecasting import Rules
from systems.basesystem import System
from systems.rawdata import RawData
from systems.forecast_combine import ForecastCombine
from systems.forecast_scale_cap import ForecastScaleCap
from systems.positionsizing import PositionSizing
from systems.portfolio import Portfolios
from systems.accounts.order_simulator.hourly_market_orders import (
AccountWithOrderSimulatorForHourlyMarketOrders,
)
from systems.accounts.order_simulator.hourly_limit_orders import (
AccountWithOrderSimulatorForLimitOrders,
)
from systems.accounts.accounts_stage import Account
def futures_system(
sim_data=arg_not_supplied,
use_limit_orders: bool = False,
use_vanilla_accounting: bool = False,
config_filename="systems.provided.example.hourly_with_order_simulator.yaml",
):
if sim_data is arg_not_supplied:
sim_data = dbFuturesSimData()
config = Config(config_filename)
if use_vanilla_accounting:
account = Account()
elif use_limit_orders:
account = AccountWithOrderSimulatorForLimitOrders()
else:
account = AccountWithOrderSimulatorForHourlyMarketOrders()
system = System(
[
account,
Portfolios(),
PositionSizing(),
ForecastCombine(),
ForecastScaleCap(),
Rules(),
RawData(),
],
sim_data,
config,
)
return system
```Shown in full with attribution under the source's licence. Licence: GPL-3.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.