Skip to main content

A package containing algorithms to compute higher order moments implied from option prices.

Project description

English 日本語

Option Implied Moments

This repository contains code to compute option implied, or risk-neutral, higher moments from stock option data. Stock return characteristics like volatility, skewness, and kurtosis are computed based on out-of-the-money stock option contracts under risk-neutral measure $\mathbb{Q}$.

Risk-neutral volatility, skewness, and kurtosis are estimated from a cross-section of out-of-the-money calls and puts following [1]:

$$ Var^{\mathbb{Q}} = \frac{e^{r\tau}V_{i,t} - \mu^{2}}{\tau}, $$ $$ Skew^{\mathbb{Q}} = \frac{e^{r\tau}W - 3\mu e^{r\tau}V + 2\mu^{3}}{[e^{r\tau}V-\mu^{2}]^{3/2}}, $$ $$ Kurt^{\mathbb{Q}} = \frac{e^{r\tau}X - 4\mu e^{r\tau}W + 6e^{r\tau}\mu^{2}V - 3\mu^{4}}{[e^{r\tau}V-\mu^{2}]^{2}} - 3 $$

where

$$ \mu = e^{r\tau} - 1 - \frac{e^{r\tau}}{2}V - \frac{e^{r\tau}}{6}W - \frac{e^{r\tau}}{24}X $$

$V$, $W$, and $X$ are the expected squared, cubed and fourth-power log of the stock return during the period from $t$ to time $t + \tau$ under measure $\mathbb{Q}$; $r$ is the continuously compounded risk-free rate for the same period. To estimate these parameters, we follow the trapezoidal implementation from [2] to use discrete strike prices from calls and put options. Please refer to Appendix B of the paper for the formalised implementation details.

Programming Implementation Details

The library is implemented in three layers.

Note: This library works best with implied volatility surface data from data providers like WRDS.

C layer

All numerical work is done in pure C:

  • Normal CDF — approximated using complementary error function:

$$ \Phi(x) = 0.5 \times \text{erfc}(\frac{-x}{\sqrt(2)}) $$

  • Black-Scholes pricing — OTM option prices are computed from implied volatilities using the standard closed-form formula.
  • Trapezoidal integration — calls and puts are sorted by strike, priced, and integrated separately using the trapezoidal rule following [2].

Cython layer

The Cython layer functions as a bridge between NumPy and the C extension. It accepts flat contiguous NumPy arrays in a CSR (compressed sparse row) layout. Strikes, implied volatilities, and flags concatenated across all groups, with an indptr array marking the boundary of each group.

Groups are then processed in parallel using OpenMP.

Python layer

The Python layer is responsible for data preparation only. It filters OTM options, encodes call/put flags as integers, sorts and groups the data by stock and time period, and assembles the CSR layout that the Cython layer expects. After the Cython call returns, it reconstructs the output as a Polars DataFrame.

References

[1] Bakshi, G., Kapadia, N., & Madan, D. (2003). Stock return characteristics, skew laws, and the differential pricing of individual equity options. The Review of Financial Studies, 16(1), 101-143.

[2] Bali, Turan G. and Hu, Jianfeng and Murray, Scott, Option Implied Volatility, Skewness, and Kurtosis and the Cross-Section of Expected Stock Returns (January 1, 2019). Georgetown McDonough School of Business Research Paper, Available at SSRN: https://ssrn.com/abstract=2322945 or http://dx.doi.org/10.2139/ssrn.2322945

Getting Started

Installation

pip install option-implied-moments

Wheels are available for Python 3.11–3.13 on Linux, macOS, and Windows. No C compiler or CMake required.

Development Installation

For contributing or modifying the C/Cython extensions, you need CMake and a C compiler. On macOS, also install Homebrew's LLVM for OpenMP support:

brew install llvm libomp

Clone the repository and build:

git clone https://github.com/justkroft/option-implied-moments.git
cd option-implied-moments
make install
make build

Without make, set up your uv environment and make a local install:

uv pip install scikit-build-core numpy
uv pip install --no-build-isolation -e . -Ccmake.build-type=Release

OpenMP Threading

The library uses OpenMP for parallel computation across groups. You can control the number of threads:

from option_implied_moments.ext.omp_utils import get_max_threads, set_num_threads

max_threads = get_max_threads()
print(f"Available threads: {max_threads}")

set_num_threads(8)  # Use 8 threads

Please take a look at the example notebook for an example of how to use the library.

License

MIT License © 2026-PRESENT justkroft

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

