
Chris Parmer
2026-11-16
SymPy demo
Symbolic math in Python, with Dash and Plotly
TL;DR
- SymPy is Python's library for symbolic math: it differentiates, integrates, simplifies and solves formulas, prints them as LaTeX, and turns them into fast NumPy functions with lambdify. OndĆej ÄertĂk started it in 2005, it's BSD-licensed and written in pure Python, and the current version is SymPy 1.14.0.
- In Dash apps, SymPy is the package for tools built around a formula: engineering calculators, pharmacokinetic models, physics and finance sensitivities, where the app shows the equation and computes with it.
- With a coding agent you don't need to know SymPy's API. You describe the math and the agent writes the diff, simplify and lambdify calls. This demo shows what's possible, the prompts we used and other apps you can build.
- Our example is Greeks Lab, an options app built with an agent that derives its formulas with SymPy and checks them against the published values for a real option chain.

What is SymPy?
Engineers, scientists and quants spend a lot of time on formulas: deriving a sensitivity, checking that a textbook expression is right, writing the same equation in Python and then again in LaTeX for a report. Each copy is a chance for a typo, and a wrong sign in a transfer function or a hedge ratio is hard to spot in a table of numbers.
SymPy keeps the formula as one object. You write the model once with symbols, and SymPy gives you its derivatives, its simplified form, its LaTeX and a vectorized NumPy function from that same object. In a Dash app, that means the equations on the screen and the numbers in the charts come from one source. Apps that work this way include:
- Engineering calculators that derive a circuit's transfer function or a beam's deflection and solve for the component sizes that meet a target.
- Pharmacology models that solve a dosing model once and let you change the dose and interval with sliders.
- Physics and chemistry tools that check units and derive rates, equilibria or orbits.
- Finance tools that derive sensitivities such as duration or option Greeks instead of copying them from a book.
What's possible
You don't need SymPy's function names to get an agent to use it, but naming them makes the code shorter and easier to check. These are the parts of SymPy that matter for apps:
- Symbols with assumptions: symbols("x y", positive=True). Telling SymPy a variable is positive lets it simplify logs and square roots.
- Derivatives and integrals: diff(expr, x), diff(expr, x, 2), mixed derivatives like diff(expr, x, y), and integrate.
- Checking identities: simplify(a - b) == 0 shows two formulas are the same. Also expand, factor and trigsimp.
- Solving: solve and solveset for closed forms, nsolve for one equation numerically, dsolve for ordinary differential equations (ODEs) such as drug concentration or circuit models.
- Series and limits: series(expr, x, 0, n) for approximations, limit for edge cases.
- Linear algebra: Matrix, .eigenvals(), .inv() and Jacobians for state-space models and sensitivities.
- Units: sympy.physics.units to convert and check dimensions.
- Output: latex(expr) for the page, lambdify(args, expr, modules=["scipy", "numpy"]) for fast arrays, and codegen for C or Fortran.
How to build a formula-driven app with SymPy
Greeks Lab is a tool an options trader or risk analyst would use. It derives the Black-76 option price and five of its sensitivities, the Greeks, with SymPy, and runs them on the Chicago Board Options Exchange (Cboe) delayed quote snapshot for SPY (the exchange-traded fund that tracks the S&P 500) at the close on November 16, 2026, with discount rates from the U.S. Treasury yield curve for the same day.
At its core are a derivative and a lambdify, which turns it into a function that takes whole NumPy arrays:
gamma_F = sp.diff(call, F, 2) # what we evaluateassert sp.simplify(gamma_F - D * phi(d1) / (F * sigma * sp.sqrt(T))) == 0 # what we showgamma = sp.lambdify((F, K, T, sigma, D), gamma_F, modules=["scipy", "numpy"])
Two tips came out of building it. Lambdify the raw derivative rather than the simplified one, because simplify can return a form that's correct but overflows on real inputs. And pass modules=["scipy", "numpy"], so erf maps to SciPy's vectorized version instead of Python's math.erf, which takes one number at a time.
Page 1: derive the formulas
The Formulas page shows the price, the formula for the Greek you pick, and a line confirming that SymPy's derivative and the textbook formula are the same expression. The chart draws that Greek across strikes for one expiry, so you can see the formula and its shape side by side.
Prompt: Build a Dash page called Formulas. With SymPy, write the Black-76 call price C = D [F N(d1) - K N(d2)] with symbols F, K, T, sigma, D (all positive) and N as (1 + erf(x/sqrt(2)))/2. Derive delta and gamma with respect to F, vega, vanna and volga with sympy.diff. Write the textbook forms with phi(d1) and check each one with sympy.simplify(derivative - textbook) == 0. Show the price and the selected Greek as LaTeX with dcc.Markdown(mathjax=True), and plot that Greek by strike for one expiry.

