margot.data¶
-
class
margot.data.
MargotDataFrame
(env: dict = {})¶ An MargotDataFrame brings together symbols, columns, features and ratios.
- Parameters
env (dict) – optional env dictionary as an alternative to sysenv variables.
- Raises
NotImplementedError – [description]
- Returns
[description]
- Return type
[type]
-
to_pandas
(when: datetime.datetime = None) → pandas.core.frame.DataFrame¶ Return a pandas Dataframe representing this MargotDataFrame.
- Parameters
when (datetime, optional) – slice to only show data that was available at when. That is, the EOD from the previous day. Defaults to None.
- Returns
- a Pandas dataframe representing all data from
the MargotDataFrame
- Return type
pd.DataFrame
-
refresh
()¶ Refresh all Symbols in this DataFrame.
-
property
start_date
¶ First Timestamp of the time-series index.
- Returns
a pandas timestamp.
- Return type
Timestamp
-
property
end_date
¶ Last Timestamp value of the time-series index.
- Returns
a pandas timestamp.
- Return type
Timestamp
-
property
index
¶ Return the time-series index.
- Returns
a pandas timeseries index.
- Return type
pd.Index
-
simulate
(when)¶ Create a dataframe simulating a datetime in history.
- Used for backtesting to simplify the writing of trading
algorithms.
- After simulating a historical datetime, it is not possible to
go back to the future.
- Parameters
when (tz_aware datetime or pd.Timestamp) – when to go back to.
-
class
margot.data.
Symbol
(symbol: str, trading_calendar: str, env: dict = {})¶ A Symbol, represents a securitised tradable asset.
A symbol can contain columns and features as members.
Usage example:
- class Equity(Symbol):
close = av.Column(time_series=’adjusted_close’)
spy = Equity(symbol=’SPY’, trading_calendar=’NYSE’)
- Parameters
symbol (str) – the code for this symbol
trading_calendar (str) – ISO Code market identifier uses https://github.com/quantopian/trading_calendars/blob/master/README.md
env (dict) – Optional - pass in env values rather than use sysenv.
-
refresh
()¶ Refresh all columns in this Symbol.
-
simulate
(when)¶ Make the Symbol simulate a datetime in history.
- Used for backtesting to simplify the writing of trading
algorithms.
- Parameters
when (tz_aware datetime or pd.Timestamp) – when to go back to.
-
class
margot.data.
Ratio
(numerator, denominator, label, **kwargs)¶ Ratio of two series.
Ratio = numerator / denomnator of two series.
- Parameters
numerator (str) – the series to numerate the ratio
denominator (str) – the series to denominate the ratio
label (str) – give it a name for your dataframe. e.g. current_ratio
-
property
latest
¶ Return the latest value in this series