code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def retrieve_all(self, sids, default_none=False):
"""
Retrieve all assets in `sids`.
Parameters
----------
sids : iterable of int
Assets to retrieve.
default_none : bool
If True, return None for failed lookups.
If False, raise `SidsNot... |
Retrieve all assets in `sids`.
Parameters
----------
sids : iterable of int
Assets to retrieve.
default_none : bool
If True, return None for failed lookups.
If False, raise `SidsNotFound`.
Returns
-------
assets : lis... | retrieve_all | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def _select_most_recent_symbols_chunk(self, sid_group):
"""Retrieve the most recent symbol for a set of sids.
Parameters
----------
sid_group : iterable[int]
The sids to lookup. The length of this sequence must be less than
or equal to SQLITE_MAX_VARIABLE_NUMBER ... | Retrieve the most recent symbol for a set of sids.
Parameters
----------
sid_group : iterable[int]
The sids to lookup. The length of this sequence must be less than
or equal to SQLITE_MAX_VARIABLE_NUMBER because the sids will be
passed in as sql bind params.
... | _select_most_recent_symbols_chunk | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def _retrieve_assets(self, sids, asset_tbl, asset_type):
"""
Internal function for loading assets from a table.
This should be the only method of `AssetFinder` that writes Assets into
self._asset_cache.
Parameters
---------
sids : iterable of int
Ass... |
Internal function for loading assets from a table.
This should be the only method of `AssetFinder` that writes Assets into
self._asset_cache.
Parameters
---------
sids : iterable of int
Asset ids to look up.
asset_tbl : sqlalchemy.Table
... | _retrieve_assets | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def _lookup_symbol_strict(self,
ownership_map,
multi_country,
symbol,
as_of_date):
"""
Resolve a symbol to an asset object without fuzzy matching.
Parameters
---------... |
Resolve a symbol to an asset object without fuzzy matching.
Parameters
----------
ownership_map : dict[(str, str), list[OwnershipPeriod]]
The mapping from split symbols to ownership periods.
multi_country : bool
Does this mapping span multiple countries?... | _lookup_symbol_strict | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def lookup_future_symbol(self, symbol):
"""Lookup a future contract by symbol.
Parameters
----------
symbol : str
The symbol of the desired contract.
Returns
-------
future : Future
The future contract referenced by ``symbol``.
R... | Lookup a future contract by symbol.
Parameters
----------
symbol : str
The symbol of the desired contract.
Returns
-------
future : Future
The future contract referenced by ``symbol``.
Raises
------
SymbolNotFound
... | lookup_future_symbol | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def get_supplementary_field(self, sid, field_name, as_of_date):
"""Get the value of a supplementary field for an asset.
Parameters
----------
sid : int
The sid of the asset to query.
field_name : str
Name of the supplementary field.
as_of_date : p... | Get the value of a supplementary field for an asset.
Parameters
----------
sid : int
The sid of the asset to query.
field_name : str
Name of the supplementary field.
as_of_date : pd.Timestamp, None
The last known value on this date is returned... | get_supplementary_field | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def _lookup_generic_scalar(self,
obj,
as_of_date,
country_code,
matches,
missing):
"""
Convert asset_convertible to an asset.
On success, ap... |
Convert asset_convertible to an asset.
On success, append to matches.
On failure, append to missing.
| _lookup_generic_scalar | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def lookup_generic(self, obj, as_of_date, country_code):
"""
Convert an object into an Asset or sequence of Assets.
This method exists primarily as a convenience for implementing
user-facing APIs that can handle multiple kinds of input. It should
not be used for internal code w... |
Convert an object into an Asset or sequence of Assets.
This method exists primarily as a convenience for implementing
user-facing APIs that can handle multiple kinds of input. It should
not be used for internal code where we already know the expected types
of our inputs.
... | lookup_generic | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def _compute_asset_lifetimes(self, country_codes):
"""
Compute and cache a recarray of asset lifetimes.
"""
sids = starts = ends = []
equities_cols = self.equities.c
if country_codes:
results = sa.select((
equities_cols.sid,
equ... |
Compute and cache a recarray of asset lifetimes.
| _compute_asset_lifetimes | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def lifetimes(self, dates, include_start_date, country_codes):
"""
Compute a DataFrame representing asset lifetimes for the specified date
range.
Parameters
----------
dates : pd.DatetimeIndex
The dates for which to compute lifetimes.
include_start_da... |
Compute a DataFrame representing asset lifetimes for the specified date
range.
Parameters
----------
dates : pd.DatetimeIndex
The dates for which to compute lifetimes.
include_start_date : bool
Whether or not to count the asset as alive on its st... | lifetimes | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def was_active(reference_date_value, asset):
"""
Whether or not `asset` was active at the time corresponding to
`reference_date_value`.
Parameters
----------
reference_date_value : int
Date, represented as nanoseconds since EPOCH, for which we want to know
if `asset` was alive. ... |
Whether or not `asset` was active at the time corresponding to
`reference_date_value`.
Parameters
----------
reference_date_value : int
Date, represented as nanoseconds since EPOCH, for which we want to know
if `asset` was alive. This is generally the result of accessing the
... | was_active | python | quantopian/zipline | zipline/assets/assets.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/assets.py | Apache-2.0 |
def alter_columns(op, name, *columns, **kwargs):
"""Alter columns from a table.
Parameters
----------
name : str
The name of the table.
*columns
The new columns to have.
selection_string : str, optional
The string to use in the selection. If not provided, it will select ... | Alter columns from a table.
Parameters
----------
name : str
The name of the table.
*columns
The new columns to have.
selection_string : str, optional
The string to use in the selection. If not provided, it will select all
of the new columns from the old table.
... | alter_columns | python | quantopian/zipline | zipline/assets/asset_db_migrations.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_db_migrations.py | Apache-2.0 |
def downgrade(engine, desired_version):
"""Downgrades the assets db at the given engine to the desired version.
Parameters
----------
engine : Engine
An SQLAlchemy engine to the assets database.
desired_version : int
The desired resulting version for the assets database.
"""
... | Downgrades the assets db at the given engine to the desired version.
Parameters
----------
engine : Engine
An SQLAlchemy engine to the assets database.
desired_version : int
The desired resulting version for the assets database.
| downgrade | python | quantopian/zipline | zipline/assets/asset_db_migrations.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_db_migrations.py | Apache-2.0 |
def downgrades(src):
"""Decorator for marking that a method is a downgrade to a version to the
previous version.
Parameters
----------
src : int
The version this downgrades from.
Returns
-------
decorator : callable[(callable) -> callable]
The decorator to apply.
""... | Decorator for marking that a method is a downgrade to a version to the
previous version.
Parameters
----------
src : int
The version this downgrades from.
Returns
-------
decorator : callable[(callable) -> callable]
The decorator to apply.
| downgrades | python | quantopian/zipline | zipline/assets/asset_db_migrations.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_db_migrations.py | Apache-2.0 |
def _downgrade_v1(op):
"""
Downgrade assets db by removing the 'tick_size' column and renaming the
'multiplier' column.
"""
# Drop indices before batch
# This is to prevent index collision when creating the temp table
op.drop_index('ix_futures_contracts_root_symbol')
op.drop_index('ix_fu... |
Downgrade assets db by removing the 'tick_size' column and renaming the
'multiplier' column.
| _downgrade_v1 | python | quantopian/zipline | zipline/assets/asset_db_migrations.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_db_migrations.py | Apache-2.0 |
def _downgrade_v2(op):
"""
Downgrade assets db by removing the 'auto_close_date' column.
"""
# Drop indices before batch
# This is to prevent index collision when creating the temp table
op.drop_index('ix_equities_fuzzy_symbol')
op.drop_index('ix_equities_company_symbol')
# Execute batc... |
Downgrade assets db by removing the 'auto_close_date' column.
| _downgrade_v2 | python | quantopian/zipline | zipline/assets/asset_db_migrations.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_db_migrations.py | Apache-2.0 |
def _downgrade_v3(op):
"""
Downgrade assets db by adding a not null constraint on
``equities.first_traded``
"""
op.create_table(
'_new_equities',
sa.Column(
'sid',
sa.Integer,
unique=True,
nullable=False,
primary_key=True,
... |
Downgrade assets db by adding a not null constraint on
``equities.first_traded``
| _downgrade_v3 | python | quantopian/zipline | zipline/assets/asset_db_migrations.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_db_migrations.py | Apache-2.0 |
def _downgrade_v4(op):
"""
Downgrades assets db by copying the `exchange_full` column to `exchange`,
then dropping the `exchange_full` column.
"""
op.drop_index('ix_equities_fuzzy_symbol')
op.drop_index('ix_equities_company_symbol')
op.execute("UPDATE equities SET exchange = exchange_full")... |
Downgrades assets db by copying the `exchange_full` column to `exchange`,
then dropping the `exchange_full` column.
| _downgrade_v4 | python | quantopian/zipline | zipline/assets/asset_db_migrations.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_db_migrations.py | Apache-2.0 |
def _normalize_index_columns_in_place(equities,
equity_supplementary_mappings,
futures,
exchanges,
root_symbols):
"""
Update dataframes in place to set indentif... |
Update dataframes in place to set indentifier columns as indices.
For each input frame, if the frame has a column with the same name as its
associated index column, set that column as the index.
Otherwise, assume the index already contains identifiers.
If frames are passed as None, they're ignor... | _normalize_index_columns_in_place | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def _generate_output_dataframe(data_subset, defaults):
"""
Generates an output dataframe from the given subset of user-provided
data, the given column names, and the given default values.
Parameters
----------
data_subset : DataFrame
A DataFrame, usually from an AssetData object,
... |
Generates an output dataframe from the given subset of user-provided
data, the given column names, and the given default values.
Parameters
----------
data_subset : DataFrame
A DataFrame, usually from an AssetData object,
that contains the user's input metadata for the asset type b... | _generate_output_dataframe | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def _check_symbol_mappings(df, exchanges, asset_exchange):
"""Check that there are no cases where multiple symbols resolve to the same
asset at the same time in the same country.
Parameters
----------
df : pd.DataFrame
The equity symbol mappings table.
exchanges : pd.DataFrame
T... | Check that there are no cases where multiple symbols resolve to the same
asset at the same time in the same country.
Parameters
----------
df : pd.DataFrame
The equity symbol mappings table.
exchanges : pd.DataFrame
The exchanges table.
asset_exchange : pd.Series
A serie... | _check_symbol_mappings | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def _split_symbol_mappings(df, exchanges):
"""Split out the symbol: sid mappings from the raw data.
Parameters
----------
df : pd.DataFrame
The dataframe with multiple rows for each symbol: sid pair.
exchanges : pd.DataFrame
The exchanges table.
Returns
-------
asset_in... | Split out the symbol: sid mappings from the raw data.
Parameters
----------
df : pd.DataFrame
The dataframe with multiple rows for each symbol: sid pair.
exchanges : pd.DataFrame
The exchanges table.
Returns
-------
asset_info : pd.DataFrame
The asset info with one ... | _split_symbol_mappings | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def _dt_to_epoch_ns(dt_series):
"""Convert a timeseries into an Int64Index of nanoseconds since the epoch.
Parameters
----------
dt_series : pd.Series
The timeseries to convert.
Returns
-------
idx : pd.Int64Index
The index converted to nanoseconds since the epoch.
"""
... | Convert a timeseries into an Int64Index of nanoseconds since the epoch.
Parameters
----------
dt_series : pd.Series
The timeseries to convert.
Returns
-------
idx : pd.Int64Index
The index converted to nanoseconds since the epoch.
| _dt_to_epoch_ns | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def check_version_info(conn, version_table, expected_version):
"""
Checks for a version value in the version table.
Parameters
----------
conn : sa.Connection
The connection to use to perform the check.
version_table : sa.Table
The version table of the asset database
expecte... |
Checks for a version value in the version table.
Parameters
----------
conn : sa.Connection
The connection to use to perform the check.
version_table : sa.Table
The version table of the asset database
expected_version : int
The expected version of the asset database
... | check_version_info | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def write_direct(self,
equities=None,
equity_symbol_mappings=None,
equity_supplementary_mappings=None,
futures=None,
exchanges=None,
root_symbols=None,
chunk_size=DEFAULT_CH... | Write asset metadata to a sqlite database in the format that it is
stored in the assets db.
Parameters
----------
equities : pd.DataFrame, optional
The equity metadata. The columns for this dataframe are:
symbol : str
The ticker symbol for th... | write_direct | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def write(self,
equities=None,
futures=None,
exchanges=None,
root_symbols=None,
equity_supplementary_mappings=None,
chunk_size=DEFAULT_CHUNK_SIZE):
"""Write asset metadata to a sqlite database.
Parameters
------... | Write asset metadata to a sqlite database.
Parameters
----------
equities : pd.DataFrame, optional
The equity metadata. The columns for this dataframe are:
symbol : str
The ticker symbol for this equity.
asset_name : str
... | write | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def _all_tables_present(self, txn):
"""
Checks if any tables are present in the current assets database.
Parameters
----------
txn : Transaction
The open transaction to check in.
Returns
-------
has_tables : bool
True if any table... |
Checks if any tables are present in the current assets database.
Parameters
----------
txn : Transaction
The open transaction to check in.
Returns
-------
has_tables : bool
True if any tables are present, otherwise False.
| _all_tables_present | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def init_db(self, txn=None):
"""Connect to database and create tables.
Parameters
----------
txn : sa.engine.Connection, optional
The transaction to execute in. If this is not provided, a new
transaction will be started with the engine provided.
Returns
... | Connect to database and create tables.
Parameters
----------
txn : sa.engine.Connection, optional
The transaction to execute in. If this is not provided, a new
transaction will be started with the engine provided.
Returns
-------
metadata : sa.Me... | init_db | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def _load_data(self,
equities,
futures,
exchanges,
root_symbols,
equity_supplementary_mappings):
"""
Returns a standard set of pandas.DataFrames:
equities, futures, exchanges, root_symbols
"""
... |
Returns a standard set of pandas.DataFrames:
equities, futures, exchanges, root_symbols
| _load_data | python | quantopian/zipline | zipline/assets/asset_writer.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/asset_writer.py | Apache-2.0 |
def _get_active_contract_at_offset(self, root_symbol, dt, offset):
"""
For the given root symbol, find the contract that is considered active
on a specific date at a specific offset.
"""
oc = self.asset_finder.get_ordered_contracts(root_symbol)
session = self.trading_cale... |
For the given root symbol, find the contract that is considered active
on a specific date at a specific offset.
| _get_active_contract_at_offset | python | quantopian/zipline | zipline/assets/roll_finder.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/roll_finder.py | Apache-2.0 |
def get_rolls(self, root_symbol, start, end, offset):
"""
Get the rolls, i.e. the session at which to hop from contract to
contract in the chain.
Parameters
----------
root_symbol : str
The root symbol for which to calculate rolls.
start : Timestamp
... |
Get the rolls, i.e. the session at which to hop from contract to
contract in the chain.
Parameters
----------
root_symbol : str
The root symbol for which to calculate rolls.
start : Timestamp
Start of the date range.
end : Timestamp
... | get_rolls | python | quantopian/zipline | zipline/assets/roll_finder.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/roll_finder.py | Apache-2.0 |
def _active_contract(self, oc, front, back, dt):
r"""
Return the active contract based on the previous trading day's volume.
In the rare case that a double volume switch occurs we treat the first
switch as the roll. Take the following case for example:
| +++++ _____... |
Return the active contract based on the previous trading day's volume.
In the rare case that a double volume switch occurs we treat the first
switch as the roll. Take the following case for example:
| +++++ _____
| + __ / <--- 'G'
| ... | _active_contract | python | quantopian/zipline | zipline/assets/roll_finder.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/roll_finder.py | Apache-2.0 |
def get_contract_center(self, root_symbol, dt, offset):
"""
Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset ... |
Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset from the primary contract.
0 is the primary, 1 is the s... | get_contract_center | python | quantopian/zipline | zipline/assets/roll_finder.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/roll_finder.py | Apache-2.0 |
def make_rotating_equity_info(num_assets,
first_start,
frequency,
periods_between_starts,
asset_lifetime,
exchange='TEST'):
"""
Create a DataFrame representing li... |
Create a DataFrame representing lifetimes of assets that are constantly
rotating in and out of existence.
Parameters
----------
num_assets : int
How many assets to create.
first_start : pd.Timestamp
The start date for the first asset.
frequency : str or pd.tseries.offsets.O... | make_rotating_equity_info | python | quantopian/zipline | zipline/assets/synthetic.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/synthetic.py | Apache-2.0 |
def make_simple_equity_info(sids,
start_date,
end_date,
symbols=None,
names=None,
exchange='TEST'):
"""
Create a DataFrame representing assets that exist for the full durat... |
Create a DataFrame representing assets that exist for the full duration
between `start_date` and `end_date`.
Parameters
----------
sids : array-like of int
start_date : pd.Timestamp, optional
end_date : pd.Timestamp, optional
symbols : list, optional
Symbols to use for the asse... | make_simple_equity_info | python | quantopian/zipline | zipline/assets/synthetic.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/synthetic.py | Apache-2.0 |
def make_simple_multi_country_equity_info(countries_to_sids,
countries_to_exchanges,
start_date,
end_date):
"""Create a DataFrame representing assets that exist for the full duration
bet... | Create a DataFrame representing assets that exist for the full duration
between `start_date` and `end_date`, from multiple countries.
| make_simple_multi_country_equity_info | python | quantopian/zipline | zipline/assets/synthetic.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/synthetic.py | Apache-2.0 |
def make_jagged_equity_info(num_assets,
start_date,
first_end,
frequency,
periods_between_ends,
auto_close_delta):
"""
Create a DataFrame representing assets that all begin... |
Create a DataFrame representing assets that all begin at the same start
date, but have cascading end dates.
Parameters
----------
num_assets : int
How many assets to create.
start_date : pd.Timestamp
The start date for all the assets.
first_end : pd.Timestamp
The da... | make_jagged_equity_info | python | quantopian/zipline | zipline/assets/synthetic.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/synthetic.py | Apache-2.0 |
def make_future_info(first_sid,
root_symbols,
years,
notice_date_func,
expiration_date_func,
start_date_func,
month_codes=None,
multiplier=500):
"""
Create a DataFra... |
Create a DataFrame representing futures for `root_symbols` during `year`.
Generates a contract per triple of (symbol, year, month) supplied to
`root_symbols`, `years`, and `month_codes`.
Parameters
----------
first_sid : int
The first sid to use for assigning sids to the created contr... | make_future_info | python | quantopian/zipline | zipline/assets/synthetic.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/synthetic.py | Apache-2.0 |
def make_commodity_future_info(first_sid,
root_symbols,
years,
month_codes=None,
multiplier=500):
"""
Make futures testing data that simulates the notice/expiration date
behavior of ph... |
Make futures testing data that simulates the notice/expiration date
behavior of physical commodities like oil.
Parameters
----------
first_sid : int
The first sid to use for assigning sids to the created contracts.
root_symbols : list[str]
A list of root symbols for which to cr... | make_commodity_future_info | python | quantopian/zipline | zipline/assets/synthetic.py | https://github.com/quantopian/zipline/blob/master/zipline/assets/synthetic.py | Apache-2.0 |
def load_adjustments(self,
dates,
assets,
should_include_splits,
should_include_mergers,
should_include_dividends,
adjustment_type):
"""
Load collection o... |
Load collection of Adjustment objects from underlying adjustments db.
Parameters
----------
dates : pd.DatetimeIndex
Dates for which adjustments are needed.
assets : pd.Int64Index
Assets for which adjustments are needed.
should_include_splits : b... | load_adjustments | python | quantopian/zipline | zipline/data/adjustments.py | https://github.com/quantopian/zipline/blob/master/zipline/data/adjustments.py | Apache-2.0 |
def unpack_db_to_component_dfs(self, convert_dates=False):
"""Returns the set of known tables in the adjustments file in DataFrame
form.
Parameters
----------
convert_dates : bool, optional
By default, dates are returned in seconds since EPOCH. If
convert... | Returns the set of known tables in the adjustments file in DataFrame
form.
Parameters
----------
convert_dates : bool, optional
By default, dates are returned in seconds since EPOCH. If
convert_dates is True, all ints in date columns will be converted
... | unpack_db_to_component_dfs | python | quantopian/zipline | zipline/data/adjustments.py | https://github.com/quantopian/zipline/blob/master/zipline/data/adjustments.py | Apache-2.0 |
def _df_dtypes(self, table_name, convert_dates):
"""Get dtypes to use when unpacking sqlite tables as dataframes.
"""
out = self._raw_table_dtypes[table_name]
if convert_dates:
out = out.copy()
for date_column in self._datetime_int_cols[table_name]:
... | Get dtypes to use when unpacking sqlite tables as dataframes.
| _df_dtypes | python | quantopian/zipline | zipline/data/adjustments.py | https://github.com/quantopian/zipline/blob/master/zipline/data/adjustments.py | Apache-2.0 |
def write_dividend_payouts(self, frame):
"""
Write dividend payout data to SQLite table `dividend_payouts`.
"""
return self._write(
'dividend_payouts',
SQLITE_DIVIDEND_PAYOUT_COLUMN_DTYPES,
frame,
) |
Write dividend payout data to SQLite table `dividend_payouts`.
| write_dividend_payouts | python | quantopian/zipline | zipline/data/adjustments.py | https://github.com/quantopian/zipline/blob/master/zipline/data/adjustments.py | Apache-2.0 |
def calc_dividend_ratios(self, dividends):
"""
Calculate the ratios to apply to equities when looking back at pricing
history so that the price is smoothed over the ex_date, when the market
adjusts to the change in equity value due to upcoming dividend.
Returns
-------
... |
Calculate the ratios to apply to equities when looking back at pricing
history so that the price is smoothed over the ex_date, when the market
adjusts to the change in equity value due to upcoming dividend.
Returns
-------
DataFrame
A frame in the same forma... | calc_dividend_ratios | python | quantopian/zipline | zipline/data/adjustments.py | https://github.com/quantopian/zipline/blob/master/zipline/data/adjustments.py | Apache-2.0 |
def write_dividend_data(self, dividends, stock_dividends=None):
"""
Write both dividend payouts and the derived price adjustment ratios.
"""
# First write the dividend payouts.
self._write_dividends(dividends)
self._write_stock_dividends(stock_dividends)
# Secon... |
Write both dividend payouts and the derived price adjustment ratios.
| write_dividend_data | python | quantopian/zipline | zipline/data/adjustments.py | https://github.com/quantopian/zipline/blob/master/zipline/data/adjustments.py | Apache-2.0 |
def write(self,
splits=None,
mergers=None,
dividends=None,
stock_dividends=None):
"""
Writes data to a SQLite file to be read by SQLiteAdjustmentReader.
Parameters
----------
splits : pandas.DataFrame, optional
... |
Writes data to a SQLite file to be read by SQLiteAdjustmentReader.
Parameters
----------
splits : pandas.DataFrame, optional
Dataframe containing split data. The format of this dataframe is:
effective_date : int
The date, represented as secon... | write | python | quantopian/zipline | zipline/data/adjustments.py | https://github.com/quantopian/zipline/blob/master/zipline/data/adjustments.py | Apache-2.0 |
def winsorise_uint32(df, invalid_data_behavior, column, *columns):
"""Drops any record where a value would not fit into a uint32.
Parameters
----------
df : pd.DataFrame
The dataframe to winsorise.
invalid_data_behavior : {'warn', 'raise', 'ignore'}
What to do when data is outside t... | Drops any record where a value would not fit into a uint32.
Parameters
----------
df : pd.DataFrame
The dataframe to winsorise.
invalid_data_behavior : {'warn', 'raise', 'ignore'}
What to do when data is outside the bounds of a uint32.
*columns : iterable[str]
The names of t... | winsorise_uint32 | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def write(self,
data,
assets=None,
show_progress=False,
invalid_data_behavior='warn'):
"""
Parameters
----------
data : iterable[tuple[int, pandas.DataFrame or bcolz.ctable]]
The data chunks to write. Each chunk should b... |
Parameters
----------
data : iterable[tuple[int, pandas.DataFrame or bcolz.ctable]]
The data chunks to write. Each chunk should be a tuple of sid
and the data for that asset.
assets : set[int], optional
The assets that should be in ``data``. If this i... | write | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def write_csvs(self,
asset_map,
show_progress=False,
invalid_data_behavior='warn'):
"""Read CSVs as DataFrames from our asset map.
Parameters
----------
asset_map : dict[int -> str]
A mapping from asset id to file path... | Read CSVs as DataFrames from our asset map.
Parameters
----------
asset_map : dict[int -> str]
A mapping from asset id to file path with the CSV data for that
asset
show_progress : bool
Whether or not to show a progress bar while writing.
inva... | write_csvs | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def _write_internal(self, iterator, assets):
"""
Internal implementation of write.
`iterator` should be an iterator yielding pairs of (asset, ctable).
"""
total_rows = 0
first_row = {}
last_row = {}
calendar_offset = {}
# Maps column name -> outp... |
Internal implementation of write.
`iterator` should be an iterator yielding pairs of (asset, ctable).
| _write_internal | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def _compute_slices(self, start_idx, end_idx, assets):
"""
Compute the raw row indices to load for each asset on a query for the
given dates after applying a shift.
Parameters
----------
start_idx : int
Index of first date for which we want data.
end_... |
Compute the raw row indices to load for each asset on a query for the
given dates after applying a shift.
Parameters
----------
start_idx : int
Index of first date for which we want data.
end_idx : int
Index of last date for which we want data.
... | _compute_slices | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def _spot_col(self, colname):
"""
Get the colname from daily_bar_table and read all of it into memory,
caching the result.
Parameters
----------
colname : string
A name of a OHLCV carray in the daily_bar_table
Returns
-------
array (u... |
Get the colname from daily_bar_table and read all of it into memory,
caching the result.
Parameters
----------
colname : string
A name of a OHLCV carray in the daily_bar_table
Returns
-------
array (uint32)
Full read array of the... | _spot_col | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def sid_day_index(self, sid, day):
"""
Parameters
----------
sid : int
The asset identifier.
day : datetime64-like
Midnight of the day for which data is requested.
Returns
-------
int
Index into the data tape for the gi... |
Parameters
----------
sid : int
The asset identifier.
day : datetime64-like
Midnight of the day for which data is requested.
Returns
-------
int
Index into the data tape for the given sid and day.
Raises a NoDataOn... | sid_day_index | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def get_value(self, sid, dt, field):
"""
Parameters
----------
sid : int
The asset identifier.
day : datetime64-like
Midnight of the day for which data is requested.
colname : string
The price field. e.g. ('open', 'high', 'low', 'close'... |
Parameters
----------
sid : int
The asset identifier.
day : datetime64-like
Midnight of the day for which data is requested.
colname : string
The price field. e.g. ('open', 'high', 'low', 'close', 'volume')
Returns
-------
... | get_value | python | quantopian/zipline | zipline/data/bcolz_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/bcolz_daily_bars.py | Apache-2.0 |
def get_benchmark_returns_from_file(filelike):
"""
Get a Series of benchmark returns from a file
Parameters
----------
filelike : str or file-like object
Path to the benchmark file.
expected csv file format:
date,return
2020-01-02 00:00:00+00:00,0.01
2020-01-... |
Get a Series of benchmark returns from a file
Parameters
----------
filelike : str or file-like object
Path to the benchmark file.
expected csv file format:
date,return
2020-01-02 00:00:00+00:00,0.01
2020-01-03 00:00:00+00:00,-0.02
| get_benchmark_returns_from_file | python | quantopian/zipline | zipline/data/benchmarks.py | https://github.com/quantopian/zipline/blob/master/zipline/data/benchmarks.py | Apache-2.0 |
def load_raw_arrays(self, columns, start_date, end_date, assets):
"""
Parameters
----------
fields : list of str
'sid'
start_dt: Timestamp
Beginning of the window range.
end_dt: Timestamp
End of the window range.
sids : list of in... |
Parameters
----------
fields : list of str
'sid'
start_dt: Timestamp
Beginning of the window range.
end_dt: Timestamp
End of the window range.
sids : list of int
The asset identifiers in the window.
Returns
--... | load_raw_arrays | python | quantopian/zipline | zipline/data/continuous_future_reader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/continuous_future_reader.py | Apache-2.0 |
def get_value(self, continuous_future, dt, field):
"""
Retrieve the value at the given coordinates.
Parameters
----------
sid : int
The asset identifier.
dt : pd.Timestamp
The timestamp for the desired data point.
field : string
... |
Retrieve the value at the given coordinates.
Parameters
----------
sid : int
The asset identifier.
dt : pd.Timestamp
The timestamp for the desired data point.
field : string
The OHLVC name for the desired data point.
Returns
... | get_value | python | quantopian/zipline | zipline/data/continuous_future_reader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/continuous_future_reader.py | Apache-2.0 |
def get_last_traded_dt(self, asset, dt):
"""
Get the latest minute on or before ``dt`` in which ``asset`` traded.
If there are no trades on or before ``dt``, returns ``pd.NaT``.
Parameters
----------
asset : zipline.asset.Asset
The asset for which to get the... |
Get the latest minute on or before ``dt`` in which ``asset`` traded.
If there are no trades on or before ``dt``, returns ``pd.NaT``.
Parameters
----------
asset : zipline.asset.Asset
The asset for which to get the last traded minute.
dt : pd.Timestamp
... | get_last_traded_dt | python | quantopian/zipline | zipline/data/continuous_future_reader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/continuous_future_reader.py | Apache-2.0 |
def load_raw_arrays(self, columns, start_date, end_date, assets):
"""
Parameters
----------
fields : list of str
'open', 'high', 'low', 'close', or 'volume'
start_dt: Timestamp
Beginning of the window range.
end_dt: Timestamp
End of the wi... |
Parameters
----------
fields : list of str
'open', 'high', 'low', 'close', or 'volume'
start_dt: Timestamp
Beginning of the window range.
end_dt: Timestamp
End of the window range.
sids : list of int
The asset identifiers in th... | load_raw_arrays | python | quantopian/zipline | zipline/data/continuous_future_reader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/continuous_future_reader.py | Apache-2.0 |
def handle_extra_source(self, source_df, sim_params):
"""
Extra sources always have a sid column.
We expand the given data (by forward filling) to the full range of
the simulation dates, so that lookup is fast during simulation.
"""
if source_df is None:
retu... |
Extra sources always have a sid column.
We expand the given data (by forward filling) to the full range of
the simulation dates, so that lookup is fast during simulation.
| handle_extra_source | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def _is_extra_source(asset, field, map):
"""
Internal method that determines if this asset/field combination
represents a fetcher value or a regular OHLCVP lookup.
"""
# If we have an extra source with a column called "price", only look
# at it if it's on something like p... |
Internal method that determines if this asset/field combination
represents a fetcher value or a regular OHLCVP lookup.
| _is_extra_source | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_spot_value(self, assets, field, dt, data_frequency):
"""
Public API method that returns a scalar value representing the value
of the desired asset's field at either the given dt.
Parameters
----------
assets : Asset, ContinuousFuture, or iterable of same.
... |
Public API method that returns a scalar value representing the value
of the desired asset's field at either the given dt.
Parameters
----------
assets : Asset, ContinuousFuture, or iterable of same.
The asset or assets whose data is desired.
field : {'open',... | get_spot_value | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_scalar_asset_spot_value(self, asset, field, dt, data_frequency):
"""
Public API method that returns a scalar value representing the value
of the desired asset's field at either the given dt.
Parameters
----------
assets : Asset
The asset or assets who... |
Public API method that returns a scalar value representing the value
of the desired asset's field at either the given dt.
Parameters
----------
assets : Asset
The asset or assets whose data is desired. This cannot be
an arbitrary AssetConvertible.
... | get_scalar_asset_spot_value | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_adjustments(self, assets, field, dt, perspective_dt):
"""
Returns a list of adjustments between the dt and perspective_dt for the
given field and list of assets
Parameters
----------
assets : list of type Asset, or Asset
The asset, or assets whose adj... |
Returns a list of adjustments between the dt and perspective_dt for the
given field and list of assets
Parameters
----------
assets : list of type Asset, or Asset
The asset, or assets whose adjustments are desired.
field : {'open', 'high', 'low', 'close', 'v... | get_adjustments | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_adjusted_value(self, asset, field, dt,
perspective_dt,
data_frequency,
spot_value=None):
"""
Returns a scalar value representing the value
of the desired asset's field at the given dt with adjustments applie... |
Returns a scalar value representing the value
of the desired asset's field at the given dt with adjustments applied.
Parameters
----------
asset : Asset
The asset whose data is desired.
field : {'open', 'high', 'low', 'close', 'volume', 'pri... | get_adjusted_value | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def _get_history_daily_window(self,
assets,
end_dt,
bar_count,
field_to_use,
data_frequency):
"""
Internal method that returns a dataf... |
Internal method that returns a dataframe containing history bars
of daily frequency for the given sids.
| _get_history_daily_window | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def _get_history_minute_window(self, assets, end_dt, bar_count,
field_to_use):
"""
Internal method that returns a dataframe containing history bars
of minute frequency for the given sids.
"""
# get all the minutes for this window
try:
... |
Internal method that returns a dataframe containing history bars
of minute frequency for the given sids.
| _get_history_minute_window | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_history_window(self,
assets,
end_dt,
bar_count,
frequency,
field,
data_frequency,
ffill=True):
"""
Public A... |
Public API method that returns a dataframe containing the requested
history window. Data is fully adjusted.
Parameters
----------
assets : list of zipline.data.Asset objects
The assets whose data is desired.
bar_count: int
The number of bars de... | get_history_window | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def _get_minute_window_data(self, assets, field, minutes_for_window):
"""
Internal method that gets a window of adjusted minute data for an asset
and specified date range. Used to support the history API method for
minute bars.
Missing bars are filled with NaN.
Paramet... |
Internal method that gets a window of adjusted minute data for an asset
and specified date range. Used to support the history API method for
minute bars.
Missing bars are filled with NaN.
Parameters
----------
assets : iterable[Asset]
The assets wh... | _get_minute_window_data | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def _get_daily_window_data(self,
assets,
field,
days_in_window,
extra_slot=True):
"""
Internal method that gets a window of adjusted daily data for a sid
and specified date... |
Internal method that gets a window of adjusted daily data for a sid
and specified date range. Used to support the history API method for
daily bars.
Parameters
----------
asset : Asset
The asset whose data is desired.
start_dt: pandas.Timestamp
... | _get_daily_window_data | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def _get_adjustment_list(self, asset, adjustments_dict, table_name):
"""
Internal method that returns a list of adjustments for the given sid.
Parameters
----------
asset : Asset
The asset for which to return adjustments.
adjustments_dict: dict
A... |
Internal method that returns a list of adjustments for the given sid.
Parameters
----------
asset : Asset
The asset for which to return adjustments.
adjustments_dict: dict
A dictionary of sid -> list that is used as a cache.
table_name: string
... | _get_adjustment_list | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_splits(self, assets, dt):
"""
Returns any splits for the given sids and the given dt.
Parameters
----------
assets : container
Assets for which we want splits.
dt : pd.Timestamp
The date for which we are checking for splits. Note: this is
... |
Returns any splits for the given sids and the given dt.
Parameters
----------
assets : container
Assets for which we want splits.
dt : pd.Timestamp
The date for which we are checking for splits. Note: this is
expected to be midnight UTC.
... | get_splits | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_stock_dividends(self, sid, trading_days):
"""
Returns all the stock dividends for a specific sid that occur
in the given trading range.
Parameters
----------
sid: int
The asset whose stock dividends should be returned.
trading_days: pd.Dateti... |
Returns all the stock dividends for a specific sid that occur
in the given trading range.
Parameters
----------
sid: int
The asset whose stock dividends should be returned.
trading_days: pd.DatetimeIndex
The trading range.
Returns
... | get_stock_dividends | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_fetcher_assets(self, dt):
"""
Returns a list of assets for the current date, as defined by the
fetcher data.
Returns
-------
list: a list of Asset objects.
"""
# return a list of assets for the current date, as defined by the
# fetcher sou... |
Returns a list of assets for the current date, as defined by the
fetcher data.
Returns
-------
list: a list of Asset objects.
| get_fetcher_assets | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def get_current_future_chain(self, continuous_future, dt):
"""
Retrieves the future chain for the contract at the given `dt` according
the `continuous_future` specification.
Returns
-------
future_chain : list[Future]
A list of active futures, where the firs... |
Retrieves the future chain for the contract at the given `dt` according
the `continuous_future` specification.
Returns
-------
future_chain : list[Future]
A list of active futures, where the first index is the current
contract specified by the continuou... | get_current_future_chain | python | quantopian/zipline | zipline/data/data_portal.py | https://github.com/quantopian/zipline/blob/master/zipline/data/data_portal.py | Apache-2.0 |
def days_and_sids_for_frames(frames):
"""
Returns the date index and sid columns shared by a list of dataframes,
ensuring they all match.
Parameters
----------
frames : list[pd.DataFrame]
A list of dataframes indexed by day, with a column per sid.
Returns
-------
days : np.... |
Returns the date index and sid columns shared by a list of dataframes,
ensuring they all match.
Parameters
----------
frames : list[pd.DataFrame]
A list of dataframes indexed by day, with a column per sid.
Returns
-------
days : np.array[datetime64[ns]]
The days in the... | days_and_sids_for_frames | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def write(self,
country_code,
frames,
currency_codes=None,
scaling_factors=None):
"""
Write the OHLCV data for one country to the HDF5 file.
Parameters
----------
country_code : str
The ISO 3166 alpha-2 country ... |
Write the OHLCV data for one country to the HDF5 file.
Parameters
----------
country_code : str
The ISO 3166 alpha-2 country code for this country.
frames : dict[str, pd.DataFrame]
A dict mapping each OHLCV field to a dataframe with a row
for... | write | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def write_from_sid_df_pairs(self,
country_code,
data,
currency_codes=None,
scaling_factors=None):
"""
Parameters
----------
country_code : str
The I... |
Parameters
----------
country_code : str
The ISO 3166 alpha-2 country code for this country.
data : iterable[tuple[int, pandas.DataFrame]]
The data chunks to write. Each chunk should be a tuple of
sid and the data for that asset.
currency_code... | write_from_sid_df_pairs | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def compute_asset_lifetimes(frames):
"""
Parameters
----------
frames : dict[str, pd.DataFrame]
A dict mapping each OHLCV field to a dataframe with a row for
each date and a column for each sid, as passed to write().
Returns
-------
start_date_ixs : np.array[int64]
T... |
Parameters
----------
frames : dict[str, pd.DataFrame]
A dict mapping each OHLCV field to a dataframe with a row for
each date and a column for each sid, as passed to write().
Returns
-------
start_date_ixs : np.array[int64]
The index of the first date with non-nan valu... | compute_asset_lifetimes | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def from_file(cls, h5_file, country_code):
"""
Construct from an h5py.File and a country code.
Parameters
----------
h5_file : h5py.File
An HDF5 daily pricing file.
country_code : str
The ISO 3166 alpha-2 country code for the country to read.
... |
Construct from an h5py.File and a country code.
Parameters
----------
h5_file : h5py.File
An HDF5 daily pricing file.
country_code : str
The ISO 3166 alpha-2 country code for the country to read.
| from_file | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def load_raw_arrays(self,
columns,
start_date,
end_date,
assets):
"""
Parameters
----------
columns : list of str
'open', 'high', 'low', 'close', or 'volume'
start_date: Tim... |
Parameters
----------
columns : list of str
'open', 'high', 'low', 'close', or 'volume'
start_date: Timestamp
Beginning of the window range.
end_date: Timestamp
End of the window range.
assets : list of int
The asset identifier... | load_raw_arrays | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def _make_sid_selector(self, assets):
"""
Build an indexer mapping ``self.sids`` to ``assets``.
Parameters
----------
assets : list[int]
List of assets requested by a caller of ``load_raw_arrays``.
Returns
-------
index : np.array[int64]
... |
Build an indexer mapping ``self.sids`` to ``assets``.
Parameters
----------
assets : list[int]
List of assets requested by a caller of ``load_raw_arrays``.
Returns
-------
index : np.array[int64]
Index array containing the index in ``sel... | _make_sid_selector | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def _validate_assets(self, assets):
"""Validate that asset identifiers are contained in the daily bars.
Parameters
----------
assets : array-like[int]
The asset identifiers to validate.
Raises
------
NoDataForSid
If one or more of the prov... | Validate that asset identifiers are contained in the daily bars.
Parameters
----------
assets : array-like[int]
The asset identifiers to validate.
Raises
------
NoDataForSid
If one or more of the provided asset identifiers are not
cont... | _validate_assets | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def currency_codes(self, sids):
"""Get currencies in which prices are quoted for the requested sids.
Parameters
----------
sids : np.array[int64]
Array of sids for which currencies are needed.
Returns
-------
currency_codes : np.array[object]
... | Get currencies in which prices are quoted for the requested sids.
Parameters
----------
sids : np.array[int64]
Array of sids for which currencies are needed.
Returns
-------
currency_codes : np.array[object]
Array of currency codes for listing cu... | currency_codes | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def trading_calendar(self):
"""
Returns the zipline.utils.calendar.trading_calendar used to read
the data. Can be None (if the writer didn't specify it).
"""
raise NotImplementedError(
'HDF5 pricing does not yet support trading calendars.'
) |
Returns the zipline.utils.calendar.trading_calendar used to read
the data. Can be None (if the writer didn't specify it).
| trading_calendar | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def get_last_traded_dt(self, asset, dt):
"""
Get the latest day on or before ``dt`` in which ``asset`` traded.
If there are no trades on or before ``dt``, returns ``pd.NaT``.
Parameters
----------
asset : zipline.asset.Asset
The asset for which to get the la... |
Get the latest day on or before ``dt`` in which ``asset`` traded.
If there are no trades on or before ``dt``, returns ``pd.NaT``.
Parameters
----------
asset : zipline.asset.Asset
The asset for which to get the last traded day.
dt : pd.Timestamp
... | get_last_traded_dt | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def from_file(cls, h5_file):
"""
Construct from an h5py.File.
Parameters
----------
h5_file : h5py.File
An HDF5 daily pricing file.
"""
return cls({
country: HDF5DailyBarReader.from_file(h5_file, country)
for country in h5_file... |
Construct from an h5py.File.
Parameters
----------
h5_file : h5py.File
An HDF5 daily pricing file.
| from_file | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def last_available_dt(self):
"""
Returns
-------
dt : pd.Timestamp
The last session for which the reader can provide data.
"""
return max(
reader.last_available_dt for reader in self._readers.values()
) |
Returns
-------
dt : pd.Timestamp
The last session for which the reader can provide data.
| last_available_dt | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def first_trading_day(self):
"""
Returns
-------
dt : pd.Timestamp
The first trading day (session) for which the reader can provide
data.
"""
return min(
reader.first_trading_day for reader in self._readers.values()
) |
Returns
-------
dt : pd.Timestamp
The first trading day (session) for which the reader can provide
data.
| first_trading_day | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def sessions(self):
"""
Returns
-------
sessions : DatetimeIndex
All session labels (unioning the range for all assets) which the
reader can provide.
"""
return pd.to_datetime(
reduce(
np.union1d,
(reader.d... |
Returns
-------
sessions : DatetimeIndex
All session labels (unioning the range for all assets) which the
reader can provide.
| sessions | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def get_value(self, sid, dt, field):
"""
Retrieve the value at the given coordinates.
Parameters
----------
sid : int
The asset identifier.
dt : pd.Timestamp
The timestamp for the desired data point.
field : string
The OHLVC na... |
Retrieve the value at the given coordinates.
Parameters
----------
sid : int
The asset identifier.
dt : pd.Timestamp
The timestamp for the desired data point.
field : string
The OHLVC name for the desired data point.
Returns
... | get_value | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def check_sids_arrays_match(left, right, message):
"""Check that two 1d arrays of sids are equal
"""
if len(left) != len(right):
raise ValueError(
"{}:\nlen(left) ({}) != len(right) ({})".format(
message, len(left), len(right)
)
)
diff = (left != ... | Check that two 1d arrays of sids are equal
| check_sids_arrays_match | python | quantopian/zipline | zipline/data/hdf5_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/hdf5_daily_bars.py | Apache-2.0 |
def load_pricing_adjustments(self, columns, dts, assets):
"""
Returns
-------
adjustments : list[dict[int -> Adjustment]]
A list, where each element corresponds to the `columns`, of
mappings from index to adjustment objects to apply at that index.
"""
... |
Returns
-------
adjustments : list[dict[int -> Adjustment]]
A list, where each element corresponds to the `columns`, of
mappings from index to adjustment objects to apply at that index.
| load_pricing_adjustments | python | quantopian/zipline | zipline/data/history_loader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/history_loader.py | Apache-2.0 |
def _get_adjustments_in_range(self, asset, dts, field):
"""
Get the Float64Multiply objects to pass to an AdjustedArrayWindow.
For the use of AdjustedArrayWindow in the loader, which looks back
from current simulation time back to a window of data the dictionary is
structured wi... |
Get the Float64Multiply objects to pass to an AdjustedArrayWindow.
For the use of AdjustedArrayWindow in the loader, which looks back
from current simulation time back to a window of data the dictionary is
structured with:
- the key into the dictionary for adjustments is the lo... | _get_adjustments_in_range | python | quantopian/zipline | zipline/data/history_loader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/history_loader.py | Apache-2.0 |
def get(self, end_ix):
"""
Returns
-------
out : A np.ndarray of the equity pricing up to end_ix after adjustments
and rounding have been applied.
"""
if self.most_recent_ix == end_ix:
return self.current
target = end_ix - self.cal_start... |
Returns
-------
out : A np.ndarray of the equity pricing up to end_ix after adjustments
and rounding have been applied.
| get | python | quantopian/zipline | zipline/data/history_loader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/history_loader.py | Apache-2.0 |
def _ensure_sliding_windows(self, assets, dts, field,
is_perspective_after):
"""
Ensure that there is a Float64Multiply window for each asset that can
provide data for the given parameters.
If the corresponding window for the (assets, len(dts), field) does... |
Ensure that there is a Float64Multiply window for each asset that can
provide data for the given parameters.
If the corresponding window for the (assets, len(dts), field) does not
exist, then create a new one.
If a corresponding window does exist for (assets, len(dts), field), b... | _ensure_sliding_windows | python | quantopian/zipline | zipline/data/history_loader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/history_loader.py | Apache-2.0 |
def history(self, assets, dts, field, is_perspective_after):
"""
A window of pricing data with adjustments applied assuming that the
end of the window is the day before the current simulation time.
Parameters
----------
assets : iterable of Assets
The assets ... |
A window of pricing data with adjustments applied assuming that the
end of the window is the day before the current simulation time.
Parameters
----------
assets : iterable of Assets
The assets in the window.
dts : iterable of datetime64-like
The... | history | python | quantopian/zipline | zipline/data/history_loader.py | https://github.com/quantopian/zipline/blob/master/zipline/data/history_loader.py | Apache-2.0 |
def get_last_traded_dt(self, asset, dt):
"""
Parameters
----------
asset : zipline.asset.Asset
The asset identifier.
dt : datetime64-like
Midnight of the day for which data is requested.
Returns
-------
pd.Timestamp : The last know... |
Parameters
----------
asset : zipline.asset.Asset
The asset identifier.
dt : datetime64-like
Midnight of the day for which data is requested.
Returns
-------
pd.Timestamp : The last know dt for the asset and dt;
NaT... | get_last_traded_dt | python | quantopian/zipline | zipline/data/in_memory_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/in_memory_daily_bars.py | Apache-2.0 |
def verify_frames_aligned(frames, calendar):
"""
Verify that DataFrames in ``frames`` have the same indexing scheme and are
aligned to ``calendar``.
Parameters
----------
frames : list[pd.DataFrame]
calendar : trading_calendars.TradingCalendar
Raises
------
ValueError
I... |
Verify that DataFrames in ``frames`` have the same indexing scheme and are
aligned to ``calendar``.
Parameters
----------
frames : list[pd.DataFrame]
calendar : trading_calendars.TradingCalendar
Raises
------
ValueError
If frames have different indexes/columns, or if frame... | verify_frames_aligned | python | quantopian/zipline | zipline/data/in_memory_daily_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/in_memory_daily_bars.py | Apache-2.0 |
def convert_cols(cols, scale_factor, sid, invalid_data_behavior):
"""Adapt OHLCV columns into uint32 columns.
Parameters
----------
cols : dict
A dict mapping each column name (open, high, low, close, volume)
to a float column to convert to uint32.
scale_factor : int
Factor ... | Adapt OHLCV columns into uint32 columns.
Parameters
----------
cols : dict
A dict mapping each column name (open, high, low, close, volume)
to a float column to convert to uint32.
scale_factor : int
Factor to use to scale float values before converting to uint32.
sid : int
... | convert_cols | python | quantopian/zipline | zipline/data/minute_bars.py | https://github.com/quantopian/zipline/blob/master/zipline/data/minute_bars.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.