Pictures for the Shelf

Charts for finance

The pictures phase of the finance package: payments split into interest and principal, the balance falling, percentile bands from repeated runs, yield curves and option payoffs.

Loans

amortisationChart(loan) stacks each period's interest under its principal (extra payments and a balloon count as principal), so the bar's height is what was paid. balanceChart(loan) draws the balance after each period, starting from the principal. Both take a loan from @ratmath/finance or any { schedule }; the bars are the schedule's cents, so the chart is exact.

Fan charts

fanChart(simulation) reads a simulation's bands: one row per period with its percentiles. The outer band joins the lowest and highest percentiles, the inner one the next pair, and the median is a line. The runs are seeded, so the picture is marked simulated: the same seed draws it again.

Yield curves

yieldCurveFigure(curve) draws spot rates against maturity in years, from a curve with periods, frequency and spot(k), or from points.

Payoffs at expiry

A position in calls, puts, stock and bonds has a payoff that is piecewise linear in the price SS at expiry, with kinks only at the strikes. payoffFigure(strategy) evaluates the payoff and the profit exactly at the ends of the window and at each kink, and joins them by straight lines: that is the whole graph, so the picture is exact. Break-even prices are marked.

Try itEdit the code and run it with @ratmath/graphics and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math, and SHOW(svg) draws a picture.
Ctrl/⌘ + Enter runs