Higher-order Greeks cost nothing extra. Volga, the second derivative of the price with respect to volatility, is one more diff call, and SymPy confirms it matches the textbook formula.
Page 2: the volatility smile

The Smile page solves the implied volatility (IV) of every option in an expiry from its market price, using Newton's method with the lambdified price and vega on whole arrays at once. The result is the familiar equity index skew, where lower strikes trade at higher volatility, and it solves a whole expiry in milliseconds.
Prompt: Add a Smile page. Lambdify the SymPy price and vega with modules=["scipy", "numpy"]. Solve implied vol for every out-of-the-money option in an expiry with a vectorized Newton step on vega, falling back to bisection between 0.0001 and 5. Plot IV by strike (puts pink, calls purple, Cboe's IV as gray open circles) and at-the-money IV by expiry. KPI cards: ATM IV, IV at 90% and 110% of the forward, solve time.
Page 3: check against Cboe

A formula you derived yourself deserves a check against someone else's numbers. This page compares the app's IV, delta, gamma and vega with the values Cboe publishes for each option, and the median delta differs from Cboe's by 0.0017. The small gaps that remain sit in long-dated puts, where the early exercise of American-style options matters and a European model like Black-76 parts from the exchange's.
Prompt: Add a Check page that compares our IV, delta, gamma and vega with the iv, delta, gamma and vega columns in Cboe's delayed quotes JSON, for out-of-the-money options. Spot delta is the forward delta times F/S; spot gamma is the forward gamma times (F/S)^2. Scatter ours against theirs colored by days to expiry with a y = x line, and show the median and 90th percentile absolute difference.
Page 4: scenarios for a position

The Scenario page compares two ways of estimating a position's profit and loss across price moves: repricing every option with the SymPy formula, and the Taylor estimate from the Greeks that many risk systems store. The two agree for small moves and drift apart for large ones, which shows when the shortcut is good enough.
Prompt: Add a Scenario page: pick an expiry, an option and a number of contracts, and a volatility shift slider. Plot P&L across SPY moves of -12% to +12% two ways: full repricing with the lambdified price, and the second-order Taylor estimate from delta, gamma, vega, vanna and volga. Show the P&L and the Taylor error at -5% and -10%.
Other apps you can build with SymPy
- Energy: a battery degradation calculator that fits an Arrhenius model and solves for the operating temperature that meets a capacity target (solve, lambdify).
- Pharma: a dosing app that solves a one-compartment oral dose model with dsolve and shows peak concentration and time to peak as you change the dose and interval.
- Electronics: a filter designer that derives an active filter's transfer function, draws its Bode plot and solves for component values that hit a cutoff frequency (solve, Matrix).
- Structures: a beam deflection calculator that integrates the load with boundary conditions and plots deflection for a chosen section (integrate, dsolve).
- Finance: a bond analytics page that derives duration and convexity by differentiating price with respect to yield (diff, series).
- Science: an orbital calculator that checks Kepler's third law against measured exoplanet periods, with units handled by sympy.physics.units.
Lambdified functions run on the arrays covered in our NumPy demo, and our guide to Python packages for data covers the rest of the series.
What's new in SymPy 1.14
SymPy 1.14.0 came out on April 27, 2025, and it is still the current release as of November 2026. From its release notes:
- Type hints for SymPy expressions, so editors give better completion and help.
- New code generation classes for NumPy's amin, amax, minimum and maximum, and isinf for C code.
- Floats stay inside powers: (x**2 + 10.0)**2 is now kept as written instead of becoming 100.0*(0.1*x**2 + 1)**2.
- A breaking change in match and replace: patterns with bound symbols now match structurally. Use Wild symbols for bound variables.
- A deprecation: the gcd argument of Rational is deprecated and may become an error sooner than usual.
Running SymPy on Plotly Cloud and Dash Enterprise
What we learned deploying Greeks Lab privately on Plotly Cloud, which applies the same way on Dash Enterprise:
- Derive once, at startup. Derive and lambdify the formulas when the app starts, so callbacks only call NumPy functions. Keep simplify and solve out of callbacks, because they can take seconds.
- Show the derivation, not just the numbers. latex() and dcc.Markdown(mathjax=True) show the exact formula the app evaluates. When the formula changes with a dropdown, return a new dcc.Markdown with its own id, so MathJax redraws it.
- Pin sympy in requirements.txt. Small changes in how expressions are printed or simplified can change the LaTeX your users see.