Visualization¶
See the Visualization guide.
Plots¶
plots
¶
Dark-themed, publication-quality plots for jaxfolio.
Every function returns a matplotlib Figure so callers can further customize
or save. The functions cover the portfolio workflow (weights, efficient frontier,
equity curves, drawdowns, risk contributions, correlation network, HRP
dendrogram) and the options workflow (payoff diagrams, Greeks profiles, vol
surface). Colors are drawn from the validated dark palette in :mod:.theme.
plot_weights
¶
Horizontal bar chart of portfolio weights (largest holdings on top).
Source code in src/jaxfolio/viz/plots.py
plot_efficient_frontier
¶
plot_efficient_frontier(
returns: DataFrame,
*,
n_portfolios: int = 4000,
highlight: dict[str, object] | None = None,
seed: int = 0,
) -> Figure
Monte-Carlo efficient frontier colored by Sharpe ratio.
Simulates random long-only portfolios and plots them in risk/return space,
colored by Sharpe. Optionally overlays named :class:PortfolioResult markers
passed via highlight ({label: result}).
Source code in src/jaxfolio/viz/plots.py
plot_equity_curves
¶
Overlay cumulative equity curves for several backtest results.
results maps name -> BacktestResult. Each curve is direct-labeled at
its right end so identity never relies on color alone.
Source code in src/jaxfolio/viz/plots.py
plot_drawdown
¶
Underwater (drawdown) plot for one or more backtest results.
Source code in src/jaxfolio/viz/plots.py
plot_weight_evolution
¶
Stacked-area chart of weight evolution over a backtest.
Accepts a :class:BacktestResult or a weights DataFrame (dates x assets).
Source code in src/jaxfolio/viz/plots.py
plot_risk_contributions
¶
Bar chart of each asset's risk contribution (needs ERC metadata or recompute).
Source code in src/jaxfolio/viz/plots.py
plot_correlation_network
¶
Force-directed-style correlation network via the minimum spanning tree.
Nodes are assets placed on a circle; edges are the MST of the correlation
distance, plus any strong pairwise correlations above threshold. Node
size encodes degree centrality.
Source code in src/jaxfolio/viz/plots.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
plot_dendrogram
¶
Plot the HRP linkage dendrogram from a hierarchical_risk_parity result.
Source code in src/jaxfolio/viz/plots.py
plot_correlation_heatmap
¶
Clustered correlation heatmap (diverging blue↔red), optionally reordered.
Source code in src/jaxfolio/viz/plots.py
plot_metrics_table
¶
Render a metrics comparison table as a styled dark figure.
Source code in src/jaxfolio/viz/plots.py
plot_weight_path
¶
Stacked-area chart of a planned multi-period weight path.
Period 0 is the portfolio the plan starts from (metadata["w_prev"]), so the
chart reads as "here is what I hold, here is how it changes" rather than
starting mid-trade. A long-only path renders as stacked bands; if the path
contains short positions, stacking would be meaningless and the chart falls
back to one line per asset with a zero baseline.
top_n keeps only the largest holdings by peak absolute weight and folds the
remainder into an "Other" band, which keeps a wide universe readable.
Source code in src/jaxfolio/viz/plots.py
plot_turnover_schedule
¶
Per-period trade size for a planned path, with cumulative turnover.
This is the diagnostic that shows whether execution is actually being spread: bars are the one-way turnover planned for each period and the line is the running total. A decaying bar profile is the signature of quadratic market impact; a single tall bar means the plan front-loads everything, which is the correct answer when only a proportional cost is charged.
reference_weights optionally draws the turnover a single rebalance to
some external target would cost — pass the myopic (frictionless) optimum to see
what the plan saves. Note the plan's own terminal weights are not a valid
reference: a monotone path's total turnover equals
|w_T - w_prev| identically, so comparing against it would be a tautology
rather than a measurement.
Source code in src/jaxfolio/viz/plots.py
plot_path_convergence
¶
Distance from each period's weights to the plan's terminal target.
Partial adjustment toward a fixed target should decay monotonically, so this is the quickest way to see whether a plan is gliding smoothly, has converged early (a flat tail means the horizon is longer than needed), or is still moving at the final period (the horizon is too short to finish the trade).
Source code in src/jaxfolio/viz/plots.py
plot_cost_comparison
¶
Compare execution schedules across cost assumptions.
results maps a label to a multi-period :class:PortfolioResult. Use it to
show the one genuinely counter-intuitive property of the model: a purely
proportional cost makes you trade less but gives no reason to trade later,
so its schedule spikes once and flatlines. Only quadratic impact spreads
execution across the horizon.
Source code in src/jaxfolio/viz/plots.py
multiperiod_dashboard
¶
multiperiod_dashboard(
result,
*,
comparison: dict | None = None,
reference_weights=None,
) -> Figure
Composite one-page report for a planned multi-period trajectory.
A KPI strip (horizon, total turnover, cost of the plan, smoothing bias), the
weight path, the execution schedule, and convergence to the target — with an
optional cost-regime comparison panel when comparison maps labels to other
multi-period results.
reference_weights optionally supplies an external one-shot target (the
myopic optimum is the natural choice) so the turnover KPI can report what the
plan saves. Without it that card shows how the trade was spread instead, since
the path's own terminal weights would make the comparison a tautology.
Source code in src/jaxfolio/viz/plots.py
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | |
plot_payoff
¶
Payoff-at-expiry diagram for an :class:OptionStrategy.
Profit region is shaded green, loss region red; break-even points and the reference spot are annotated.
Source code in src/jaxfolio/viz/plots.py
plot_greeks_profile
¶
plot_greeks_profile(
strategy,
*,
spot: float,
vol: float = 0.25,
rate: float = 0.0,
spread: float = 0.4,
greeks: tuple[str, ...] = (
"delta",
"gamma",
"vega",
"theta",
),
) -> Figure
Plot net position Greeks as a function of the underlying spot.
Source code in src/jaxfolio/viz/plots.py
plot_vol_surface
¶
Implied-volatility surface as a filled contour (strike x expiry -> IV).
ivs is a 2-D grid indexed [expiry, strike].
Source code in src/jaxfolio/viz/plots.py
dashboard
¶
Composite strategy-comparison report: KPI strip, equity, drawdown, frontier, table.
results maps name -> BacktestResult; highlight maps
name -> PortfolioResult for the frontier overlay. The layout is a clean
reporting grid — a headline KPI row for the best strategy (by Sharpe), the
equity and drawdown panels, and the efficient frontier beside a ranked
risk-adjusted (Sharpe) bar chart.
Source code in src/jaxfolio/viz/plots.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 | |
save
¶
Theme¶
theme
¶
Dark matplotlib theme for jaxfolio.
Colors come from a validated, colorblind-considered palette (the reference
instance of the data-viz method): a fixed categorical order applied in-sequence
(never cycled arbitrarily), a single-hue blue sequential ramp for magnitude, and
neutral ink/grid tokens tuned for the dark chart surface #1a1a19.
Import side effect: calling :func:use_dark_theme (also invoked by
jaxfolio.viz on import) registers the rcParams globally.
color
¶
Return the categorical color for series index i (fixed order).
A 9th+ series intentionally wraps — callers with many series should fold to an "Other" bucket or use small multiples rather than rely on this wrap.
Source code in src/jaxfolio/viz/theme.py
use_dark_theme
¶
Register the jaxfolio dark theme as the active matplotlib rcParams.