margot.data.column.columns¶
-
class
margot.data.column.columns.
BaseColumn
(time_series: str, *args, **kwargs)¶ A Column represents a single time series of a symbol.
This could be adjusted_close, open, volume - etc.
To implement a new type of column, you must implement the ‘fetch’ method.
Example:
class MyDataProvider(BaseColumn): def fetch(self, symbol): df = get_my_dataframe(symbol) return self.clean(df)
- Optionally, you may need to add additional cleaning to the data, you can
do this by extending the clean() method.
Example:
class MyDataProvider(BaseColumn): def clean(self, df): df = df.rename(mapper={ 'Open': 'open', 'High': 'high', 'Low': 'low', 'Close': 'close', }, axis='columns') return super().clean(df)
- Parameters
function (str) – the name of the function passed to the Alphavantage API
time_series (str) – the name of the time_series that will be returned
-
get_label
()¶ Return the label for this column.
-
clone
()¶ Return a new instance of oneself.
-
setup
(symbol: str, env: dict = {})¶ Setup the column.
Called by the Symbol so that the symbol name can be passed.
-
clean
(df)¶ Clean the data.
-
load_or_fetch_series
(symbol: str)¶ Load of fetch the Dataframe, return the series.
In order to return the time-series, first determine if we have it and can return it, or if we need to fetch it.
TODO: Test for up-to-dateness (or maybe that happens in Symbol)?
- Parameters
symbol (str) – the name of the symbol to fetch.
- Returns
time-series of the column
- Return type
pd.Series
-
refresh
()¶ Refresh the data from the source.
- Returns
the whole dataframe (cleaned)
- Return type
pd.DataFrame
-
load
(symbol: str)¶ Load it.
-
save
(df, symbol)¶ Save it.
-
get_series
(when=None)¶ Get the data series as a pandas series.
- Parameters
when (datetime) – (optional) used when simulating historical data, typically using margot.backtest.
- Returns
time series of the field
- Return type
pd.Series
-
property
latest
¶ Return the latest value in this series.