option_implied_moments-1.0.0.tar.gz (180.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

option_implied_moments-1.0.0-cp313-cp313-win_amd64.whl (213.6 kB view details)

Uploaded CPython 3.13Windows x86-64

option_implied_moments-1.0.0-cp313-cp313-win32.whl (198.0 kB view details)

Uploaded CPython 3.13Windows x86

option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (298.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl (301.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ i686

option_implied_moments-1.0.0-cp313-cp313-macosx_15_0_arm64.whl (451.0 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

option_implied_moments-1.0.0-cp312-cp312-win_amd64.whl (213.8 kB view details)

Uploaded CPython 3.12Windows x86-64

option_implied_moments-1.0.0-cp312-cp312-win32.whl (198.1 kB view details)

Uploaded CPython 3.12Windows x86

option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (299.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (301.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

option_implied_moments-1.0.0-cp312-cp312-macosx_15_0_arm64.whl (451.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

option_implied_moments-1.0.0-cp311-cp311-win_amd64.whl (215.0 kB view details)

Uploaded CPython 3.11Windows x86-64

option_implied_moments-1.0.0-cp311-cp311-win32.whl (197.7 kB view details)

Uploaded CPython 3.11Windows x86

option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (300.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (304.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

option_implied_moments-1.0.0-cp311-cp311-macosx_15_0_arm64.whl (450.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

File details

Details for the file option_implied_moments-1.0.0.tar.gz.

File metadata

  • Download URL: option_implied_moments-1.0.0.tar.gz
  • Upload date:
  • Size: 180.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for option_implied_moments-1.0.0.tar.gz
Algorithm Hash digest
SHA256 84a6d70d82b4794e5433049ce727013af80d42029faee886205965208c0404e6
MD5 547142cf6070efccc74bbb1e3f885afa
BLAKE2b-256 43ec4ae0395aad55f68b055c9b524b5187871dcc84cd0402be3c831a8630e9ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0.tar.gz:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9d17ca3703deb14f97d812499f44c40c27961740e8f14f47babf0b3cf74fa7e9
MD5 755f886f7584c936ac64c85b24a09d2b
BLAKE2b-256 d574454758d7187f7ae0b0a127e84267cc39ca65eb7aa4582726afb65dc8081f

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp313-cp313-win_amd64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp313-cp313-win32.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 52cd38cbf8474be7233addb4b70a134faaaef04dc206b18a660ed0d8dc19cf6d
MD5 504ebe42c99b92528d3cd9a92f54ed5f
BLAKE2b-256 d8e9aa850e943460826bffd40257e5f8d9b7407fa1498bf455063c2bce8a361d

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp313-cp313-win32.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af5e42aa0e211e997cd7ca043e3d04ec25feef06e06e73a9fe58d1021660d859
MD5 0ab60db8694fb66347c01174722fb6c5
BLAKE2b-256 a281f230b0c6dba07443a1ca857289e800c33fcb3bfa9a0893948fa3a68246ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8eb8cfc5cfd97830acf696ef250d494110535715cf680cb950167692ce046b38
MD5 79548e7cf68bc810b17bd54b4ed48fd7
BLAKE2b-256 fed417de7c5b4c733cf4b0ede9d6e75bf8bd1f275369de9e285dd111b69af0e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 11d597ff4a202c27c1abbf1f3254790ffeebab909f52f3c87f41c7715a9dc58c
MD5 b6c6ae6a8e2e10a8a16d616467f5b08c
BLAKE2b-256 eca14f3201dc922db6d7e48f5af0cdedee04dc44a1a76fe634f7db80de4b762d

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp313-cp313-macosx_15_0_arm64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2aff5dcf3d974b088a599e8da2e49c2884e4b6b86b907798b1d6ac5af977a4a7
MD5 e024f727ffe1f166c427ffdff6f32620
BLAKE2b-256 7ed994993061d15fbf809655aa301d2b98e6343cd9c043ff66769568649faa6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp312-cp312-win_amd64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 77c26eb185b2fc03fce3739cdc69405c48872c7159186a439549acf769e657f3
MD5 db41f8233cb396e4b3e6d8ba2701d8d4
BLAKE2b-256 5089aa671ce5e0b2cb99327b62fbcd4eb3d31691fc12a6daa65d2a922d6622a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp312-cp312-win32.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee32bcfcd3a36ae216e4d39a442a8ebe3a3a0fbe45c105efdb4149ef24dd3b3c
MD5 6202746b7696d0e785761334866fe669
BLAKE2b-256 af41b6f9bade9e479c1653e70129874f0db82c7cccfed2b1fcbf42a1283cdb6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 63cd87079720861766026e93914dc3b3230c92d14b62454c18b0ed8f40b233b4
MD5 56141058497cf6684458e94050d4548f
BLAKE2b-256 bd0606958ac6b4604903b84eb1ae29ba6024d5d0ea5cc0656d78db8a9dd1ee8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9825ca8adfe5935a312acf715470f37502bde2d777f7f16a686ad95c2ee4dd73
MD5 d2afa415e84a3cf1f173ba956112c57f
BLAKE2b-256 fa57c6d17f67a8250867ec70709c927396853a1ae56a1e8d5db3bc914d6d5989

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp312-cp312-macosx_15_0_arm64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 963a52ab6b58667b6cb89f7b8c249ca1ba590c28b623ff40c470c0da681c6b8a
MD5 4d18cf9d822d39c13971920690d2d668
BLAKE2b-256 948836fd63aec437003151eaf498f2393421a60429af354f6b09de35ca981415

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp311-cp311-win_amd64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 aaf6bbf90ad0b9350496a8cdad5e7bf9c128ac14521c46e525b10f6c5803d7e8
MD5 41fe115509ebe38d1754e9205ecd9bc4
BLAKE2b-256 673c876bb2ae63ebdaf8440fa4372170ea70585856f307448a5e2dbbf2c7c98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp311-cp311-win32.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 67f9c9ea7ce238736ee2427c8b7bea3806a9459782771867a4a2c25898236a61
MD5 dadeebd16412f7379e7380b0d967f508
BLAKE2b-256 7f4313a680cd4bb2057417240c84f4a52736db915cbfcb2689cb12c61f2661ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8bd07f477ede8e0ca5638de5d92a4ef50893d875560d22dd76af55db2171bf85
MD5 64d8044df75c296c5f04831225e898c7
BLAKE2b-256 ddfef6f53ae2b7166765f3e03595066d548c9204e03efe3377aee7672d02c226

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file option_implied_moments-1.0.0-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for option_implied_moments-1.0.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 3c2800d95fbbcf2d0ae819ae08316c859d117cf1736e244937eb046fb1d0e3fb
MD5 d8bb898de538f2d07bfbe8d6698601fd
BLAKE2b-256 5063227923c1439b8ba6271adb9bb25fbd6696df4397b197c11b3178fb806287

See more details on using hashes here.

Provenance

The following attestation bundles were made for option_implied_moments-1.0.0-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: cd.yml on justkroft/option-implied-moments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page