options-math

A Java library for European option pricing and Greeks calculation using the Black-Scholes model.

View on GitHub


Overview

options-math provides financial calculations for European options trading, including theoretical pricing based on the Black-Scholes model, Greeks (risk sensitivities), and profit/loss analysis.


Features

Option Pricing:

  • Theoretical prices for call and put options
  • Based on spot price, strike price, time to maturity, interest rates, and volatility

Greeks Calculation:

  • Delta — Price sensitivity to underlying asset changes
  • Gamma — Delta’s rate of change
  • Vega — Volatility sensitivity
  • Theta — Time decay effect
  • Rho — Interest rate sensitivity

Profit/Loss Analysis:

  • Realized gains or losses at expiration
  • Accounts for premium paid/received
  • Supports both buy and sell positions

Installation

Maven:

<dependency>
    <groupId>com.druvu</groupId>
    <artifactId>options-math</artifactId>
    <version>1.0.1</version>
</dependency>

Gradle:

implementation 'com.druvu:options-math:1.0.1'

Usage

Option Pricing

OptionPriceRequest request = new OptionPriceRequest(
    OptionType.CALL,    // Option type
    100.0,              // Spot price
    105.0,              // Strike price
    0.25,               // Time to maturity (years)
    0.05,               // Risk-free rate
    0.20                // Volatility
);

double price = OptionCalculator.calculatePrice(request);

Greeks Calculation

Greeks greeks = OptionCalculator.calculateGreeks(request);

double delta = greeks.getDelta();
double gamma = greeks.getGamma();
double vega = greeks.getVega();
double theta = greeks.getTheta();
double rho = greeks.getRho();

Profit/Loss Calculation

ProfitLossRequest plRequest = new ProfitLossRequest(
    OptionSide.CALL,    // Call or Put
    Position.BUY,       // Buy or Sell
    105.0,              // Strike price
    3.50,               // Premium paid
    10                  // Number of contracts
);

double profitLoss = OptionCalculator.calculateProfitLoss(plRequest, spotAtExpiry);

License

Apache License 2.0



Back to top

Copyright © 2026 druvu.com. All rights reserved.

This site uses Just the Docs, a documentation theme for Jekyll.