r"""Get data from an external feed. Parameters ---------- model : alphapy.Model The model object describing the data. market_specs : dict The specifications for controlling the MarketFlow pipeline. group : alphapy.Group The group of symbols. lookback_
(model, market_specs, group, lookback_period, intraday_data=False)
| 738 | # |
| 739 | |
| 740 | def get_market_data(model, market_specs, group, lookback_period, intraday_data=False): |
| 741 | r"""Get data from an external feed. |
| 742 | |
| 743 | Parameters |
| 744 | ---------- |
| 745 | model : alphapy.Model |
| 746 | The model object describing the data. |
| 747 | market_specs : dict |
| 748 | The specifications for controlling the MarketFlow pipeline. |
| 749 | group : alphapy.Group |
| 750 | The group of symbols. |
| 751 | lookback_period : int |
| 752 | The number of periods of data to retrieve. |
| 753 | intraday_data : bool |
| 754 | If True, then get intraday data. |
| 755 | |
| 756 | Returns |
| 757 | ------- |
| 758 | n_periods : int |
| 759 | The maximum number of periods actually retrieved. |
| 760 | |
| 761 | """ |
| 762 | |
| 763 | # Unpack market specifications |
| 764 | |
| 765 | data_fractal = market_specs['data_fractal'] |
| 766 | subschema = market_specs['subschema'] |
| 767 | |
| 768 | # Unpack model specifications |
| 769 | |
| 770 | directory = model.specs['directory'] |
| 771 | extension = model.specs['extension'] |
| 772 | separator = model.specs['separator'] |
| 773 | |
| 774 | # Unpack group elements |
| 775 | |
| 776 | gspace = group.space |
| 777 | schema = gspace.schema |
| 778 | fractal = gspace.fractal |
| 779 | |
| 780 | # Determine the feed source |
| 781 | |
| 782 | if intraday_data: |
| 783 | # intraday data (date and time) |
| 784 | logger.info("%s Intraday Data [%s] for %d periods", |
| 785 | schema, data_fractal, lookback_period) |
| 786 | index_column = 'datetime' |
| 787 | else: |
| 788 | # daily data or higher (date only) |
| 789 | logger.info("%s Daily Data [%s] for %d periods", |
| 790 | schema, data_fractal, lookback_period) |
| 791 | index_column = 'date' |
| 792 | |
| 793 | # Get the data from the relevant feed |
| 794 | |
| 795 | data_dir = SSEP.join([directory, 'data']) |
| 796 | n_periods = 0 |
| 797 | resample_data = True if fractal != data_fractal else False |
no test coverage detected