Skip to main content

A library for mock quantitative trading exercises.

Project description

CardQuant 🃏 Quantitatively

CardQuant is a Python library designed for simulating and analyzing scenarios related to trading games. It currently features two main classes:

  • Figgie: for the Jane Street Figgie game
  • CardValuation: for IMC’s mock trading game involving options on the sum of drawn cards

Features

  • Figgie Game Analysis Calculate probabilities related to the Figgie card game.
  • Card Sum Options Valuation Simulate a game where options are based on the sum of n drawn cards, and calculate their theoretical values and associated Greeks.

Installation

pip install cardquant

Core Classes

Figgie

The Figgie class provides utilities for the Jane Street Figgie card game.

  • Primary function: Calculate the probability of achieving the goal suit based on a given starting hand and game state.

CardValuation

The CardValuation class simulates drawing n cards from a deck and pricing European‑style options on the final sum.

  • Outputs:

    • Theo: theoretical option values
    • Greeks: Delta, Gamma, Theta, Charm, Color

Key Concepts & Parameters

When creating a CardValuation instance, you can specify:

Parameter Description
n Total number of cards to be drawn
deck List representing the deck (e.g. list(range(1,14))*4 for a standard deck)
strike_list List of strike prices for which options will be valued
seen_cards List of cards already drawn and known
with_replacement True to draw with replacement, False otherwise
calculate_all_greeks True to compute all Greeks (Theo, Delta, Gamma, Theta, Charm, Color); False for (Theo, Delta)

After instantiation or any state change (e.g. via add_card), the instance exposes:

  • options: dict mapping each strike to an object with Call/Put valuations (Theo + Greeks)
  • future: expected final sum of the n cards given the current state

Public Methods

  • add_card(new_card: int) Adds new_card to seen_cards (validates availability and total count), then recalculates future, all Theos, and Greeks.

Greeks Explained

  • Delta (Δ) Probability of the option expiring in the money.

    • Call Δ = P(final sum > K)
    • Put Δ = −P(final sum < K)
  • Gamma (Γ) Rate of change of Delta with respect to the strike:

    $$ \Gamma \approx \frac{\bigl|\Delta(K+1) - \Delta(K-1)\bigr|}{2} $$

  • Time Greeks (interpreted as drawing one more card):

    • Theta (Θ): change in Theo if one more card (expected value) is drawn
    • Charm (ψ): change in Delta under the same “one more card” move
    • Color (χ): change in Gamma under the same “one more card” move

Usage Example

from cardquant import CardValuation

# initialize the pricing engine
# note that the values here are the default values used for IMC's mock trading
# nonetheless, the ability to alter them is given in the event slight changes are made to the mock
pricing_engine = CardValuation(
    n=10,
    seen_cards=[],
    strike_list=list(range(50,91,10)),
    deck=list(range(1,14))*4,
    with_replacement=False,
    calculate_all_greeks=True
)

print(pricing_engine)

# access the numerical value for the future
print(pricing_engine.future)

# access the numerical value for a particular attribute of an option strike
# by pricing_enging.options[strike].(call/put).(theo/greek)
print(pricing_engine.options[50].call.theo)
print(pricing_engine.options[50].put.delta)
print(pricing_engine.options[70].call.theta)

# Add a new card and recalc
pricing_engine.add_card(5)
print("\nAfter adding card 5:")
print(game)

Contributing

Contributions are welcome!

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature-name)
  3. Commit your changes (git commit -m 'Add feature')
  4. Push to the branch (git push origin feature-name)
  5. Open a Pull Request

Please adhere to the existing code style and include tests where appropriate.


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

cardquant-0.1.10.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

cardquant-0.1.10-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file cardquant-0.1.10.tar.gz.

File metadata

  • Download URL: cardquant-0.1.10.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for cardquant-0.1.10.tar.gz
Algorithm Hash digest
SHA256 8d6761a697aa5e29ce37f1a0606e52fb5aec99e303028dee358eb84bd0e5e8d1
MD5 c33e9849b1619ef748effcc26583527f
BLAKE2b-256 fea888097181bac9417b9eaf70dbcc7b1a6bf3021e03277301ecc8f2f5605fce

See more details on using hashes here.

File details

Details for the file cardquant-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: cardquant-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for cardquant-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 460158c3f071985f9aba45dc79e69c923e4fc482591a79656532d0649aec57d0
MD5 08f9b366960d33b67974937907c44612
BLAKE2b-256 88afc4716cbb623d70766da39812fc6a9e177b7b9e2d12dfe68b4b837a675aad

See more details on using hashes here.

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