The margot.signals module contains classes to help you construct trading algorithms using the MargotDataFrame

class margot.signals.BaseAlgo(env: dict = {}, calendar='XNYS')

A base class to inherit when implementing your trading algorithm.

You should at least implement signal() which is the output of a trading algorithm.


env (dict) – a dictionary of environment variables, e.g. API keys. Overrides anything provided in sys env.

  • ValueError – the attribute, ‘data’ must be a reference to a MargotDataFrame.

  • NotImplementedError – If your subclass does not implement signal(), you will receive a NotImplementedError.

signal() → list

Return a list of Position objects for a given datetime.

simulate_signal(when: datetime.datetime)

Simulate a signal from a point in time.

Stores the original MargotDataFrame referenced by on a temporary reference so that the data attribute can be used by signal() to calculate positions at a point in history.

After running signal(), the full dataframe is re-referenced at


when (datetime) – when in history to go back to


a list of Position objects.

Return type


class margot.signals.Position(symbol: str, weight: float)

Represents a Position with a symbol and a weight.

  • symbol (str) – The identifier of the symbol. e.g. ‘SPY’.

  • weight (float) – A value between -1.0 and +1.0 representing the weight of this symbol in the position list.


Return the Position as a dictionary.