Skip to content

Commit

Permalink
chore: update code style by black
Browse files Browse the repository at this point in the history
  • Loading branch information
chilango74 committed Jul 5, 2024
1 parent 2813aed commit fadf935
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 96 deletions.
2 changes: 1 addition & 1 deletion examples/03 investment portfolios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"import matplotlib.pyplot as plt\n",
"\n",
"plt.rcParams[\"figure.figsize\"] = [12.0, 6.0]\n",
"warnings.simplefilter(action='ignore', category=FutureWarning)\n",
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)\n",
"\n",
"import okama as ok"
]
Expand Down
34 changes: 17 additions & 17 deletions examples/04 investment portfolios with DCF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"import okama as ok\n",
"\n",
"plt.rcParams[\"figure.figsize\"] = [12.0, 6.0]\n",
"warnings.simplefilter(action='ignore', category=FutureWarning)"
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -92,12 +92,12 @@
],
"source": [
"pf = ok.Portfolio(\n",
" ['SPY.US', 'AGG.US', 'GLD.US'],\n",
" weights=[.60, .35, .05],\n",
" ccy='USD',\n",
" [\"SPY.US\", \"AGG.US\", \"GLD.US\"],\n",
" weights=[0.60, 0.35, 0.05],\n",
" ccy=\"USD\",\n",
" inflation=False,\n",
" last_date='2024-01',\n",
" rebalancing_period='year',\n",
" last_date=\"2024-01\",\n",
" rebalancing_period=\"year\",\n",
" initial_amount=300_000, # portfolio initial investments\n",
" cashflow=-2_000, # portfolio monthly withdrawals\n",
")\n",
Expand Down Expand Up @@ -228,7 +228,7 @@
}
],
"source": [
"pf.dcf.survival_date # the date when portfolio has zero value after withdrawals"
"pf.dcf.survival_date # the date when portfolio has zero value after withdrawals"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -335,7 +335,7 @@
}
],
"source": [
"pf.dcf.initial_amount_pv # the value of initial investments PV changes"
"pf.dcf.initial_amount_pv # the value of initial investments PV changes"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -365,12 +365,12 @@
"outputs": [],
"source": [
"pf2 = ok.Portfolio(\n",
" ['MCFTR.INDX', 'RGBITR.INDX', 'GC.COMM'],\n",
" weights=[.40, .40, .20],\n",
" ccy='RUB',\n",
" [\"MCFTR.INDX\", \"RGBITR.INDX\", \"GC.COMM\"],\n",
" weights=[0.40, 0.40, 0.20],\n",
" ccy=\"RUB\",\n",
" inflation=True,\n",
" last_date='2024-01',\n",
" rebalancing_period='year',\n",
" last_date=\"2024-01\",\n",
" rebalancing_period=\"year\",\n",
" initial_amount=600_000, # portfolio initial investments\n",
" cashflow=-4_000, # portfolio monthly withdrawals\n",
")"
Expand Down Expand Up @@ -403,10 +403,10 @@
],
"source": [
"pf2.dcf.plot_forecast_monte_carlo(\n",
" distr='norm', # the rate of return distribution. Can be set to `norm` for normal distribution or `lognorm` for lognormal\n",
" distr=\"norm\", # the rate of return distribution. Can be set to `norm` for normal distribution or `lognorm` for lognormal\n",
" years=30, # future period\n",
" backtest=True, # chose whether to plot backtest portfolio (True) or start from the future time series (False)\n",
" n=50 # Number of random time series generated by Monte Carlo\n",
" n=50, # Number of random time series generated by Monte Carlo\n",
")"
],
"metadata": {
Expand Down Expand Up @@ -446,9 +446,9 @@
"outputs": [],
"source": [
"s = pf2.monte_carlo_survival_period(\n",
" distr='norm', # the rate of return distribution. Can be set to `norm` for normal distribution, `lognorm` for lognormal or 't' for Student's\n",
" distr=\"norm\", # the rate of return distribution. Can be set to `norm` for normal distribution, `lognorm` for lognormal or 't' for Student's\n",
" years=30, # future period\n",
" n=100 # Number of random time series generated by Monte Carlo\n",
" n=100, # Number of random time series generated by Monte Carlo\n",
")"
],
"metadata": {
Expand Down
89 changes: 47 additions & 42 deletions examples/05 macroeconomics - inflation rates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"import okama as ok\n",
"\n",
"plt.rcParams[\"figure.figsize\"] = [12.0, 6.0]\n",
"warnings.simplefilter(action='ignore', category=FutureWarning)"
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -107,7 +107,7 @@
}
],
"source": [
"ok.symbols_in_namespace('INFL') # the list of available inflation data series"
"ok.symbols_in_namespace(\"INFL\") # the list of available inflation data series"
],
"metadata": {
"collapsed": false
Expand All @@ -127,7 +127,7 @@
}
],
"source": [
"us_inf = ok.Inflation('USD.INFL', first_date='1913-01', last_date='2024-01') # US dollar inflation\n",
"us_inf = ok.Inflation(\"USD.INFL\", first_date=\"1913-01\", last_date=\"2024-01\") # US dollar inflation\n",
"us_inf"
],
"metadata": {
Expand Down Expand Up @@ -166,7 +166,7 @@
}
],
"source": [
"us_inf.rolling_inflation['1980':].plot(); # plot US 12-months inflation (CPI)"
"us_inf.rolling_inflation[\"1980\":].plot(); # plot US 12-months inflation (CPI)"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -224,7 +224,7 @@
}
],
"source": [
"us_inf.annual_inflation_ts['2000': '2020'].plot(kind='bar');"
"us_inf.annual_inflation_ts[\"2000\":\"2020\"].plot(kind=\"bar\");"
],
"metadata": {
"collapsed": false
Expand All @@ -249,24 +249,27 @@
" Plot 12-month rolling inflation for several countries.\n",
" \"\"\"\n",
" import pandas as pd\n",
"\n",
" fig, ax = plt.subplots(figsize=[12.0, 8.0])\n",
" date1 = pd.to_datetime(first_date)\n",
" date2 = pd.to_datetime(last_date)\n",
"\n",
" for i, ccy in enumerate(ccy_list):\n",
" infl_obj = ok.Inflation(ccy)\n",
" if i == 0:\n",
" infl_df = infl_obj.rolling_inflation[str(date1):] * 100\n",
" infl_df = infl_obj.rolling_inflation[str(date1) :] * 100\n",
" else:\n",
" infl = infl_obj.rolling_inflation[str(date1):] * 100\n",
" infl_df = pd.concat([infl_df, infl], axis=1, join='inner').dropna()\n",
" infl = infl_obj.rolling_inflation[str(date1) :] * 100\n",
" infl_df = pd.concat([infl_df, infl], axis=1, join=\"inner\").dropna()\n",
"\n",
" for infl_symbol in infl_df.columns:\n",
" ticker = infl_symbol.split('.', 1)[0]\n",
" ax.plot(infl_df[infl_symbol].index.to_timestamp(), infl_df[infl_symbol], linewidth=2, label=f'Inflation {ticker}')\n",
" ticker = infl_symbol.split(\".\", 1)[0]\n",
" ax.plot(\n",
" infl_df[infl_symbol].index.to_timestamp(), infl_df[infl_symbol], linewidth=2, label=f\"Inflation {ticker}\"\n",
" )\n",
"\n",
" ax.set_xlim(date1, date2 + pd.Timedelta(30, unit=\"d\"))\n",
" ax.legend(loc='upper right')"
" ax.legend(loc=\"upper right\")"
],
"metadata": {
"collapsed": false
Expand All @@ -286,7 +289,7 @@
}
],
"source": [
"infl_symbols = list(ok.symbols_in_namespace('INFL').loc[:, 'symbol'])\n",
"infl_symbols = list(ok.symbols_in_namespace(\"INFL\").loc[:, \"symbol\"])\n",
"infl_symbols"
],
"metadata": {
Expand All @@ -307,7 +310,7 @@
}
],
"source": [
"plot_inflation_list(ccy_list=infl_symbols, first_date='2000-01', last_date='2020-01')"
"plot_inflation_list(ccy_list=infl_symbols, first_date=\"2000-01\", last_date=\"2020-01\")"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -355,7 +358,7 @@
}
],
"source": [
"ok.Inflation('EUR.INFL', first_date='2000-01', last_date='2020-01').purchasing_power_1000"
"ok.Inflation(\"EUR.INFL\", first_date=\"2000-01\", last_date=\"2020-01\").purchasing_power_1000"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -384,7 +387,7 @@
}
],
"source": [
"ok.Inflation('GBP.INFL', first_date='2000-01', last_date='2020-01').purchasing_power_1000"
"ok.Inflation(\"GBP.INFL\", first_date=\"2000-01\", last_date=\"2020-01\").purchasing_power_1000"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -413,7 +416,7 @@
}
],
"source": [
"ok.Inflation('CNY.INFL', first_date='2000-01', last_date='2020-01').purchasing_power_1000"
"ok.Inflation(\"CNY.INFL\", first_date=\"2000-01\", last_date=\"2020-01\").purchasing_power_1000"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -442,7 +445,7 @@
"execution_count": 38,
"outputs": [],
"source": [
"ru_inf = ok.Inflation('RUB.INFL', first_date='2000-01', last_date='2020-01') # Russian rubl inflation"
"ru_inf = ok.Inflation(\"RUB.INFL\", first_date=\"2000-01\", last_date=\"2020-01\") # Russian rubl inflation"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -482,7 +485,7 @@
"execution_count": 43,
"outputs": [],
"source": [
"ru_inf.set_values_monthly(date='2020-02', value=0.006)"
"ru_inf.set_values_monthly(date=\"2020-02\", value=0.006)"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -545,7 +548,7 @@
}
],
"source": [
"isr_inf = ok.Inflation('ILS.INFL') # Israeli shekel inflation\n",
"isr_inf = ok.Inflation(\"ILS.INFL\") # Israeli shekel inflation\n",
"isr_inf"
],
"metadata": {
Expand All @@ -567,7 +570,7 @@
}
],
"source": [
"isr_inf.describe([5, 10, 20]) # statistics for 5, 10 and 20 years and full period"
"isr_inf.describe([5, 10, 20]) # statistics for 5, 10 and 20 years and full period"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -615,7 +618,7 @@
}
],
"source": [
"ok.symbols_in_namespace('RATE') # the list of available rates data series"
"ok.symbols_in_namespace(\"RATE\") # the list of available rates data series"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -644,7 +647,7 @@
}
],
"source": [
"us_rate = ok.Rate('US_EFFR.RATE')\n",
"us_rate = ok.Rate(\"US_EFFR.RATE\")\n",
"us_rate"
],
"metadata": {
Expand Down Expand Up @@ -674,7 +677,7 @@
}
],
"source": [
"us_rate.values_monthly['2020':].plot();"
"us_rate.values_monthly[\"2020\":].plot();"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -760,32 +763,34 @@
"import matplotlib.dates as mdates\n",
"import pandas as pd\n",
"\n",
"def plot_infl_and_keyrate(infl: pd.DataFrame,\n",
" rate: pd.DataFrame,\n",
" first_date: str,\n",
" last_date: str,\n",
" figsize: list = [12, 6],\n",
" ):\n",
"\n",
"def plot_infl_and_keyrate(\n",
" infl: pd.DataFrame,\n",
" rate: pd.DataFrame,\n",
" first_date: str,\n",
" last_date: str,\n",
" figsize: list = [12, 6],\n",
"):\n",
"\n",
" fig, ax = plt.subplots(figsize=figsize)\n",
" first_date_dt = pd.to_datetime(first_date)\n",
" last_date_dt = pd.to_datetime(last_date)\n",
" rate = rate.loc[first_date: last_date]\n",
" rate = rate.loc[first_date:last_date]\n",
" if infl is not None:\n",
" infl = infl.loc[first_date: last_date]\n",
" ax.plot(infl.index.to_timestamp(), infl * 100, color ='blue', linewidth = 2, label='12-month inflation')\n",
" ax.plot(rate.index.to_timestamp(), rate * 100, color ='green', linewidth = 2, label='Key rate')\n",
" infl = infl.loc[first_date:last_date]\n",
" ax.plot(infl.index.to_timestamp(), infl * 100, color=\"blue\", linewidth=2, label=\"12-month inflation\")\n",
" ax.plot(rate.index.to_timestamp(), rate * 100, color=\"green\", linewidth=2, label=\"Key rate\")\n",
"\n",
" ax.set_xlim(first_date_dt, last_date_dt + pd.DateOffset(months=1))\n",
"\n",
" # set tickers format\n",
" years = mdates.YearLocator()\n",
" years_fmt = mdates.DateFormatter('%Y')\n",
" years_fmt = mdates.DateFormatter(\"%Y\")\n",
" ax.xaxis.set_major_locator(years)\n",
" ax.xaxis.set_major_formatter(years_fmt)\n",
"\n",
" ax.legend(loc='upper left')\n",
" ax.set_ylabel('rate, %')"
" ax.legend(loc=\"upper left\")\n",
" ax.set_ylabel(\"rate, %\")"
],
"metadata": {
"collapsed": false
Expand All @@ -796,8 +801,8 @@
"execution_count": 76,
"outputs": [],
"source": [
"infl = ok.Inflation('USD.INFL').rolling_inflation\n",
"rates = ok.Rate('US_EFFR.RATE').values_monthly # US Federal Reserve Effective Federal Funds Rate"
"infl = ok.Inflation(\"USD.INFL\").rolling_inflation\n",
"rates = ok.Rate(\"US_EFFR.RATE\").values_monthly # US Federal Reserve Effective Federal Funds Rate"
],
"metadata": {
"collapsed": false
Expand All @@ -817,7 +822,7 @@
}
],
"source": [
"plot_infl_and_keyrate(infl=infl, rate=rates, first_date='2000-01', last_date='2020-01')"
"plot_infl_and_keyrate(infl=infl, rate=rates, first_date=\"2000-01\", last_date=\"2020-01\")"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -856,7 +861,7 @@
}
],
"source": [
"ok.symbols_in_namespace('RATIO')"
"ok.symbols_in_namespace(\"RATIO\")"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -899,7 +904,7 @@
}
],
"source": [
"cape = ok.Indicator('GBR_CAPE10.RATIO') # CAPE 10 for UK market\n",
"cape = ok.Indicator(\"GBR_CAPE10.RATIO\") # CAPE 10 for UK market\n",
"cape"
],
"metadata": {
Expand Down Expand Up @@ -973,7 +978,7 @@
}
],
"source": [
"cape_symbols = ok.symbols_in_namespace('RATIO')['symbol']\n",
"cape_symbols = ok.symbols_in_namespace(\"RATIO\")[\"symbol\"]\n",
"cape_objects = [ok.Indicator(cape) for cape in cape_symbols]\n",
"cape_df = pd.DataFrame({cape.country: cape.values_monthly for cape in cape_objects})\n",
"cape_df.plot();"
Expand Down
Loading

0 comments on commit fadf935

Please sign in to comment.