av module¶
Module with AVData.
AVData class¶
AVData(
wrapper,
data,
single_key=True,
classes=None,
level_name=None,
fetch_kwargs=None,
returned_kwargs=None,
last_index=None,
delisted=None,
tz_localize=None,
tz_convert=None,
missing_index=None,
missing_columns=None,
**kwargs
)
Data class for fetching from Alpha Vantage.
See https://www.alphavantage.co/documentation/ for API.
Apart of using https://github.com/RomelTorres/alpha_vantage package, this class can also parse the API documentation with AVData.parse_api_meta() using BeautifulSoup4 and build the API query based on this metadata (pass use_parser=True).
This approach is the most flexible we can get since we can instantly react to Alpha Vantage's changes in the API. If the data provider changes its API documentation, you can always adapt the parsing procedure by overriding AVData.parse_api_meta().
If parser still fails, you can disable parsing entirely and specify all information manually by setting function and disabling match_params
See AVData.fetch_symbol() for arguments.
Usage
- Set up the API key globally (optional):
- Pull data:
>>> data = vbt.AVData.pull(
... "GOOGL",
... timeframe="1 day",
... )
>>> data = vbt.AVData.pull(
... "BTC_USD",
... timeframe="30 minutes", # premium?
... category="digital-currency",
... outputsize="full"
... )
>>> data = vbt.AVData.pull(
... "REAL_GDP",
... category="economic-indicators"
... )
>>> data = vbt.AVData.pull(
... "IBM",
... category="technical-indicators",
... function="STOCHRSI",
... params=dict(fastkperiod=14)
... )
Superclasses
- Analyzable
- AttrResolverMixin
- BaseDataMixin
- Cacheable
- Chainable
- Comparable
- Configured
- CustomData
- Data
- DataWithFeatures
- ExtPandasIndexer
- HasSettings
- IndexApplier
- IndexingBase
- Itemable
- OHLCDataMixin
- PandasIndexer
- Paramable
- Pickleable
- PlotsBuilderMixin
- Prettified
- RemoteData
- StatsBuilderMixin
- Wrapping
Inherited members
- AttrResolverMixin.deep_getattr()
- AttrResolverMixin.post_resolve_attr()
- AttrResolverMixin.pre_resolve_attr()
- AttrResolverMixin.resolve_attr()
- AttrResolverMixin.resolve_shortcut_attr()
- BaseDataMixin.assert_has_feature()
- BaseDataMixin.assert_has_symbol()
- BaseDataMixin.get_feature()
- BaseDataMixin.get_feature_idx()
- BaseDataMixin.get_symbol()
- BaseDataMixin.get_symbol_idx()
- BaseDataMixin.has_feature()
- BaseDataMixin.has_multiple_keys()
- BaseDataMixin.has_symbol()
- BaseDataMixin.prepare_key()
- BaseDataMixin.select_features()
- BaseDataMixin.select_symbols()
- Cacheable.get_ca_setup()
- Chainable.pipe()
- Configured.copy()
- Configured.equals()
- Configured.get_writeable_attrs()
- Configured.prettify()
- Configured.resolve_merge_kwargs()
- Configured.update_config()
- CustomData.get_custom_setting()
- CustomData.get_custom_settings()
- CustomData.has_custom_setting()
- CustomData.has_custom_settings()
- CustomData.key_match()
- CustomData.resolve_custom_setting()
- CustomData.set_custom_settings()
- Data.add()
- Data.add_column()
- Data.add_feature()
- Data.add_key()
- Data.add_symbol()
- Data.align_columns()
- Data.align_data()
- Data.align_index()
- Data.build_feature_config_doc()
- Data.check_dict_type()
- Data.column_stack()
- Data.concat()
- Data.dropna()
- Data.fetch()
- Data.fetch_feature()
- Data.fix_data_dict_type()
- Data.fix_dict_types_in_kwargs()
- Data.from_csv()
- Data.from_data()
- Data.from_data_str()
- Data.from_duckdb()
- Data.from_feather()
- Data.from_hdf()
- Data.from_parquet()
- Data.from_sql()
- Data.get()
- Data.get_base_setting()
- Data.get_base_settings()
- Data.get_feature_wrapper()
- Data.get_intersection_dict()
- Data.get_key_index()
- Data.get_key_wrapper()
- Data.get_keys()
- Data.get_level_name()
- Data.get_symbol_wrapper()
- Data.has_base_setting()
- Data.has_base_settings()
- Data.has_key_dict()
- Data.indexing_func()
- Data.invert()
- Data.invert_data()
- Data.items()
- Data.merge()
- Data.modify_state()
- Data.override_feature_config_doc()
- Data.plot()
- Data.prepare_dt()
- Data.prepare_dt_column()
- Data.prepare_dt_index()
- Data.prepare_tzaware_index()
- Data.pull()
- Data.realign()
- Data.remove()
- Data.remove_columns()
- Data.remove_features()
- Data.remove_keys()
- Data.remove_symbols()
- Data.rename()
- Data.rename_columns()
- Data.rename_features()
- Data.rename_in_dict()
- Data.rename_keys()
- Data.rename_symbols()
- Data.replace()
- Data.resample()
- Data.resolve_base_setting()
- Data.resolve_columns()
- Data.resolve_features()
- Data.resolve_key_arg()
- Data.resolve_keys()
- Data.resolve_keys_meta()
- Data.resolve_symbols()
- Data.row_stack()
- Data.run()
- Data.select()
- Data.select_classes()
- Data.select_columns()
- Data.select_delisted()
- Data.select_feature_from_dict()
- Data.select_feature_idxs()
- Data.select_feature_kwargs()
- Data.select_fetch_kwargs()
- Data.select_from_dict()
- Data.select_key_from_dict()
- Data.select_key_kwargs()
- Data.select_keys()
- Data.select_last_index()
- Data.select_returned_kwargs()
- Data.select_run_func_args()
- Data.select_run_func_kwargs()
- Data.select_symbol_from_dict()
- Data.select_symbol_idxs()
- Data.select_symbol_kwargs()
- Data.set_base_settings()
- Data.sql()
- Data.switch_class()
- Data.to_csv()
- Data.to_duckdb()
- Data.to_feather()
- Data.to_feature_oriented()
- Data.to_hdf()
- Data.to_parquet()
- Data.to_sql()
- Data.to_symbol_oriented()
- Data.transform()
- Data.try_fetch_feature()
- Data.try_fetch_symbol()
- Data.try_run()
- Data.try_update_feature()
- Data.try_update_symbol()
- Data.update()
- Data.update_classes()
- Data.update_feature()
- Data.update_fetch_kwargs()
- Data.update_returned_kwargs()
- Data.update_symbol()
- Data.use_feature_config_of()
- HasSettings.get_path_setting()
- HasSettings.get_path_settings()
- HasSettings.get_setting()
- HasSettings.get_settings()
- HasSettings.has_path_setting()
- HasSettings.has_path_settings()
- HasSettings.has_setting()
- HasSettings.has_settings()
- HasSettings.reset_settings()
- HasSettings.resolve_setting()
- HasSettings.resolve_settings_paths()
- HasSettings.set_settings()
- IndexApplier.add_levels()
- IndexApplier.drop_duplicate_levels()
- IndexApplier.drop_levels()
- IndexApplier.drop_redundant_levels()
- IndexApplier.rename_levels()
- IndexApplier.select_levels()
- IndexingBase.indexing_setter_func()
- OHLCDataMixin.get_daily_log_returns()
- OHLCDataMixin.get_daily_returns()
- OHLCDataMixin.get_drawdowns()
- OHLCDataMixin.get_log_returns()
- OHLCDataMixin.get_returns()
- OHLCDataMixin.get_returns_acc()
- PandasIndexer.xs()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.resolve_file_path()
- Pickleable.save()
- PlotsBuilderMixin.build_subplots_doc()
- PlotsBuilderMixin.override_subplots_doc()
- PlotsBuilderMixin.plots()
- RemoteData.classes
- RemoteData.close
- RemoteData.cls_dir
- RemoteData.column_only_select
- RemoteData.column_type
- RemoteData.columns
- RemoteData.config
- RemoteData.daily_log_returns
- RemoteData.daily_returns
- RemoteData.data
- RemoteData.delisted
- RemoteData.dict_type
- RemoteData.drawdowns
- RemoteData.feature_classes
- RemoteData.feature_config
- RemoteData.feature_oriented
- RemoteData.feature_wrapper
- RemoteData.features
- RemoteData.fetch_kwargs
- RemoteData.freq
- RemoteData.group_select
- RemoteData.has_any_ohlc
- RemoteData.has_any_ohlcv
- RemoteData.has_ohlc
- RemoteData.has_ohlcv
- RemoteData.high
- RemoteData.hlc3
- RemoteData.iloc
- RemoteData.index
- RemoteData.indexing_kwargs
- RemoteData.key_index
- RemoteData.key_wrapper
- RemoteData.keys
- RemoteData.last_index
- RemoteData.level_name
- RemoteData.loc
- RemoteData.log_returns
- RemoteData.low
- RemoteData.missing_columns
- RemoteData.missing_index
- RemoteData.ndim
- RemoteData.ohlc
- RemoteData.ohlc4
- RemoteData.ohlcv
- RemoteData.open
- RemoteData.plots_defaults
- RemoteData.range_only_select
- RemoteData.rec_state
- RemoteData.returned_kwargs
- RemoteData.returns
- RemoteData.returns_acc
- RemoteData.self_aliases
- RemoteData.shape
- RemoteData.shape_2d
- RemoteData.single_feature
- RemoteData.single_key
- RemoteData.single_symbol
- RemoteData.stats_defaults
- RemoteData.symbol_classes
- RemoteData.symbol_oriented
- RemoteData.symbol_wrapper
- RemoteData.symbols
- RemoteData.trade_count
- RemoteData.tz_convert
- RemoteData.tz_localize
- RemoteData.volume
- RemoteData.vwap
- RemoteData.wrapper
- RemoteData.xloc
- StatsBuilderMixin.build_metrics_doc()
- StatsBuilderMixin.override_metrics_doc()
- StatsBuilderMixin.stats()
- Wrapping.apply_to_index()
- Wrapping.as_param()
- Wrapping.regroup()
- Wrapping.resolve_column_stack_kwargs()
- Wrapping.resolve_row_stack_kwargs()
- Wrapping.resolve_self()
- Wrapping.resolve_stack_kwargs()
- Wrapping.select_col()
- Wrapping.select_col_from_obj()
- Wrapping.split()
- Wrapping.split_apply()
fetch_symbol class method¶
AVData.fetch_symbol(
symbol,
use_parser=None,
apikey=None,
api_meta=None,
category=None,
function=None,
timeframe=None,
tz=None,
adjusted=None,
extended=None,
slice=None,
series_type=None,
time_period=None,
outputsize=None,
match_params=None,
params=None,
read_csv_kwargs=None,
silence_warnings=None
)
Fetch a symbol from Alpha Vantage.
If use_parser is False, or None and alpha_vantage is installed, uses the package. Otherwise, parses the API documentation and pulls data directly.
See https://www.alphavantage.co/documentation/ for API endpoints and their parameters.
Note
Supports the CSV format only.
Args
symbol:str-
Symbol.
May combine symbol/from_currency and market/to_currency using an underscore.
use_parser:bool- Whether to use the parser instead of the
alpha_vantagepackage. apikey:str- API key.
api_meta:dict-
API meta.
If None, will use AVData.parse_api_meta() if
functionis not provided ormatch_paramsis True. category:strorAlphaVantage-
API category of your choice.
Used if
functionis not provided ormatch_paramsis True.Supported are:
alpha_vantage.alphavantage.AlphaVantageinstance, class, or class name- "time-series-data" or "time-series"
- "fundamental-data" or "fundamentals"
- "foreign-exchange", "forex", or "fx"
- "digital-currency", "cryptocurrencies", "cryptocurrency", or "crypto"
- "commodities"
- "economic-indicators"
- "technical-indicators" or "indicators"
function:strorcallable-
API function of your choice.
If None, will try to resolve it based on other arguments, such as
timeframe,adjusted, andextended. Required for technical indicators, economic indicators, and fundamental data.See the keys in sub-dictionaries returned by AVData.parse_api_meta().
timeframe:str-
Timeframe.
Allows human-readable strings such as "15 minutes".
For time series, forex, and crypto, looks for interval type in the function's name. Defaults to "60min" if extended, otherwise to "daily".
tz:any-
Timezone.
See to_timezone().
adjusted:bool- Whether to return time series adjusted by historical split and dividend events.
extended:bool- Whether to return historical intraday time series for the trailing 2 years.
slice:str- Slice of the trailing 2 years.
series_type:str- The desired price type in the time series.
time_period:int- Number of data points used to calculate each window value.
outputsize:str-
Output size.
Supported are
- "compact" that returns only the latest 100 data points
- "full" that returns the full-length time series
match_params:bool-
Whether to match parameters with the ones required by the endpoint.
Otherwise, uses only (resolved)
function,apikey,datatype="csv", andparams. params- Additional keyword arguments passed as key/value pairs in the URL.
read_csv_kwargs:dict- Keyword arguments passed to
pd.read_csv. silence_warnings:bool- Whether to silence all warnings.
For defaults, see custom.av in data.
list_symbols class method¶
List all symbols.
parse_api_meta class method¶
Parse API metadata from the documentation at https://www.alphavantage.co/documentation
Cached class method. To avoid re-parsing the same metadata in different runtimes, save it manually.