Skip to main content

Making the Black-Scholes Formula Accessible for SoME4

· 5 mins
Manim Black-Scholes Video Github
Ryan Gibson
Author
Ryan Gibson
Quantitative Analyst | Computer Scientist
Table of Contents

For the fourth Summer of Math Exposition, I chose to reimagine “A Simple Derivation of the Black-Scholes Option Pricing Formula” as a more detailed, Manim-animated YouTube video.

It’s structured as a self-contained lesson that walks through a complete derivation of the Black-Scholes-Merton formula in a way that’s accessible to anyone with knowledge of calculus-based probability and statistics. No financial background is needed.

I also included 6 exercises with hints and sample solutions to encourage working through the derivation on your own.

The source code for these animations is available at https://github.com/ragibson/manim-videos

Key differences from the original post
#

There are several notable improvements over the original post:

  • I introduced the financial background on stocks and options to keep it accessible to a broad audience.
  • Instead of presenting geometric Brownian motion / the lognormal distribution as an assumption of the Black-Scholes model, I build it up from first principles by motivating the properties we’d like our simulation to have.
  • All exercises were expanded with more detailed (and sometimes simpler) solutions and hints where they’d be most useful.
  • I included a final visualization of the pricing formula to build intuition for how the calculation behaves in general and how each parameter impacts the final result.
  • Being a video, a lot of the content includes significantly more color and exposition than the original.

The rest of this post covers my thoughts on this project.

Thoughts on Manim
#

This was my first time using the Manim package, and I was reasonably impressed.

The usage of the codebase is mostly consistent and has some nice overarching themes surrounding how all the objects and functions interact with each other. This is much better than some popular Python packages (cough pandas cough).

Moreover, the community edition has pretty good documentation and a large collection of helpful examples to get started. There are some functions that remain undocumented, and I had to dig through the source code to get a handful of the animations working the way I wanted, but I admit some of my usage was a bit unorthodox.

Especially since this is a community effort that forked a one-man personal project, that’s quite incredible!

The very general animation mechanisms also seem extremely powerful. I made the mistake at first of treating this like a simple plotting library and writing ad-hoc code that would be used once and never looked at again.

The strengths of the library didn’t become clear until I started treating it as a much more integrated system that can animate properties of classes with arbitrarily complicated internal state.

Ultimately for Manim, the code and animations are the main product whereas in most other cases they’re more of a side consideration (e.g., research papers, supplementary figures in presentations, etc.).

Video production is insanely intensive
#

This project took significantly more time than I had expected – I wasn’t tracking it precisely, but I believe it was easily over 100 hours of work.

As such, there are parts I wish I could have polished more or animated more extravagantly, but I’m happy overall with the end result.

Similarly, video production is much more computationally expensive than I’d realized. I’ve worked with large batches of video encoding in the past but usually left them running overnight or in the background. In this case, the encoding itself is often the bottleneck of the creative pipeline, so you feel every second of it.

On a moderately powerful consumer desktop, each end-to-end render of this video required:

  • ~2 hours of render time from Manim1
  • ~7 minutes of ffmpeg conversions
  • ~18 minutes for DaVinci Resolve to export the final timeline into a video

Two and a half hours of waiting time on a fresh run is enormous! I had to do this several times in the final editing process to make sure everything was to my liking.

DaVinci Resolve’s Linux support is finicky
#

This was also the first time I ran DaVinci Resolve fully on Linux, which is a bit of a pain.

Their Linux release requires a very recent version of Nvidia’s proprietary driver to run, which was a bit of a surprise. Other GPUs (AMD, integrated, etc.) are simply not supported.

It also didn’t support my distro perfectly, asking for impossible sets of dependencies, so I had to resort to an unofficial script to convert it into a package that could be installed properly.

On top of this, it doesn’t support most video codecs! Anything remotely common like MP4s are out the window because the official implementations carry licensing fees and Blackmagic Design doesn’t seem willing to allow free, open-source alternatives.2

This is why my workflow ended up including an ffmpeg conversion step. I had to convert Manim’s video output into the Avid DNxHR LB codec.

This is apparently a “low-quality” professional codec, and it creates truly enormous files. Despite my video having perhaps ~10 minutes of actual moving animations, the raw files totalled ~37 GB in size (more than 8x the final render)!

Voiceover is difficult
#

The workflow I settled on involved:

  • Watching the rendered animations
  • Writing a rough script of what I intended to talk about
  • Reading this script and recording in Audacity (perhaps while looking at a key part of the relevant animation)
  • Aligning the timing of the animations and voiceover in post

I think this is how most of these voiceovers get produced, but I’m more used to doing this sort of thing in front of a live audience, so it wasn’t the most natural process.

There is a Manim Voiceover plugin that lets you add voiceovers directly into the rendered Manim animation. However, it didn’t seem particularly common, suggested prototyping with text-to-speech engines, and required some extra Manim classes, so it didn’t seem worth the effort.

Indeed, I’d done some video editing in the past, so I thought I would prefer the extra control of doing all the post-production myself.

See also and references
#

For more information, see the following resources.


  1. Manim is not particularly well optimized, so render times can be quite long in general. Luckily, it is slightly faster on repeat runs since it caches some of the LaTeX, animations, etc. ↩︎

  2. Realistically, this might get them into legal trouble, so it is a reasonable (but still painful) constraint. ↩︎

Related

A Simple Derivation of the Black-Scholes Option Pricing Formula
·· 8 mins
Black-Scholes Option-Pricing Derivation Statistics
A straightforward derivation of the famous option pricing formula using only basic probability and statistics. No stochastic calculus required!
Animated Cellular Automaton QR Codes
· 6 mins
Qr-Codes Cellular-Automata Video
An experiment in using randomized cellular automata to generate QR codes that remain valid on every frame.
Steganography: Hiding Data Inside Data
·· 7 mins
Steganography Programming Github Cybersecurity
A general introduction to hiding information in plain sight, its uses in the real-world, and how it works in digital mediums.