Skip to content

Commit fadf935

Browse files
committed
chore: update code style by black
1 parent 2813aed commit fadf935

15 files changed

+99
-96
lines changed

examples/03 investment portfolios.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"import matplotlib.pyplot as plt\n",
5555
"\n",
5656
"plt.rcParams[\"figure.figsize\"] = [12.0, 6.0]\n",
57-
"warnings.simplefilter(action='ignore', category=FutureWarning)\n",
57+
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)\n",
5858
"\n",
5959
"import okama as ok"
6060
]

examples/04 investment portfolios with DCF.ipynb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"import okama as ok\n",
6060
"\n",
6161
"plt.rcParams[\"figure.figsize\"] = [12.0, 6.0]\n",
62-
"warnings.simplefilter(action='ignore', category=FutureWarning)"
62+
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)"
6363
],
6464
"metadata": {
6565
"collapsed": false
@@ -92,12 +92,12 @@
9292
],
9393
"source": [
9494
"pf = ok.Portfolio(\n",
95-
" ['SPY.US', 'AGG.US', 'GLD.US'],\n",
96-
" weights=[.60, .35, .05],\n",
97-
" ccy='USD',\n",
95+
" [\"SPY.US\", \"AGG.US\", \"GLD.US\"],\n",
96+
" weights=[0.60, 0.35, 0.05],\n",
97+
" ccy=\"USD\",\n",
9898
" inflation=False,\n",
99-
" last_date='2024-01',\n",
100-
" rebalancing_period='year',\n",
99+
" last_date=\"2024-01\",\n",
100+
" rebalancing_period=\"year\",\n",
101101
" initial_amount=300_000, # portfolio initial investments\n",
102102
" cashflow=-2_000, # portfolio monthly withdrawals\n",
103103
")\n",
@@ -228,7 +228,7 @@
228228
}
229229
],
230230
"source": [
231-
"pf.dcf.survival_date # the date when portfolio has zero value after withdrawals"
231+
"pf.dcf.survival_date # the date when portfolio has zero value after withdrawals"
232232
],
233233
"metadata": {
234234
"collapsed": false
@@ -335,7 +335,7 @@
335335
}
336336
],
337337
"source": [
338-
"pf.dcf.initial_amount_pv # the value of initial investments PV changes"
338+
"pf.dcf.initial_amount_pv # the value of initial investments PV changes"
339339
],
340340
"metadata": {
341341
"collapsed": false
@@ -365,12 +365,12 @@
365365
"outputs": [],
366366
"source": [
367367
"pf2 = ok.Portfolio(\n",
368-
" ['MCFTR.INDX', 'RGBITR.INDX', 'GC.COMM'],\n",
369-
" weights=[.40, .40, .20],\n",
370-
" ccy='RUB',\n",
368+
" [\"MCFTR.INDX\", \"RGBITR.INDX\", \"GC.COMM\"],\n",
369+
" weights=[0.40, 0.40, 0.20],\n",
370+
" ccy=\"RUB\",\n",
371371
" inflation=True,\n",
372-
" last_date='2024-01',\n",
373-
" rebalancing_period='year',\n",
372+
" last_date=\"2024-01\",\n",
373+
" rebalancing_period=\"year\",\n",
374374
" initial_amount=600_000, # portfolio initial investments\n",
375375
" cashflow=-4_000, # portfolio monthly withdrawals\n",
376376
")"
@@ -403,10 +403,10 @@
403403
],
404404
"source": [
405405
"pf2.dcf.plot_forecast_monte_carlo(\n",
406-
" distr='norm', # the rate of return distribution. Can be set to `norm` for normal distribution or `lognorm` for lognormal\n",
406+
" distr=\"norm\", # the rate of return distribution. Can be set to `norm` for normal distribution or `lognorm` for lognormal\n",
407407
" years=30, # future period\n",
408408
" backtest=True, # chose whether to plot backtest portfolio (True) or start from the future time series (False)\n",
409-
" n=50 # Number of random time series generated by Monte Carlo\n",
409+
" n=50, # Number of random time series generated by Monte Carlo\n",
410410
")"
411411
],
412412
"metadata": {
@@ -446,9 +446,9 @@
446446
"outputs": [],
447447
"source": [
448448
"s = pf2.monte_carlo_survival_period(\n",
449-
" distr='norm', # the rate of return distribution. Can be set to `norm` for normal distribution, `lognorm` for lognormal or 't' for Student's\n",
449+
" distr=\"norm\", # the rate of return distribution. Can be set to `norm` for normal distribution, `lognorm` for lognormal or 't' for Student's\n",
450450
" years=30, # future period\n",
451-
" n=100 # Number of random time series generated by Monte Carlo\n",
451+
" n=100, # Number of random time series generated by Monte Carlo\n",
452452
")"
453453
],
454454
"metadata": {

examples/05 macroeconomics - inflation rates.ipynb

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"import okama as ok\n",
6060
"\n",
6161
"plt.rcParams[\"figure.figsize\"] = [12.0, 6.0]\n",
62-
"warnings.simplefilter(action='ignore', category=FutureWarning)"
62+
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)"
6363
],
6464
"metadata": {
6565
"collapsed": false
@@ -107,7 +107,7 @@
107107
}
108108
],
109109
"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"
111111
],
112112
"metadata": {
113113
"collapsed": false
@@ -127,7 +127,7 @@
127127
}
128128
],
129129
"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",
131131
"us_inf"
132132
],
133133
"metadata": {
@@ -166,7 +166,7 @@
166166
}
167167
],
168168
"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)"
170170
],
171171
"metadata": {
172172
"collapsed": false
@@ -224,7 +224,7 @@
224224
}
225225
],
226226
"source": [
227-
"us_inf.annual_inflation_ts['2000': '2020'].plot(kind='bar');"
227+
"us_inf.annual_inflation_ts[\"2000\":\"2020\"].plot(kind=\"bar\");"
228228
],
229229
"metadata": {
230230
"collapsed": false
@@ -249,24 +249,27 @@
249249
" Plot 12-month rolling inflation for several countries.\n",
250250
" \"\"\"\n",
251251
" import pandas as pd\n",
252+
"\n",
252253
" fig, ax = plt.subplots(figsize=[12.0, 8.0])\n",
253254
" date1 = pd.to_datetime(first_date)\n",
254255
" date2 = pd.to_datetime(last_date)\n",
255256
"\n",
256257
" for i, ccy in enumerate(ccy_list):\n",
257258
" infl_obj = ok.Inflation(ccy)\n",
258259
" 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",
260261
" 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",
263264
"\n",
264265
" 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",
267270
"\n",
268271
" ax.set_xlim(date1, date2 + pd.Timedelta(30, unit=\"d\"))\n",
269-
" ax.legend(loc='upper right')"
272+
" ax.legend(loc=\"upper right\")"
270273
],
271274
"metadata": {
272275
"collapsed": false
@@ -286,7 +289,7 @@
286289
}
287290
],
288291
"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",
290293
"infl_symbols"
291294
],
292295
"metadata": {
@@ -307,7 +310,7 @@
307310
}
308311
],
309312
"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\")"
311314
],
312315
"metadata": {
313316
"collapsed": false
@@ -355,7 +358,7 @@
355358
}
356359
],
357360
"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"
359362
],
360363
"metadata": {
361364
"collapsed": false
@@ -384,7 +387,7 @@
384387
}
385388
],
386389
"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"
388391
],
389392
"metadata": {
390393
"collapsed": false
@@ -413,7 +416,7 @@
413416
}
414417
],
415418
"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"
417420
],
418421
"metadata": {
419422
"collapsed": false
@@ -442,7 +445,7 @@
442445
"execution_count": 38,
443446
"outputs": [],
444447
"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"
446449
],
447450
"metadata": {
448451
"collapsed": false
@@ -482,7 +485,7 @@
482485
"execution_count": 43,
483486
"outputs": [],
484487
"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)"
486489
],
487490
"metadata": {
488491
"collapsed": false
@@ -545,7 +548,7 @@
545548
}
546549
],
547550
"source": [
548-
"isr_inf = ok.Inflation('ILS.INFL') # Israeli shekel inflation\n",
551+
"isr_inf = ok.Inflation(\"ILS.INFL\") # Israeli shekel inflation\n",
549552
"isr_inf"
550553
],
551554
"metadata": {
@@ -567,7 +570,7 @@
567570
}
568571
],
569572
"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"
571574
],
572575
"metadata": {
573576
"collapsed": false
@@ -615,7 +618,7 @@
615618
}
616619
],
617620
"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"
619622
],
620623
"metadata": {
621624
"collapsed": false
@@ -644,7 +647,7 @@
644647
}
645648
],
646649
"source": [
647-
"us_rate = ok.Rate('US_EFFR.RATE')\n",
650+
"us_rate = ok.Rate(\"US_EFFR.RATE\")\n",
648651
"us_rate"
649652
],
650653
"metadata": {
@@ -674,7 +677,7 @@
674677
}
675678
],
676679
"source": [
677-
"us_rate.values_monthly['2020':].plot();"
680+
"us_rate.values_monthly[\"2020\":].plot();"
678681
],
679682
"metadata": {
680683
"collapsed": false
@@ -760,32 +763,34 @@
760763
"import matplotlib.dates as mdates\n",
761764
"import pandas as pd\n",
762765
"\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",
769774
"\n",
770775
" fig, ax = plt.subplots(figsize=figsize)\n",
771776
" first_date_dt = pd.to_datetime(first_date)\n",
772777
" 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",
774779
" 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",
778783
"\n",
779784
" ax.set_xlim(first_date_dt, last_date_dt + pd.DateOffset(months=1))\n",
780785
"\n",
781786
" # set tickers format\n",
782787
" years = mdates.YearLocator()\n",
783-
" years_fmt = mdates.DateFormatter('%Y')\n",
788+
" years_fmt = mdates.DateFormatter(\"%Y\")\n",
784789
" ax.xaxis.set_major_locator(years)\n",
785790
" ax.xaxis.set_major_formatter(years_fmt)\n",
786791
"\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, %\")"
789794
],
790795
"metadata": {
791796
"collapsed": false
@@ -796,8 +801,8 @@
796801
"execution_count": 76,
797802
"outputs": [],
798803
"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"
801806
],
802807
"metadata": {
803808
"collapsed": false
@@ -817,7 +822,7 @@
817822
}
818823
],
819824
"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\")"
821826
],
822827
"metadata": {
823828
"collapsed": false
@@ -856,7 +861,7 @@
856861
}
857862
],
858863
"source": [
859-
"ok.symbols_in_namespace('RATIO')"
864+
"ok.symbols_in_namespace(\"RATIO\")"
860865
],
861866
"metadata": {
862867
"collapsed": false
@@ -899,7 +904,7 @@
899904
}
900905
],
901906
"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",
903908
"cape"
904909
],
905910
"metadata": {
@@ -973,7 +978,7 @@
973978
}
974979
],
975980
"source": [
976-
"cape_symbols = ok.symbols_in_namespace('RATIO')['symbol']\n",
981+
"cape_symbols = ok.symbols_in_namespace(\"RATIO\")[\"symbol\"]\n",
977982
"cape_objects = [ok.Indicator(cape) for cape in cape_symbols]\n",
978983
"cape_df = pd.DataFrame({cape.country: cape.values_monthly for cape in cape_objects})\n",
979984
"cape_df.plot();"

0 commit comments

Comments
 (0)