<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: NandanDivate</title>
    <description>The latest articles on DEV Community by NandanDivate (@nandandivate).</description>
    <link>https://dev.to/nandandivate</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4242219%2F5cc1f8ae-e647-48b7-920f-bb684525aac1.png</url>
      <title>DEV Community: NandanDivate</title>
      <link>https://dev.to/nandandivate</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nandandivate"/>
    <language>en</language>
    <item>
      <title>Building STRIKEWISE: Engineering an Options Pricing Engine with Python and SciPy</title>
      <dc:creator>NandanDivate</dc:creator>
      <pubDate>Fri, 13 Nov 2026 05:50:46 +0000</pubDate>
      <link>https://dev.to/nandandivate/building-strikewise-engineering-an-options-pricing-engine-with-python-and-scipy-2i9l</link>
      <guid>https://dev.to/nandandivate/building-strikewise-engineering-an-options-pricing-engine-with-python-and-scipy-2i9l</guid>
      <description>&lt;p&gt;Options trading involves more than predicting whether an underlying index will move up or down.&lt;/p&gt;

&lt;p&gt;A change in the underlying price, implied volatility, interest rates, and time to expiry can all affect an option's theoretical premium.&lt;/p&gt;

&lt;p&gt;I wanted to build a project that explored these relationships mathematically while also applying practical software engineering concepts.&lt;/p&gt;

&lt;p&gt;That led me to build STRIKEWISE, an open-source quantitative options pricing and risk engine focused on NIFTY 50 options.&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/NandanDivate/STRIKEWISE" rel="noopener noreferrer"&gt;https://github.com/NandanDivate/STRIKEWISE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Live API: &lt;a href="https://strikewise-4mxr.onrender.com/docs" rel="noopener noreferrer"&gt;https://strikewise-4mxr.onrender.com/docs&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The problem I wanted to solve&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Consider this scenario:&lt;/p&gt;

&lt;p&gt;You hold a NIFTY 24,500 Call option.&lt;/p&gt;

&lt;p&gt;You want to understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What could its theoretical premium become if NIFTY reaches 24,700?&lt;/li&gt;
&lt;li&gt;How might the premium change under different implied volatility assumptions?&lt;/li&gt;
&lt;li&gt;How much does time decay affect the option?&lt;/li&gt;
&lt;li&gt;What underlying spot price would be required for the option to reach a particular premium?&lt;/li&gt;
&lt;li&gt;What would the projected P&amp;amp;L and ROI look like?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions involve multiple variables. Simply applying a fixed percentage to the current option premium does not capture the relationship between the underlying price, volatility, and time.&lt;/p&gt;

&lt;p&gt;I built STRIKEWISE to model these relationships using the Black-Scholes-Merton framework.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The mathematical foundation: Black-Scholes-Merton&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At the core of STRIKEWISE is the European Black-Scholes-Merton (BSM) pricing model with continuous dividend yield.&lt;/p&gt;

&lt;p&gt;The model estimates theoretical Call and Put option premiums using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Underlying spot price (S)&lt;/li&gt;
&lt;li&gt;Strike price (K)&lt;/li&gt;
&lt;li&gt;Time to expiry (T)&lt;/li&gt;
&lt;li&gt;Risk-free interest rate (r)&lt;/li&gt;
&lt;li&gt;Dividend yield (q)&lt;/li&gt;
&lt;li&gt;Annualized volatility (σ)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model uses:&lt;/p&gt;

