Skip to content

OracleDataFrame

Reference information for the OracleDataFrame class.

anterior.source.OracleDataFrame

OracleDataFrame(df, date_col='index', past=True)

DataFrame that inherits all the methods and attributes of a pandas or polars DataFrame, but only returns and modifies data before/after the current date depending on specification.

PARAMETER DESCRIPTION
df

The DataFrame to use as the data source.

TYPE: DataFrame | DataFrame

date_col

The name of the column containing dates. Defaults to the index.

TYPE: str DEFAULT: 'index'

past

If True, the OracleDataFrame will return only the data before the current date. If False, it will return only the data after the current date.

TYPE: bool DEFAULT: True

Examples:

OracleDataFrame vs regular DataFrame

from pandas import DataFrame
from anterior import BackTester, RetroDataFrame

data = ... #  data between 2010 to 2024
df = DataFrame(data)
oracle_df = RetroDataFrame(data, past=True)

bt = BackTester()

@bt.on(year=2020, month=1, day=1)
def update()
    df.iloc[:-5]            # returns the last 5 rows of the entire dataset
    oracle_df.iloc[:-5]     # returns the last 5 rows of the dataset before 2020-01-01

bt.run("2010-01-01", "2024-01-01")
from polars import DataFrame
from anterior import BackTester, RetroDataFrame

data = ... #  data between 2010 to 2024
df = DataFrame(data)
oracle_df = RetroDataFrame(data, past=False)

bt = BackTester()

@bt.on(year=2020, month=1, day=1)
def update()
    df.iloc[:5]             # returns the first 5 rows of the entire dataset
    oracle_df.iloc[:5]      # returns the first 5 rows of the dataset after 2020-01-01

bt.run("2010-01-01", "2024-01-01")

pd_from_csv classmethod

pd_from_csv(path, date_col='index', past=True, **kwargs)

Create an OracleDataFrame from a CSV file inheriting all the methods and attributes of a Pandas DataFrame.

PARAMETER DESCRIPTION
path

The path to the CSV file.

TYPE: str

date_col

The name of the column containing dates. Defaults to the index.

DEFAULT: 'index'

past

If True, the OracleDataFrame will return only the data before the current date. If False, it will return only the data after the current date.

TYPE: bool DEFAULT: True

kwargs

Additional keyword arguments to pass to `pd.read

DEFAULT: {}

RETURNS DESCRIPTION
OracleDataFrame

The OracleDataFrame created from the CSV file.

pl_from_csv classmethod

pl_from_csv(path, date_col='index', past=True, **kwargs)

Create an OracleDataFrame from a CSV file inheriting all the methods and attributes of a Polars DataFrame.

PARAMETER DESCRIPTION
path

The path to the CSV file.

TYPE: str

date_col

The name of the column containing dates. Defaults to the index.

DEFAULT: 'index'

past

If True, the OracleDataFrame will return only the data before the current date. If False, it will return only the data after the current date.

TYPE: bool DEFAULT: True

kwargs

Additional keyword arguments to pass to `pl.read

DEFAULT: {}

RETURNS DESCRIPTION
OracleDataFrame

The OracleDataFrame created from the CSV file.