|
59 | 59 | "import okama as ok\n", |
60 | 60 | "\n", |
61 | 61 | "plt.rcParams[\"figure.figsize\"] = [12.0, 6.0]\n", |
62 | | - "warnings.simplefilter(action='ignore', category=FutureWarning)" |
| 62 | + "warnings.simplefilter(action=\"ignore\", category=FutureWarning)" |
63 | 63 | ], |
64 | 64 | "metadata": { |
65 | 65 | "collapsed": false |
|
107 | 107 | } |
108 | 108 | ], |
109 | 109 | "source": [ |
110 | | - "ok.symbols_in_namespace('INFL') # the list of available inflation data series" |
| 110 | + "ok.symbols_in_namespace(\"INFL\") # the list of available inflation data series" |
111 | 111 | ], |
112 | 112 | "metadata": { |
113 | 113 | "collapsed": false |
|
127 | 127 | } |
128 | 128 | ], |
129 | 129 | "source": [ |
130 | | - "us_inf = ok.Inflation('USD.INFL', first_date='1913-01', last_date='2024-01') # US dollar inflation\n", |
| 130 | + "us_inf = ok.Inflation(\"USD.INFL\", first_date=\"1913-01\", last_date=\"2024-01\") # US dollar inflation\n", |
131 | 131 | "us_inf" |
132 | 132 | ], |
133 | 133 | "metadata": { |
|
166 | 166 | } |
167 | 167 | ], |
168 | 168 | "source": [ |
169 | | - "us_inf.rolling_inflation['1980':].plot(); # plot US 12-months inflation (CPI)" |
| 169 | + "us_inf.rolling_inflation[\"1980\":].plot(); # plot US 12-months inflation (CPI)" |
170 | 170 | ], |
171 | 171 | "metadata": { |
172 | 172 | "collapsed": false |
|
224 | 224 | } |
225 | 225 | ], |
226 | 226 | "source": [ |
227 | | - "us_inf.annual_inflation_ts['2000': '2020'].plot(kind='bar');" |
| 227 | + "us_inf.annual_inflation_ts[\"2000\":\"2020\"].plot(kind=\"bar\");" |
228 | 228 | ], |
229 | 229 | "metadata": { |
230 | 230 | "collapsed": false |
|
249 | 249 | " Plot 12-month rolling inflation for several countries.\n", |
250 | 250 | " \"\"\"\n", |
251 | 251 | " import pandas as pd\n", |
| 252 | + "\n", |
252 | 253 | " fig, ax = plt.subplots(figsize=[12.0, 8.0])\n", |
253 | 254 | " date1 = pd.to_datetime(first_date)\n", |
254 | 255 | " date2 = pd.to_datetime(last_date)\n", |
255 | 256 | "\n", |
256 | 257 | " for i, ccy in enumerate(ccy_list):\n", |
257 | 258 | " infl_obj = ok.Inflation(ccy)\n", |
258 | 259 | " if i == 0:\n", |
259 | | - " infl_df = infl_obj.rolling_inflation[str(date1):] * 100\n", |
| 260 | + " infl_df = infl_obj.rolling_inflation[str(date1) :] * 100\n", |
260 | 261 | " else:\n", |
261 | | - " infl = infl_obj.rolling_inflation[str(date1):] * 100\n", |
262 | | - " infl_df = pd.concat([infl_df, infl], axis=1, join='inner').dropna()\n", |
| 262 | + " infl = infl_obj.rolling_inflation[str(date1) :] * 100\n", |
| 263 | + " infl_df = pd.concat([infl_df, infl], axis=1, join=\"inner\").dropna()\n", |
263 | 264 | "\n", |
264 | 265 | " for infl_symbol in infl_df.columns:\n", |
265 | | - " ticker = infl_symbol.split('.', 1)[0]\n", |
266 | | - " ax.plot(infl_df[infl_symbol].index.to_timestamp(), infl_df[infl_symbol], linewidth=2, label=f'Inflation {ticker}')\n", |
| 266 | + " ticker = infl_symbol.split(\".\", 1)[0]\n", |
| 267 | + " ax.plot(\n", |
| 268 | + " infl_df[infl_symbol].index.to_timestamp(), infl_df[infl_symbol], linewidth=2, label=f\"Inflation {ticker}\"\n", |
| 269 | + " )\n", |
267 | 270 | "\n", |
268 | 271 | " ax.set_xlim(date1, date2 + pd.Timedelta(30, unit=\"d\"))\n", |
269 | | - " ax.legend(loc='upper right')" |
| 272 | + " ax.legend(loc=\"upper right\")" |
270 | 273 | ], |
271 | 274 | "metadata": { |
272 | 275 | "collapsed": false |
|
286 | 289 | } |
287 | 290 | ], |
288 | 291 | "source": [ |
289 | | - "infl_symbols = list(ok.symbols_in_namespace('INFL').loc[:, 'symbol'])\n", |
| 292 | + "infl_symbols = list(ok.symbols_in_namespace(\"INFL\").loc[:, \"symbol\"])\n", |
290 | 293 | "infl_symbols" |
291 | 294 | ], |
292 | 295 | "metadata": { |
|
307 | 310 | } |
308 | 311 | ], |
309 | 312 | "source": [ |
310 | | - "plot_inflation_list(ccy_list=infl_symbols, first_date='2000-01', last_date='2020-01')" |
| 313 | + "plot_inflation_list(ccy_list=infl_symbols, first_date=\"2000-01\", last_date=\"2020-01\")" |
311 | 314 | ], |
312 | 315 | "metadata": { |
313 | 316 | "collapsed": false |
|
355 | 358 | } |
356 | 359 | ], |
357 | 360 | "source": [ |
358 | | - "ok.Inflation('EUR.INFL', first_date='2000-01', last_date='2020-01').purchasing_power_1000" |
| 361 | + "ok.Inflation(\"EUR.INFL\", first_date=\"2000-01\", last_date=\"2020-01\").purchasing_power_1000" |
359 | 362 | ], |
360 | 363 | "metadata": { |
361 | 364 | "collapsed": false |
|
384 | 387 | } |
385 | 388 | ], |
386 | 389 | "source": [ |
387 | | - "ok.Inflation('GBP.INFL', first_date='2000-01', last_date='2020-01').purchasing_power_1000" |
| 390 | + "ok.Inflation(\"GBP.INFL\", first_date=\"2000-01\", last_date=\"2020-01\").purchasing_power_1000" |
388 | 391 | ], |
389 | 392 | "metadata": { |
390 | 393 | "collapsed": false |
|
413 | 416 | } |
414 | 417 | ], |
415 | 418 | "source": [ |
416 | | - "ok.Inflation('CNY.INFL', first_date='2000-01', last_date='2020-01').purchasing_power_1000" |
| 419 | + "ok.Inflation(\"CNY.INFL\", first_date=\"2000-01\", last_date=\"2020-01\").purchasing_power_1000" |
417 | 420 | ], |
418 | 421 | "metadata": { |
419 | 422 | "collapsed": false |
|
442 | 445 | "execution_count": 38, |
443 | 446 | "outputs": [], |
444 | 447 | "source": [ |
445 | | - "ru_inf = ok.Inflation('RUB.INFL', first_date='2000-01', last_date='2020-01') # Russian rubl inflation" |
| 448 | + "ru_inf = ok.Inflation(\"RUB.INFL\", first_date=\"2000-01\", last_date=\"2020-01\") # Russian rubl inflation" |
446 | 449 | ], |
447 | 450 | "metadata": { |
448 | 451 | "collapsed": false |
|
482 | 485 | "execution_count": 43, |
483 | 486 | "outputs": [], |
484 | 487 | "source": [ |
485 | | - "ru_inf.set_values_monthly(date='2020-02', value=0.006)" |
| 488 | + "ru_inf.set_values_monthly(date=\"2020-02\", value=0.006)" |
486 | 489 | ], |
487 | 490 | "metadata": { |
488 | 491 | "collapsed": false |
|
545 | 548 | } |
546 | 549 | ], |
547 | 550 | "source": [ |
548 | | - "isr_inf = ok.Inflation('ILS.INFL') # Israeli shekel inflation\n", |
| 551 | + "isr_inf = ok.Inflation(\"ILS.INFL\") # Israeli shekel inflation\n", |
549 | 552 | "isr_inf" |
550 | 553 | ], |
551 | 554 | "metadata": { |
|
567 | 570 | } |
568 | 571 | ], |
569 | 572 | "source": [ |
570 | | - "isr_inf.describe([5, 10, 20]) # statistics for 5, 10 and 20 years and full period" |
| 573 | + "isr_inf.describe([5, 10, 20]) # statistics for 5, 10 and 20 years and full period" |
571 | 574 | ], |
572 | 575 | "metadata": { |
573 | 576 | "collapsed": false |
|
615 | 618 | } |
616 | 619 | ], |
617 | 620 | "source": [ |
618 | | - "ok.symbols_in_namespace('RATE') # the list of available rates data series" |
| 621 | + "ok.symbols_in_namespace(\"RATE\") # the list of available rates data series" |
619 | 622 | ], |
620 | 623 | "metadata": { |
621 | 624 | "collapsed": false |
|
644 | 647 | } |
645 | 648 | ], |
646 | 649 | "source": [ |
647 | | - "us_rate = ok.Rate('US_EFFR.RATE')\n", |
| 650 | + "us_rate = ok.Rate(\"US_EFFR.RATE\")\n", |
648 | 651 | "us_rate" |
649 | 652 | ], |
650 | 653 | "metadata": { |
|
674 | 677 | } |
675 | 678 | ], |
676 | 679 | "source": [ |
677 | | - "us_rate.values_monthly['2020':].plot();" |
| 680 | + "us_rate.values_monthly[\"2020\":].plot();" |
678 | 681 | ], |
679 | 682 | "metadata": { |
680 | 683 | "collapsed": false |
|
760 | 763 | "import matplotlib.dates as mdates\n", |
761 | 764 | "import pandas as pd\n", |
762 | 765 | "\n", |
763 | | - "def plot_infl_and_keyrate(infl: pd.DataFrame,\n", |
764 | | - " rate: pd.DataFrame,\n", |
765 | | - " first_date: str,\n", |
766 | | - " last_date: str,\n", |
767 | | - " figsize: list = [12, 6],\n", |
768 | | - " ):\n", |
| 766 | + "\n", |
| 767 | + "def plot_infl_and_keyrate(\n", |
| 768 | + " infl: pd.DataFrame,\n", |
| 769 | + " rate: pd.DataFrame,\n", |
| 770 | + " first_date: str,\n", |
| 771 | + " last_date: str,\n", |
| 772 | + " figsize: list = [12, 6],\n", |
| 773 | + "):\n", |
769 | 774 | "\n", |
770 | 775 | " fig, ax = plt.subplots(figsize=figsize)\n", |
771 | 776 | " first_date_dt = pd.to_datetime(first_date)\n", |
772 | 777 | " last_date_dt = pd.to_datetime(last_date)\n", |
773 | | - " rate = rate.loc[first_date: last_date]\n", |
| 778 | + " rate = rate.loc[first_date:last_date]\n", |
774 | 779 | " if infl is not None:\n", |
775 | | - " infl = infl.loc[first_date: last_date]\n", |
776 | | - " ax.plot(infl.index.to_timestamp(), infl * 100, color ='blue', linewidth = 2, label='12-month inflation')\n", |
777 | | - " ax.plot(rate.index.to_timestamp(), rate * 100, color ='green', linewidth = 2, label='Key rate')\n", |
| 780 | + " infl = infl.loc[first_date:last_date]\n", |
| 781 | + " ax.plot(infl.index.to_timestamp(), infl * 100, color=\"blue\", linewidth=2, label=\"12-month inflation\")\n", |
| 782 | + " ax.plot(rate.index.to_timestamp(), rate * 100, color=\"green\", linewidth=2, label=\"Key rate\")\n", |
778 | 783 | "\n", |
779 | 784 | " ax.set_xlim(first_date_dt, last_date_dt + pd.DateOffset(months=1))\n", |
780 | 785 | "\n", |
781 | 786 | " # set tickers format\n", |
782 | 787 | " years = mdates.YearLocator()\n", |
783 | | - " years_fmt = mdates.DateFormatter('%Y')\n", |
| 788 | + " years_fmt = mdates.DateFormatter(\"%Y\")\n", |
784 | 789 | " ax.xaxis.set_major_locator(years)\n", |
785 | 790 | " ax.xaxis.set_major_formatter(years_fmt)\n", |
786 | 791 | "\n", |
787 | | - " ax.legend(loc='upper left')\n", |
788 | | - " ax.set_ylabel('rate, %')" |
| 792 | + " ax.legend(loc=\"upper left\")\n", |
| 793 | + " ax.set_ylabel(\"rate, %\")" |
789 | 794 | ], |
790 | 795 | "metadata": { |
791 | 796 | "collapsed": false |
|
796 | 801 | "execution_count": 76, |
797 | 802 | "outputs": [], |
798 | 803 | "source": [ |
799 | | - "infl = ok.Inflation('USD.INFL').rolling_inflation\n", |
800 | | - "rates = ok.Rate('US_EFFR.RATE').values_monthly # US Federal Reserve Effective Federal Funds Rate" |
| 804 | + "infl = ok.Inflation(\"USD.INFL\").rolling_inflation\n", |
| 805 | + "rates = ok.Rate(\"US_EFFR.RATE\").values_monthly # US Federal Reserve Effective Federal Funds Rate" |
801 | 806 | ], |
802 | 807 | "metadata": { |
803 | 808 | "collapsed": false |
|
817 | 822 | } |
818 | 823 | ], |
819 | 824 | "source": [ |
820 | | - "plot_infl_and_keyrate(infl=infl, rate=rates, first_date='2000-01', last_date='2020-01')" |
| 825 | + "plot_infl_and_keyrate(infl=infl, rate=rates, first_date=\"2000-01\", last_date=\"2020-01\")" |
821 | 826 | ], |
822 | 827 | "metadata": { |
823 | 828 | "collapsed": false |
|
856 | 861 | } |
857 | 862 | ], |
858 | 863 | "source": [ |
859 | | - "ok.symbols_in_namespace('RATIO')" |
| 864 | + "ok.symbols_in_namespace(\"RATIO\")" |
860 | 865 | ], |
861 | 866 | "metadata": { |
862 | 867 | "collapsed": false |
|
899 | 904 | } |
900 | 905 | ], |
901 | 906 | "source": [ |
902 | | - "cape = ok.Indicator('GBR_CAPE10.RATIO') # CAPE 10 for UK market\n", |
| 907 | + "cape = ok.Indicator(\"GBR_CAPE10.RATIO\") # CAPE 10 for UK market\n", |
903 | 908 | "cape" |
904 | 909 | ], |
905 | 910 | "metadata": { |
|
973 | 978 | } |
974 | 979 | ], |
975 | 980 | "source": [ |
976 | | - "cape_symbols = ok.symbols_in_namespace('RATIO')['symbol']\n", |
| 981 | + "cape_symbols = ok.symbols_in_namespace(\"RATIO\")[\"symbol\"]\n", |
977 | 982 | "cape_objects = [ok.Indicator(cape) for cape in cape_symbols]\n", |
978 | 983 | "cape_df = pd.DataFrame({cape.country: cape.values_monthly for cape in cape_objects})\n", |
979 | 984 | "cape_df.plot();" |
|
0 commit comments