|
13 | 13 | "source": [
|
14 | 14 | "#### Sections\n",
|
15 | 15 | "* [`request_all_prices`](#request_all_prices)\n",
|
16 |
| - "* [`prices_for_symbols`](#prices_for_symbols)" |
| 16 | + "* [`prices_for_symbols`](#prices_for_symbols)\n", |
| 17 | + "* [`to_csv`](#to_csv)" |
17 | 18 | ]
|
18 | 19 | },
|
19 | 20 | {
|
|
135 | 136 | "source": [
|
136 | 137 | "Notice that no prices are stored for the H1 interval. This is because prices include an equity listed on the New York Stock Exchange and one listed on the London Stock Exchange. The opening times of these exchanges are such that sessions often overlap although the indices at H1 are not aligned. Consequently, it's not possible to evaluate common hourly indices (at least not using H1 data).\n",
|
137 | 138 | "\n",
|
138 |
| - "The rest of this subsection demonstrates some under-the-bonnet behaviour that can be safely skipped - move onto [`prices_for_symbols`](#prices_for_symbols) if you're not interested.\n", |
| 139 | + "The rest of this section demonstrates some under-the-bonnet behaviour that can be safely skipped - move onto [`prices_for_symbols`](#prices_for_symbols) if you're not interested.\n", |
139 | 140 | "\n",
|
140 | 141 | "Srictly speaking, valid hourly data will be available for any session where only one of these two exchanges is open, or when one or both have irregular opening hours such that they do not overlap (or align if they do). If intraday prices are requested for just such a session then a request for hourly data will be sent to the provider if intraday prices for that session are not available at an interval smaller than one hour."
|
141 | 142 | ]
|
|
729 | 730 | "source": [
|
730 | 731 | "new_prices._pdata[new_prices.bis.T5]._table"
|
731 | 732 | ]
|
| 733 | + }, |
| 734 | + { |
| 735 | + "cell_type": "markdown", |
| 736 | + "metadata": {}, |
| 737 | + "source": [ |
| 738 | + "## `to_csv`\n", |
| 739 | + "`to_csv` provides for exporting price data to .csv files. The method has one required argument 'path' which takes a path to an **existing** directory to which the .csv files should be written. If no further arguments are passed then the default implementation will export all available price data as one csv file per aligned base interval per symbol, such that if there are 3 base intervals and 5 symbols then 15 .csv files will be created (the base intervals for a prices instance can be inspected with `prices.bis.__members__`).\n", |
| 740 | + "\n", |
| 741 | + "Optional arguments provide for defining the `intervals` for which price data should be exported together with which symbols to `include` or `exclude`. The period over which price data is to be exported and the configuration of that data can be defined by passing any kwargs that are accepted by the `get` method (with the exception of 'interval'). For example 'start', 'days', 'anchor', 'priority', 'strict' etc are all valid keyword arguments.\n", |
| 742 | + "\n", |
| 743 | + "Files exported with `to_csv` can be retrieved with the default implementation of the `PricesCsv` class. (NB this requires that the exported data conforms with the requirements of the `PricesCsv` class, for example that prices are anchored on the 'open' and have an interval no higher than daily. Files exported with the default implementation will always be retrievable via the `PricesCsv` class.)\n", |
| 744 | + "\n", |
| 745 | + "See the method doc for further information..." |
| 746 | + ] |
| 747 | + }, |
| 748 | + { |
| 749 | + "cell_type": "code", |
| 750 | + "execution_count": null, |
| 751 | + "metadata": {}, |
| 752 | + "outputs": [], |
| 753 | + "source": [ |
| 754 | + "prices.to_csv?" |
| 755 | + ] |
| 756 | + }, |
| 757 | + { |
| 758 | + "cell_type": "markdown", |
| 759 | + "metadata": {}, |
| 760 | + "source": [ |
| 761 | + "```\n", |
| 762 | + "Signature:\n", |
| 763 | + "prices.to_csv(\n", |
| 764 | + " path: 'Annotated[Union[str, Path], Coerce(Path), Parser(parsing.verify_directory)]',\n", |
| 765 | + " intervals: 'Optional[Union[str, pd.Timedelta, datetime.timedelta, list[str], list[pd.Timedelta], list[datetime.timedelta]]]' = None,\n", |
| 766 | + " include: 'Optional[mptypes.Symbols]' = None,\n", |
| 767 | + " exclude: 'Optional[mptypes.Symbols]' = None,\n", |
| 768 | + " **kwargs,\n", |
| 769 | + ") -> 'list[Path]'\n", |
| 770 | + "Docstring:\n", |
| 771 | + "Export price data to .csv file(s).\n", |
| 772 | + "\n", |
| 773 | + "Note: Exported price data can be retrieved with the default\n", |
| 774 | + "implementation of the `PricesCsv` class (requires that the\n", |
| 775 | + "exported data conforms with the requirements of the\n", |
| 776 | + "`PricesCsv` class, for example that prices are anchored on\n", |
| 777 | + "the 'open' and have an interval no higher than daily).\n", |
| 778 | + "\n", |
| 779 | + "Price data will be exported by symbol by interval, such that if\n", |
| 780 | + "data is requested for 3 intervals and 5 symbols then 15 .csv\n", |
| 781 | + "files will be created.\n", |
| 782 | + "\n", |
| 783 | + ".csv filenames will follow the format:\n", |
| 784 | + " <SYMBOL>_<INTERVAL>_<YYMMDD>_<YYMMDD>.csv\n", |
| 785 | + " For example:\n", |
| 786 | + " MSFT_5T_240122_240215.csv\n", |
| 787 | + " This file would hold '5T' (i.e. 5 minute) price data for\n", |
| 788 | + " the symbol MSFT covering the period from 2024-01-22 through\n", |
| 789 | + " 2024-02-15. Note: for intraday intervals the dates will\n", |
| 790 | + " represent the earliest and latest sessions for which at least\n", |
| 791 | + " some price data is included.\n", |
| 792 | + "\n", |
| 793 | + "Parameters\n", |
| 794 | + "----------\n", |
| 795 | + "path\n", |
| 796 | + " Directory to which .csv files should be written. This path\n", |
| 797 | + " must exist.\n", |
| 798 | + "\n", |
| 799 | + "intervals\n", |
| 800 | + " Intervals for which price data is to be exported. To define\n", |
| 801 | + " a single interval pass as for the 'interval` parameter of the\n", |
| 802 | + " `.get` method. To define multiple intervals pass as a list\n", |
| 803 | + " of one of the types that's acceptable input to the 'interval`\n", |
| 804 | + " parameter of the `.get` method.\n", |
| 805 | + "\n", |
| 806 | + " By default (None) .csv files are exported for all available\n", |
| 807 | + " base intervals.\n", |
| 808 | + "\n", |
| 809 | + "include : list[str] | str | None\n", |
| 810 | + " Symbol or symbols to include in export. All other symbols will\n", |
| 811 | + " be excluded. If passed, do not pass `exclude`.\n", |
| 812 | + "\n", |
| 813 | + " By default, if neither include nor exclude are passed then data\n", |
| 814 | + " will be exported for all symbols.\n", |
| 815 | + "\n", |
| 816 | + "exclude : list[str] | str | None\n", |
| 817 | + " Symbol or symbols to exclude from export. Data will be exported\n", |
| 818 | + " for all other symbols. If passed, do not pass `include`.\n", |
| 819 | + "\n", |
| 820 | + " By default, if neither exclude nor include are passed then data\n", |
| 821 | + " will be exported for all symbols.\n", |
| 822 | + "\n", |
| 823 | + "kwargs\n", |
| 824 | + " All other kwargs will be passed on to the `.get` method to\n", |
| 825 | + " define the period over which prices are to be exported. Can\n", |
| 826 | + " include other options, for example 'anchor', 'priority',\n", |
| 827 | + " 'strict' etc.\n", |
| 828 | + "\n", |
| 829 | + " If no other kwargs are not passed then by default all available\n", |
| 830 | + " data will be exported for each requested symbol / interval.\n", |
| 831 | + "\n", |
| 832 | + "Returns\n", |
| 833 | + "-------\n", |
| 834 | + "paths\n", |
| 835 | + " List of Path objects to which data exported.\n", |
| 836 | + "```" |
| 837 | + ] |
732 | 838 | }
|
733 | 839 | ],
|
734 | 840 | "metadata": {
|
735 | 841 | "kernelspec": {
|
736 |
| - "display_name": "mkt_prices 3.8.2", |
| 842 | + "display_name": "market_prices_ve_39", |
737 | 843 | "language": "python",
|
738 |
| - "name": "mkt_prices" |
| 844 | + "name": "market_prices_ve_39" |
739 | 845 | },
|
740 | 846 | "language_info": {
|
741 | 847 | "codemirror_mode": {
|
|
747 | 853 | "name": "python",
|
748 | 854 | "nbconvert_exporter": "python",
|
749 | 855 | "pygments_lexer": "ipython3",
|
750 |
| - "version": "3.8.2" |
| 856 | + "version": "3.9.13" |
751 | 857 | },
|
752 | 858 | "widgets": {
|
753 | 859 | "application/vnd.jupyter.widget-state+json": {
|
|
0 commit comments