margot.signals¶
The margot.signals module contains classes to help you construct trading algorithms using the MargotDataFrame
-
class
margot.signals.
BaseAlgo
(env: dict = {}, market='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.
market (str) – The ISO code for the market we will use.
- 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.
-
weekday
(dt)¶ Return a human readable three letter day of week.
Convert the Python integer representation of day of week into a string.
e.g:
0: 'MON' (also known as self.MONDAY)
Note
You should always use the built in constants when passing days of the week. e.g. self.MONDAY, self.TUESDAY, … these map to the three charater strings.
- Parameters
dt (datetime or pd.Timestamp) – The datetime to check
- Returns
One of; ‘MON’, ‘TUE’, ‘WED’, ‘THU’, ‘FRI’, ‘SAT’, ‘SUN’
- Return type
str
-
property
next_close
¶ Return a UTC pd.Timestamp of the next close of trading session.
- Returns
Timestamp of the next close of cash session in UTC.
- Return type
pd.Timestamp
-
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, order_type: str)¶ 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.