Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Trader

A trader is responsible for creating orders. It can do this based on the signals it receives, but also based on the latest version of the account.

API

The Trader API has 1 single method called create_orders that needs to be implemented:

class MyTrader(Trader):

    def create_orders(self, signals: list[Signal], event: Event, account: Account) -> list[Order]:
        ...

Some of the typical logic:

SimpleTrader

The SimpleTrader is the default trader implementation in roboquant.

As the name suggests, it implements a simple set of rules. This makes is easier to understand what is going on, although not suitable for all use cases.

Key characteristics:

FlexTrader

FlexTrader uses a percentage of the equity to determine the desired order sizes. So if your equity grows during a back test, so does the average order size.

Some of the features:

Custom Trader

If you have custom risk policies, you’ll have to implement a custom trader. It requires a lot of testing to see if all edge cases are handled.

A very basic and naive implementation would look something like this:

class MyTrader(Trader):

    def create_orders(self, signals: list[Signal], event: Event, account: Account) -> list[Order]:
        orders = []
        for signal in signals:
            asset = signal.asset
            if price := event.get_price(asset):
                if signal.is_buy:
                    order = Order(signal.asset, 1, price)
                else: 
                    order = Order(signal.asset, -1, price)
                orders.append(order)
        return orders

But this handles none of the challenges: