margot.signals

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.

Parameters

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

Raises
  • 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 self.data 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 self.data.

Parameters

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

Returns

a list of Position objects.

Return type

list

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

Represents a Position with a symbol and a weight.

Parameters
  • 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.

as_map()

Return the Position as a dictionary.