&lt;p&gt;[&lt;br&gt;
d_1 = \frac{\ln(S/K)+(r-q+\sigma^2/2)T}{\sigma\sqrt{T}}&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;[&lt;br&gt;
d_2=d_1-\sigma\sqrt{T}&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;The Call and Put prices are calculated as:&lt;/p&gt;

&lt;p&gt;[&lt;br&gt;
C=Se^{-qT}N(d_1)-Ke^{-rT}N(d_2)&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;[&lt;br&gt;
P=Ke^{-rT}N(-d_2)-Se^{-qT}N(-d_1)&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;One important implementation decision was using the ACT/365 day-count convention.&lt;/p&gt;

&lt;p&gt;Instead of treating time to expiry as an approximate number of calendar days divided by 365, STRIKEWISE uses timezone-aware time calculations based on elapsed seconds.&lt;/p&gt;

&lt;p&gt;This helps account for intraday time differences and calendar transitions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Analytical Greeks: Understanding price sensitivity&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Calculating an option premium is only one part of the problem.&lt;/p&gt;

&lt;p&gt;I also implemented five analytical Greeks to understand how the theoretical premium responds to changes in different market variables.&lt;/p&gt;

&lt;p&gt;Greek| What it measures&lt;br&gt;
Delta| Sensitivity to underlying price&lt;br&gt;
Gamma| Rate of change of Delta&lt;br&gt;
Theta| Time decay per calendar day&lt;br&gt;
Vega| Sensitivity to a 1 percentage-point IV change&lt;br&gt;
Rho| Sensitivity to a 1 percentage-point interest-rate change&lt;/p&gt;

&lt;p&gt;An important implementation detail was documenting the units consistently.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Theta is expressed per calendar day.&lt;/li&gt;
&lt;li&gt;Vega represents the premium change for a 1 percentage-point implied volatility shift.&lt;/li&gt;
&lt;li&gt;Rho represents the premium change for a 1 percentage-point interest-rate shift.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This avoids ambiguity when interpreting the results.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reverse-solving the underlying price using Brent's method&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One of the more interesting engineering challenges was implementing an inverse pricing calculation.&lt;/p&gt;

&lt;p&gt;Most pricing models answer:&lt;/p&gt;

&lt;p&gt;"What is the theoretical option premium at this underlying spot price?"&lt;/p&gt;

&lt;p&gt;I also wanted STRIKEWISE to answer:&lt;/p&gt;

&lt;p&gt;"What underlying spot price is required for the option to reach my target premium?"&lt;/p&gt;

&lt;p&gt;This is a numerical root-finding problem.&lt;/p&gt;

&lt;p&gt;I implemented SciPy's Brent root-finding method to solve for the underlying spot price corresponding to a target option premium.&lt;/p&gt;

&lt;p&gt;The implementation includes dynamic geometric bracketing and handles unattainable targets, including the upper price boundary for Put options.&lt;/p&gt;

&lt;p&gt;The solver uses a numerical tolerance of (10^{-8}).&lt;/p&gt;

&lt;p&gt;This was particularly interesting because the problem is not simply about evaluating a formula. It requires finding a valid numerical solution while accounting for the behaviour and limits of the pricing function.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Implied volatility scenario analysis&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Future implied volatility is uncertain.&lt;/p&gt;

&lt;p&gt;A projected underlying price alone does not tell the entire story because the option premium can change significantly when volatility changes.&lt;/p&gt;

&lt;p&gt;STRIKEWISE provides three volatility scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conservative: Current IV minus 2 percentage points.&lt;/li&gt;
&lt;li&gt;Base: Current IV.&lt;/li&gt;
&lt;li&gt;Optimistic: Current IV plus 2 percentage points.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It also includes automatic lower-bound handling to prevent invalid volatility inputs.&lt;/p&gt;

&lt;p&gt;These scenarios are assumptions for comparison, not predictions of future volatility.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Designing the software architecture&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I wanted the project to be usable in two different ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;As a reusable Python library.&lt;/li&gt;
&lt;li&gt;As an asynchronous REST API.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To support both, I used a layered modular monolith architecture.&lt;/p&gt;

&lt;p&gt;The main components are:&lt;/p&gt;

&lt;p&gt;API Layer&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FastAPI endpoints.&lt;/li&gt;
&lt;li&gt;Pydantic v2 request validation.&lt;/li&gt;
&lt;li&gt;HTTP-level error handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Service Layer&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Coordinates pricing calculations.&lt;/li&gt;
&lt;li&gt;Handles scenario comparisons.&lt;/li&gt;
&lt;li&gt;Orchestrates time calculations and P&amp;amp;L estimation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pricing Engine&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Black-Scholes-Merton implementation.&lt;/li&gt;
&lt;li&gt;Analytical Greeks.&lt;/li&gt;
&lt;li&gt;Numerical root solver.&lt;/li&gt;
&lt;li&gt;Pure mathematical functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Market Data Layer&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abstract provider interface.&lt;/li&gt;
&lt;li&gt;Offline manual input adapter.&lt;/li&gt;
&lt;li&gt;DhanHQ API v2 provider adapter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The separation keeps HTTP handling, business orchestration, mathematical calculations, and market data access from becoming tightly coupled.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Two ways to use STRIKEWISE&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Option A: Python library&lt;/p&gt;

&lt;p&gt;The library can be installed directly from GitHub:&lt;/p&gt;

&lt;p&gt;pip install git+&lt;a href="https://github.com/NandanDivate/STRIKEWISE.git" rel="noopener noreferrer"&gt;https://github.com/NandanDivate/STRIKEWISE.git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;import strikewise&lt;/p&gt;

&lt;p&gt;call = strikewise.call_price(&lt;br&gt;
    spot=24450,&lt;br&gt;
    strike=24500,&lt;br&gt;
    time_to_expiry_years=0.05,&lt;br&gt;
    risk_free_rate=0.07,&lt;br&gt;
    dividend_yield=0.012,&lt;br&gt;
    volatility=0.14&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;print(f"Call Premium: ₹{call:.2f}")&lt;/p&gt;

&lt;p&gt;Greeks can also be calculated directly:&lt;/p&gt;

&lt;p&gt;greeks = strikewise.calculate_greeks(&lt;br&gt;
    spot=24450,&lt;br&gt;
    strike=24500,&lt;br&gt;
    time_to_expiry_years=0.05,&lt;br&gt;
    risk_free_rate=0.07,&lt;br&gt;
    dividend_yield=0.012,&lt;br&gt;
    volatility=0.14,&lt;br&gt;
    option_type="CE"&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;print("Delta:", greeks.delta)&lt;br&gt;
print("Gamma:", greeks.gamma)&lt;br&gt;
print("Theta/day:", greeks.theta_per_day)&lt;br&gt;
print("Vega:", greeks.vega)&lt;br&gt;
print("Rho:", greeks.rho)&lt;/p&gt;

&lt;p&gt;This allows developers to integrate the pricing engine directly into Python scripts, research workflows, and backtesting systems without making HTTP requests.&lt;/p&gt;

&lt;p&gt;Option B: FastAPI REST API&lt;/p&gt;

&lt;p&gt;For developers who prefer HTTP-based integration, STRIKEWISE also exposes its functionality through a REST API.&lt;/p&gt;

&lt;p&gt;The API supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Option pricing and estimation.&lt;/li&gt;
&lt;li&gt;Greeks calculation.&lt;/li&gt;
&lt;li&gt;Scenario analysis.&lt;/li&gt;
&lt;li&gt;Target premium calculations.&lt;/li&gt;
&lt;li&gt;P&amp;amp;L and ROI projections.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interactive documentation is available through Swagger:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://strikewise-4mxr.onrender.com/docs" rel="noopener noreferrer"&gt;https://strikewise-4mxr.onrender.com/docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The project is deployed on Render and also supports Docker-based deployment.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Testing and validation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A mathematical implementation needs more than a few successful example calculations.&lt;/p&gt;

&lt;p&gt;I added automated unit and integration tests to cover the pricing engine, numerical solver, API workflows, and edge cases.&lt;/p&gt;

&lt;p&gt;The test run produced:&lt;/p&gt;

&lt;p&gt;Metric| Result&lt;br&gt;
Tests passed| 75&lt;br&gt;
Total statements| 675&lt;br&gt;
Overall coverage| 89%&lt;br&gt;
Execution time| 4.27 seconds&lt;/p&gt;

&lt;p&gt;The coverage report also helped identify modules that need additional testing.&lt;/p&gt;

&lt;p&gt;For example, the numerical solver currently has lower coverage than the scenario analysis module. That gives me a concrete direction for future improvements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Technology stack&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.12&lt;/li&gt;
&lt;li&gt;FastAPI&lt;/li&gt;
&lt;li&gt;SciPy&lt;/li&gt;
&lt;li&gt;NumPy&lt;/li&gt;
&lt;li&gt;Pydantic v2&lt;/li&gt;
&lt;li&gt;Pytest&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Render&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The project is released under the Apache 2.0 license.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Limitations and future possibilities&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;STRIKEWISE currently uses the European Black-Scholes-Merton model.&lt;/p&gt;

&lt;p&gt;That comes with important assumptions and limitations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Theoretical premiums are not guaranteed executable market prices.&lt;/li&gt;
&lt;li&gt;Actual market prices can differ due to liquidity, bid-ask spreads, market microstructure, and changing volatility.&lt;/li&gt;
&lt;li&gt;The volatility scenarios are hypothetical assumptions.&lt;/li&gt;
&lt;li&gt;The engine does not guarantee profitable trades or generate trading signals.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is plenty of room to explore additional pricing models, more market data integrations, and further quantitative risk analysis.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Building STRIKEWISE gave me an opportunity to work at the intersection of software engineering, numerical methods, and quantitative finance.&lt;/p&gt;

&lt;p&gt;More importantly, it helped me understand how mathematical models can be translated into reusable software components and accessible APIs.&lt;/p&gt;

&lt;p&gt;The project is open source, and I would genuinely appreciate technical feedback, suggestions, and contributions.&lt;/p&gt;

&lt;p&gt;Explore STRIKEWISE:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/NandanDivate/STRIKEWISE" rel="noopener noreferrer"&gt;https://github.com/NandanDivate/STRIKEWISE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Live Swagger API: &lt;a href="https://strikewise-4mxr.onrender.com/docs" rel="noopener noreferrer"&gt;https://strikewise-4mxr.onrender.com/docs&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you work with Python, quantitative finance, derivatives, or numerical computing, I'd be interested in hearing what you think.&lt;/p&gt;




&lt;p&gt;Disclaimer: STRIKEWISE is an educational and quantitative research project. Its outputs are theoretical estimates based on stated model assumptions, not financial advice or guarantees of market execution or profit.&lt;/p&gt;

&lt;h1&gt;
  
  
  Python #QuantitativeFinance #OptionsPricing #FastAPI #BlackScholes #SciPy #OpenSource #FinTech
&lt;/h1&gt;

</description>
      <category>python</category>
      <category>finance</category>
      <category>opensource</category>
      <category>fastapi</category>
    </item>
  </channel>
</rss>
