"oanda": {
            "api_token":
            "OANDA_API_TOKEN",  # value is the environment variable name
            "account_id":
            "OANDA_ACCOUNT_ID",  # value is the environment variable name
        },
    }
}

# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.
strategy1 = EMACross(
    symbol=Symbol("AUD/USD", Venue("OANDA")),
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.MID),
    fast_ema=10,
    slow_ema=20,
    trade_size=Decimal(10000),
)

strategy2 = EMACross(
    symbol=Symbol("EUR/USD", Venue("OANDA")),
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.MID),
    fast_ema=10,
    slow_ema=20,
    trade_size=Decimal(10000),
)

strategy3 = EMACross(
    symbol=Symbol("GBP/USD", Venue("OANDA")),
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.MID),
        instrument_id=GBPUSD.id,
        aggregation=BarAggregation.MINUTE,
        price_type=PriceType.BID,
        data=TestDataProvider.gbpusd_1min_bid(),  # Stub data from the test kit
    )
    data.add_bars(
        instrument_id=GBPUSD.id,
        aggregation=BarAggregation.MINUTE,
        price_type=PriceType.ASK,
        data=TestDataProvider.gbpusd_1min_ask(),  # Stub data from the test kit
    )

    # Instantiate your strategy
    strategy = EMACross(
        instrument_id=GBPUSD.id,
        bar_spec=BarSpecification(5, BarAggregation.MINUTE, PriceType.BID),
        fast_ema_period=10,
        slow_ema_period=20,
        trade_size=Decimal(1_000_000),
        order_id_tag="001",
    )

    # Build the backtest engine
    engine = BacktestEngine(
        data=data,
        strategies=[strategy],  # List of 'any' number of strategies
        use_data_cache=
        True,  # Pre-cache data for increased performance on repeated runs
        # exec_db_type="redis",
        # exec_db_flush=False,
        # bypass_logging=True
    )
        symbol=GBPUSD.symbol,
        aggregation=BarAggregation.MINUTE,
        price_type=PriceType.BID,
        data=TestDataProvider.gbpusd_1min_bid(),  # Stub data from the test kit
    )
    data.add_bars(
        symbol=GBPUSD.symbol,
        aggregation=BarAggregation.MINUTE,
        price_type=PriceType.ASK,
        data=TestDataProvider.gbpusd_1min_ask(),  # Stub data from the test kit
    )

    # Instantiate your strategy
    strategy = EMACross(
        symbol=GBPUSD.symbol,
        bar_spec=BarSpecification(5, BarAggregation.MINUTE, PriceType.BID),
        fast_ema=10,
        slow_ema=20,
        trade_size=Decimal(1_000_000),
    )

    # Build the backtest engine
    engine = BacktestEngine(
        data=data,
        strategies=[strategy],  # List of 'any' number of strategies
        # exec_db_type="redis",
    )

    # Create a fill model (optional)
    fill_model = FillModel(
        prob_fill_at_limit=0.2,
        prob_fill_at_stop=0.95,
Beispiel #4
0
    SIM = Venue("SIM")
    symbol = Symbol("AUD/USD", SIM)
    AUDUSD = TestInstrumentProvider.default_fx_ccy(symbol)

    # Setup data container
    data = BacktestDataContainer()
    data.add_instrument(AUDUSD)
    data.add_quote_ticks(
        symbol=AUDUSD.symbol,
        data=TestDataProvider.audusd_ticks(),  # Stub data from the test kit
    )

    # Instantiate your strategy
    strategy = EMACross(
        symbol=AUDUSD.symbol,
        bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.MID),
        fast_ema_period=10,
        slow_ema_period=20,
        trade_size=Decimal(1_000_000),
        order_id_tag="001",
    )

    # Create a fill model (optional)
    fill_model = FillModel(
        prob_fill_at_limit=0.2,
        prob_fill_at_stop=0.95,
        prob_slippage=0.5,
        random_seed=42,
    )

    # Build the backtest engine
    engine = BacktestEngine(
Beispiel #5
0
    instruments = CCXTInstrumentProvider(client=ccxt.binance(), load_all=True)

    BINANCE = Venue("BINANCE")
    instrument_id = InstrumentId(symbol=Symbol("ETH/USDT"), venue=BINANCE)
    ETHUSDT_BINANCE = instruments.find(instrument_id)

    # Setup data container
    data = BacktestDataContainer()
    data.add_instrument(ETHUSDT_BINANCE)
    data.add_trade_ticks(ETHUSDT_BINANCE.id, TestDataProvider.ethusdt_trades())

    # Instantiate your strategy
    strategy = EMACross(
        instrument_id=ETHUSDT_BINANCE.id,
        bar_spec=BarSpecification(250, BarAggregation.TICK, PriceType.LAST),
        fast_ema_period=10,
        slow_ema_period=20,
        trade_size=Decimal("0.05"),
        order_id_tag="001",
    )

    # Build the backtest engine
    engine = BacktestEngine(
        data=data,
        strategies=[strategy],  # List of 'any' number of strategies
        use_data_cache=
        True,  # Pre-cache data for increased performance on repeated runs
        # exec_db_type="redis",
        # bypass_logging=True
    )

    # Create a fill model (optional)
Beispiel #6
0
}


# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.

instrument_id = InstrumentId(
    symbol=Symbol("ETH/USDT"),
    venue=Venue("BINANCE"),
)

strategy = EMACross(
    instrument_id=instrument_id,
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.LAST),
    fast_ema_period=10,
    slow_ema_period=20,
    trade_size=Decimal("0.01"),
    order_id_tag="001",
)

# Instantiate the node passing a list of strategies and configuration
node = TradingNode(strategies=[strategy], config=config)

# Register your client factories with the node (can take user defined factories)
node.add_data_client_factory("CCXT", CCXTDataClientFactory)
node.add_exec_client_factory("CCXT", CCXTExecutionClientFactory)
node.build()


# Stop and dispose of the node with SIGINT/CTRL+C
if __name__ == "__main__":
Beispiel #7
0
# BarSpecification options
# ------------------------
# price types include BID, ASK, MID, LAST
# Current aggregations TICK, SECOND, MINUTE, HOUR, DAY, VOLUME, VALUE
# These can be combined in any way, for example;
tick_bars = BarSpecification(100, BarAggregation.TICK, PriceType.LAST)
time_bars = BarSpecification(1, BarAggregation.MINUTE, PriceType.LAST)
volu_bars = BarSpecification(100, BarAggregation.VOLUME, PriceType.MID)
valu_bars = BarSpecification(1_000_000, BarAggregation.VALUE, PriceType.MID)

# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.
strategy = EMACross(
    symbol=Symbol("BTC/USD", Venue("BITMEX")),
    bar_spec=time_bars,
    fast_ema_period=10,
    slow_ema_period=20,
    trade_size=Decimal("10"),
)

# Instantiate the node passing a list of strategies and configuration
node = TradingNode(strategies=[strategy], config=config)

# Stop and dispose of the node with SIGINT/CTRL+C
if __name__ == "__main__":
    try:
        node.start()
    finally:
        node.dispose()
# custom options into the configuration file or even use another configuration
# file.

# BarSpecification options;
# price types include BID, ASK, MID, LAST
# Current aggregations TICK, MINUTE, HOUR, DAY, VOLUME, VALUE
# These can be combined in any way for example
tick_bars = BarSpecification(100, BarAggregation.TICK, PriceType.LAST)
time_bars = BarSpecification(1, BarAggregation.MINUTE, PriceType.BID)
volu_bars = BarSpecification(100, BarAggregation.VOLUME, PriceType.MID)
valu_bars = BarSpecification(1_000_000, BarAggregation.VALUE, PriceType.MID)

strategy1 = EMACross(
    symbol=Symbol("BTC/USDT", Venue("BINANCE")),
    bar_spec=tick_bars,
    fast_ema=10,
    slow_ema=20,
    trade_size=Decimal("0.001"),
)

strategy2 = EMACross(
    symbol=Symbol("ETH/USDT", Venue("BINANCE")),
    bar_spec=tick_bars,
    fast_ema=10,
    slow_ema=20,
    trade_size=Decimal("0.1"),
)

# Instantiate the node passing a list of strategies and configuration
node = TradingNode(
    strategies=[strategy1, strategy2],
            "account_id": "BITMEX_ACCOUNT_ID",  # value is the environment variable key
            "api_key": "BITMEX_API_KEY",        # value is the environment variable key
            "api_secret": "BITMEX_API_SECRET",  # value is the environment variable key
            "sandbox_mode": False,              # If clients use the testnet
        },
    },
}


# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.
strategy = EMACross(
    symbol=Symbol("BTC/USD", Venue("BITMEX")),
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.LAST),
    fast_ema_period=10,
    slow_ema_period=20,
    trade_size=Decimal("10"),
    order_id_tag="002",
)

# Instantiate the node passing a list of strategies and configuration
node = TradingNode(strategies=[strategy], config=config)


# Stop and dispose of the node with SIGINT/CTRL+C
if __name__ == "__main__":
    try:
        node.start()
    finally:
        node.dispose()
Beispiel #10
0
# ------------------------
# price types include BID, ASK, MID, LAST
# Current aggregations TICK, SECOND, MINUTE, HOUR, DAY, VOLUME, VALUE
# These can be combined in any way, for example;
tick_bars = BarSpecification(100, BarAggregation.TICK, PriceType.LAST)
time_bars = BarSpecification(1, BarAggregation.MINUTE, PriceType.LAST)
volu_bars = BarSpecification(100, BarAggregation.VOLUME, PriceType.MID)
valu_bars = BarSpecification(1_000_000, BarAggregation.VALUE, PriceType.MID)

# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.
strategy = EMACross(
    symbol=Symbol("ETH/USDT", Venue("BINANCE")),
    bar_spec=time_bars,
    fast_ema_period=10,
    slow_ema_period=20,
    trade_size=Decimal("0.05"),
    order_id_tag="001",
)

# Instantiate the node passing a list of strategies and configuration
node = TradingNode(strategies=[strategy], config=config)

# Stop and dispose of the node with SIGINT/CTRL+C
if __name__ == "__main__":
    try:
        node.start()
    finally:
        node.dispose()
Beispiel #11
0
    SIM = Venue("SIM")
    symbol = Symbol("AUD/USD", SIM)
    AUDUSD = TestInstrumentProvider.default_fx_ccy(symbol)

    # Setup data container
    data = BacktestDataContainer()
    data.add_instrument(AUDUSD)
    data.add_quote_ticks(
        symbol=AUDUSD.symbol,
        data=TestDataProvider.audusd_ticks(),  # Stub data from the test kit
    )

    # Instantiate your strategy
    strategy = EMACross(
        symbol=AUDUSD.symbol,
        bar_spec=BarSpecification(100, BarAggregation.TICK, PriceType.MID),
        fast_ema=10,
        slow_ema=20,
        trade_size=Decimal(1_000_000),
    )

    # Create a fill model (optional)
    fill_model = FillModel(
        prob_fill_at_limit=0.2,
        prob_fill_at_stop=0.95,
        prob_slippage=0.5,
        random_seed=42,
    )

    # Build the backtest engine
    engine = BacktestEngine(
        data=data,
Beispiel #12
0
    # Add starting balances for single-currency or multi-currency accounts
    engine.add_venue(
        venue=SIM,
        venue_type=VenueType.ECN,
        oms_type=OMSType.HEDGING,  # Venue will generate position_ids
        account_type=AccountType.MARGIN,
        base_currency=USD,  # Standard single-currency account
        starting_balances=[Money(1_000_000, USD)],
        fill_model=fill_model,
        modules=[fx_rollover_interest],
    )

    # Instantiate your strategy
    strategy = EMACross(
        instrument_id=AUDUSD.id,
        bar_spec=BarSpecification(100, BarAggregation.TICK, PriceType.MID),
        fast_ema_period=10,
        slow_ema_period=20,
        trade_size=Decimal(1_000_000),
        order_id_tag="001",
    )

    input("Press Enter to continue...")  # noqa (always Python 3)

    # Run the engine from start to end of data
    engine.run(strategies=[strategy])

    # Optionally view reports
    with pd.option_context(
            "display.max_rows",
            100,
            "display.max_columns",
Beispiel #13
0
        "binance": {
            "api_key":
            "BINANCE_API_KEY",  # value is the environment variable name
            "api_secret":
            "BINANCE_API_SECRET",  # value is the environment variable name
        },
    }
}

# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.
strategy = EMACross(
    symbol=Symbol("ETH/USDT", Venue("BINANCE")),
    bar_spec=BarSpecification(250, BarAggregation.TICK, PriceType.LAST),
    fast_ema=10,
    slow_ema=20,
    trade_size=Decimal("0.1"),
)

# Instantiate the node passing a list of strategies and configuration
node = TradingNode(
    strategies=[strategy],
    config=config,
)

# Stop and dispose of the node with SIGINT/CTRL+C
if __name__ == "__main__":
    try:
        node.start()
    finally:
    },
}

# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.

instrument1 = InstrumentId(
    symbol=Symbol("AUD/USD"),
    venue=Venue("OANDA"),
)

strategy1 = EMACross(
    instrument_id=instrument1,
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.MID),
    fast_ema_period=10,
    slow_ema_period=20,
    trade_size=Decimal(10000),
    order_id_tag="001",
)

# ------------------------------------------------------------------------------

instrument2 = InstrumentId(
    symbol=Symbol("EUR/USD"),
    venue=Venue("OANDA"),
)

strategy2 = EMACross(
    instrument_id=instrument2,
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.MID),
    fast_ema_period=10,
Beispiel #15
0
    instruments = CCXTInstrumentProvider(client=ccxt.binance(), load_all=True)

    BINANCE = Venue("BINANCE")
    ETHUSDT_BINANCE = instruments.get(Symbol("ETH/USDT", BINANCE))

    # Setup data container
    data = BacktestDataContainer()
    data.add_instrument(ETHUSDT_BINANCE)
    data.add_trade_ticks(ETHUSDT_BINANCE.symbol,
                         TestDataProvider.ethusdt_trades())

    # Instantiate your strategy
    strategy = EMACross(
        symbol=ETHUSDT_BINANCE.symbol,
        bar_spec=BarSpecification(250, BarAggregation.TICK, PriceType.LAST),
        fast_ema_period=10,
        slow_ema_period=20,
        trade_size=Decimal(100),
        order_id_tag="001",
    )

    # Build the backtest engine
    engine = BacktestEngine(
        data=data,
        strategies=[strategy],  # List of 'any' number of strategies
        use_tick_cache=
        True,  # Pre-cache ticks for increased performance on repeated runs
        # exec_db_type="redis",
        # bypass_logging=True
    )

    # Create a fill model (optional)
Beispiel #16
0
            "api_key":
            "BINANCE_API_KEY",  # value is the environment variable key
            "api_secret":
            "BINANCE_API_SECRET",  # value is the environment variable key
            "sandbox_mode": False,  # If clients use the testnet
        },
    },
}

# Instantiate your strategies to pass into the trading node. You could add
# custom options into the configuration file or even use another configuration
# file.
strategy = EMACross(
    symbol=Symbol("ETH/USDT", Venue("BINANCE")),
    bar_spec=BarSpecification(1, BarAggregation.MINUTE, PriceType.LAST),
    fast_ema_period=10,
    slow_ema_period=20,
    trade_size=Decimal("0.05"),
    order_id_tag="001",
)

# Instantiate the node passing a list of strategies and configuration
node = TradingNode(strategies=[strategy], config=config)

# Stop and dispose of the node with SIGINT/CTRL+C
if __name__ == "__main__":
    try:
        node.start()
    finally:
        node.dispose()
        USDJPY.symbol,
        BarAggregation.MINUTE,
        PriceType.BID,
        TestDataProvider.usdjpy_1min_bid(),
    )
    data.add_bars(
        USDJPY.symbol,
        BarAggregation.MINUTE,
        PriceType.ASK,
        TestDataProvider.usdjpy_1min_ask(),
    )

    strategies = [
        EMACross(
            symbol=USDJPY.symbol,
            bar_spec=BarSpecification(5, BarAggregation.MINUTE, PriceType.BID),
            fast_ema=10,
            slow_ema=20,
        )
    ]

    config = BacktestConfig(
        exec_db_type="in-memory",
        exec_db_flush=False,
        frozen_account=False,
        starting_capital=1000000,
        account_currency=USD,
        short_term_interest_csv_path="default",
        bypass_logging=False,
        level_console=LogLevel.INFO,
        level_file=LogLevel.DEBUG,
        level_store=LogLevel.WARNING,