Skip to content

Commit 3b30b4e

Browse files
committed
linting also in notebooks
1 parent 1d4cf44 commit 3b30b4e

File tree

4 files changed

+80
-9
lines changed

4 files changed

+80
-9
lines changed

cookbook/2-Mean-Variance-Optimisation.ipynb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,23 @@
8484
},
8585
"outputs": [],
8686
"source": [
87-
"tickers = [\"MSFT\", \"AMZN\", \"KO\", \"MA\", \"COST\", \"LUV\", \"XOM\", \"PFE\", \"JPM\", \"UNH\", \"ACN\", \"DIS\", \"GILD\", \"F\", \"TSLA\"]"
87+
"tickers = [\n",
88+
" \"MSFT\",\n",
89+
" \"AMZN\",\n",
90+
" \"KO\",\n",
91+
" \"MA\",\n",
92+
" \"COST\",\n",
93+
" \"LUV\",\n",
94+
" \"XOM\",\n",
95+
" \"PFE\",\n",
96+
" \"JPM\",\n",
97+
" \"UNH\",\n",
98+
" \"ACN\",\n",
99+
" \"DIS\",\n",
100+
" \"GILD\",\n",
101+
" \"F\",\n",
102+
" \"TSLA\",\n",
103+
"]"
88104
]
89105
},
90106
{
@@ -1117,7 +1133,9 @@
11171133
"from pypfopt import DiscreteAllocation\n",
11181134
"\n",
11191135
"latest_prices = prices.iloc[-1] # prices as of the day you are allocating\n",
1120-
"da = DiscreteAllocation(weights, latest_prices, total_portfolio_value=20000, short_ratio=0.3)\n",
1136+
"da = DiscreteAllocation(\n",
1137+
" weights, latest_prices, total_portfolio_value=20000, short_ratio=0.3\n",
1138+
")\n",
11211139
"alloc, leftover = da.lp_portfolio()\n",
11221140
"print(f\"Discrete allocation performed with ${leftover:.2f} leftover\")\n",
11231141
"alloc"
@@ -6854,7 +6872,9 @@
68546872
}
68556873
],
68566874
"source": [
6857-
"ax = plotting.plot_efficient_frontier(ef, ef_param=\"risk\", ef_param_range=np.linspace(0.2, 0.5, 50), showfig=False);"
6875+
"ax = plotting.plot_efficient_frontier(\n",
6876+
" ef, ef_param=\"risk\", ef_param_range=np.linspace(0.2, 0.5, 50), showfig=False\n",
6877+
");"
68586878
]
68596879
},
68606880
{

cookbook/3-Advanced-Mean-Variance-Optimisation.ipynb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,23 @@
113113
},
114114
"outputs": [],
115115
"source": [
116-
"tickers = [\"BLK\", \"BAC\", \"AAPL\", \"TM\", \"WMT\", \"JD\", \"INTU\", \"MA\", \"UL\", \"CVS\", \"DIS\", \"AMD\", \"NVDA\", \"PBI\", \"TGT\"]"
116+
"tickers = [\n",
117+
" \"BLK\",\n",
118+
" \"BAC\",\n",
119+
" \"AAPL\",\n",
120+
" \"TM\",\n",
121+
" \"WMT\",\n",
122+
" \"JD\",\n",
123+
" \"INTU\",\n",
124+
" \"MA\",\n",
125+
" \"UL\",\n",
126+
" \"CVS\",\n",
127+
" \"DIS\",\n",
128+
" \"AMD\",\n",
129+
" \"NVDA\",\n",
130+
" \"PBI\",\n",
131+
" \"TGT\",\n",
132+
"]"
117133
]
118134
},
119135
{
@@ -1170,7 +1186,11 @@
11701186
"source": [
11711187
"# Deviation risk parity with weight bound on the first asset\n",
11721188
"ef = EfficientFrontier(mu, S)\n",
1173-
"ef.nonconvex_objective(deviation_risk_parity, ef.cov_matrix, constraints=[{\"type\": \"eq\", \"fun\": lambda w: w[0] - 0.1}])\n",
1189+
"ef.nonconvex_objective(\n",
1190+
" deviation_risk_parity,\n",
1191+
" ef.cov_matrix,\n",
1192+
" constraints=[{\"type\": \"eq\", \"fun\": lambda w: w[0] - 0.1}],\n",
1193+
")\n",
11741194
"weights = ef.clean_weights()\n",
11751195
"weights"
11761196
]

cookbook/4-Black-Litterman-Allocation.ipynb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,13 @@
620620
},
621621
"outputs": [],
622622
"source": [
623-
"bl = BlackLittermanModel(S, pi=market_prior, absolute_views=viewdict, omega=\"idzorek\", view_confidences=confidences)"
623+
"bl = BlackLittermanModel(\n",
624+
" S,\n",
625+
" pi=market_prior,\n",
626+
" absolute_views=viewdict,\n",
627+
" omega=\"idzorek\",\n",
628+
" view_confidences=confidences,\n",
629+
")"
624630
]
625631
},
626632
{
@@ -768,7 +774,14 @@
768774
"outputs": [],
769775
"source": [
770776
"# We are using the shortcut to automatically compute market-implied prior\n",
771-
"bl = BlackLittermanModel(S, pi=\"market\", market_caps=mcaps, risk_aversion=delta, absolute_views=viewdict, omega=omega)"
777+
"bl = BlackLittermanModel(\n",
778+
" S,\n",
779+
" pi=\"market\",\n",
780+
" market_caps=mcaps,\n",
781+
" risk_aversion=delta,\n",
782+
" absolute_views=viewdict,\n",
783+
" omega=omega,\n",
784+
")"
772785
]
773786
},
774787
{
@@ -942,7 +955,9 @@
942955
}
943956
],
944957
"source": [
945-
"rets_df = pd.DataFrame([market_prior, ret_bl, pd.Series(viewdict)], index=[\"Prior\", \"Posterior\", \"Views\"]).T\n",
958+
"rets_df = pd.DataFrame(\n",
959+
" [market_prior, ret_bl, pd.Series(viewdict)], index=[\"Prior\", \"Posterior\", \"Views\"]\n",
960+
").T\n",
946961
"rets_df"
947962
]
948963
},

cookbook/5-Hierarchical-Risk-Parity.ipynb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,23 @@
297297
}
298298
],
299299
"source": [
300-
"tickers = [\"BLK\", \"BAC\", \"AAPL\", \"TM\", \"WMT\", \"JD\", \"INTU\", \"MA\", \"UL\", \"CVS\", \"DIS\", \"AMD\", \"NVDA\", \"PBI\", \"TGT\"]\n",
300+
"tickers = [\n",
301+
" \"BLK\",\n",
302+
" \"BAC\",\n",
303+
" \"AAPL\",\n",
304+
" \"TM\",\n",
305+
" \"WMT\",\n",
306+
" \"JD\",\n",
307+
" \"INTU\",\n",
308+
" \"MA\",\n",
309+
" \"UL\",\n",
310+
" \"CVS\",\n",
311+
" \"DIS\",\n",
312+
" \"AMD\",\n",
313+
" \"NVDA\",\n",
314+
" \"PBI\",\n",
315+
" \"TGT\",\n",
316+
"]\n",
301317
"\n",
302318
"ohlc = yf.download(tickers, period=\"max\")\n",
303319
"prices = ohlc[\"Adj Close\"]\n",

0 commit comments

Comments
 (0)