### Install Quantflow Source: https://github.com/quantmind/quantflow/blob/main/docs/index.md Install the Quantflow library using pip. This command installs the base package. ```bash pip install quantflow ``` -------------------------------- ### Install quantflow with data extra Source: https://github.com/quantmind/quantflow/blob/main/docs/api/data/index.md Install the quantflow library with the optional 'data' extra to enable data fetching capabilities. ```bash pip install quantflow[data] ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/quantmind/quantflow/blob/main/docs/contributing.md Install the necessary development dependencies using the provided Makefile. ```bash make install-dev ``` -------------------------------- ### Install Quantflow with ML Dependencies Source: https://github.com/quantmind/quantflow/blob/main/docs/index.md Install Quantflow with optional dependencies for training the Deep Implied Volatility model. This command includes the 'ml' extra. ```bash pip install quantflow[ml] ``` -------------------------------- ### Two-Factor BNS Calibration Example Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/bns_calibration.md Demonstrates how to calibrate the two-factor BNS model using provided data. It initializes the model with specific parameters and fits it to implied volatility data. ```python import pandas as pd from quantflow.options.calibration.bns import BNS2Calibration from quantflow.options.calibration.calibration import Calibration # Load implied volatility data data = pd.read_csv("../data/vol_surface.csv") # Initialize BNS2Calibration calibrator = BNS2Calibration( data, v01=0.01, v02=0.01, theta=0.5, beta=0.5, kappa2=0.1, kappa_delta=0.5, rho1=-0.5, rho2=-0.5, w=0.5, ) # Perform calibration calibrator.fit() # Print calibrated parameters print(calibrator.params) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/yield-curve.md Imports required modules for API calls, plotting, and data manipulation. Ensure these libraries are installed and accessible. ```javascript import {fetchJson} from "./lib/api.js"; import * as Plot from "npm:@observablehq/plot"; import * as d3 from "npm:d3"; ``` -------------------------------- ### Initialize Inputs for Double Exponential Sampling Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Sets up input ranges for the logarithm of the asymmetry parameter (kappa) and the number of samples. These inputs control the simulation parameters. ```javascript const deLogKappaInput = Inputs.range([-2, 2], {step: 0.1, value: 0.1, label: "log(κ) asymmetry"}); const deLogKappa = Generators.input(deLogKappaInput); const deSamplesInput = Inputs.range([100, 10000], {step: 100, value: 1000, label: "Samples"}); const deSamples = Generators.input(deSamplesInput); ``` -------------------------------- ### Invert Wiener Process Characteristic Function using FFT Source: https://github.com/quantmind/quantflow/blob/main/docs/theory/inversion.md This example demonstrates how to invert the characteristic function of the Wiener process to obtain the standard normal distribution using the Fast Fourier Transform (FFT). It requires the 'fft.py' script to be available. ```python --8<-- "docs/examples/fft.py" ``` -------------------------------- ### Initialize and use Deribit client Source: https://github.com/quantmind/quantflow/blob/main/docs/api/data/index.md Initialize the Deribit client as an asynchronous context manager and retrieve a volatility surface loader. Ensure the client is used within an async context. ```python from quantflow.data.deribit import Deribit async with Deribit() as cli: loader = await cli.volatility_surface_loader("btc") ``` -------------------------------- ### Clone the Quantflow Repository Source: https://github.com/quantmind/quantflow/blob/main/docs/contributing.md Clone the official quantflow repository to your local machine to begin development. ```bash git clone git@github.com:quantmind/quantflow.git ``` -------------------------------- ### Define Default and Input Rates Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/yield-curve.md Sets up the initial default interest rates and creates a mutable state variable `inputRates` to hold the rates that can be modified by the user. ```javascript const defaultRates = [ {ttm: 1/365, rate: 0.043}, {ttm: 7/365, rate: 0.043}, {ttm: 1/12, rate: 0.044}, {ttm: 0.25, rate: 0.045}, {ttm: 0.5, rate: 0.046}, {ttm: 1, rate: 0.047}, {ttm: 2, rate: 0.043}, {ttm: 3, rate: 0.041}, {ttm: 5, rate: 0.040}, {ttm: 7, rate: 0.041}, {ttm: 10, rate: 0.043}, {ttm: 20, rate: 0.048}, {ttm: 30, rate: 0.049} ]; const inputRates = Mutable(defaultRates); const setInputRates = (v) => inputRates.value = v; ``` -------------------------------- ### Gaussian (Vasicek) Process Input Controls Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Sets up interactive input controls for the Gaussian (Vasicek) process simulation, including mean reversion speed (kappa), number of samples, and an option for antithetic variates. ```javascript const gKappaInput = Inputs.range([0.1, 5], {step: 0.1, value: 1.0, label: "kappa"}); const gKappa = Generators.input(gKappaInput); const gSamplesInput = Inputs.range([100, 10000], {step: 100, value: 1000, label: "Samples"}); const gSamples = Generators.input(gSamplesInput); const gAntitheticInput = Inputs.toggle({label: "Antithetic variates", value: true}); const gAntithetic = Generators.input(gAntitheticInput); ``` -------------------------------- ### Select Pricing Method Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/pricing_method_comparison.md Instantiate an OptionPricer with a specified pricing method. Requires importing OptionPricer, OptionPricingMethod, and the relevant model (e.g., Heston). ```python from quantflow.options.pricer import OptionPricer, OptionPricingMethod from quantflow.sp.heston import Heston model = Heston.create(vol=0.2) pricer = OptionPricer(model=model, method=OptionPricingMethod.COS) result = pricer.maturity(1.0) ``` -------------------------------- ### Run Tests Source: https://github.com/quantmind/quantflow/blob/main/docs/contributing.md Execute the test suite to ensure the codebase is functioning correctly. ```bash make tests ``` -------------------------------- ### Vasicek Process Kappa Input Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/hurst.md Creates an input range for the kappa (mean reversion) parameter for the Vasicek process simulation. Higher kappa indicates stronger mean reversion. ```javascript const kappaInput = Inputs.range([1, 500], {step: 1, value: 10, label: "Kappa (mean reversion)"}); const kappa = Generators.input(kappaInput); ``` -------------------------------- ### Display Gaussian Input Controls Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Renders the input controls for the Gaussian process simulation in a flexible layout. ```javascript display(html`
${gKappaInput}${gSamplesInput}${gAntitheticInput}
`); ``` -------------------------------- ### Import Fred Module Source: https://github.com/quantmind/quantflow/blob/main/docs/api/data/fred.md Import the Fred class from the quantflow data module. ```python from quantflow.data.fred import Fred ``` -------------------------------- ### Inspect Surface Inputs (Python) Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/volatility_surface.md Load and display the inputs of a volatility surface, including forward prices, interest rates, and option bid/ask prices with implied volatilities. ```python --8<-- "docs/examples/vol_surface_inputs.py" ``` -------------------------------- ### Import Yahoo Client Source: https://github.com/quantmind/quantflow/blob/main/docs/api/data/yahoo.md Import the Yahoo client module for use in your project. This is the primary entry point for interacting with Yahoo Finance data. ```python from quantflow.data.yahoo import Yahoo ``` -------------------------------- ### Display Poisson Input Controls Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Renders the input controls for the Poisson process simulation in a flexible layout. ```javascript display(html`
${pIntensityInput}${pSamplesInput}
`); ``` -------------------------------- ### Fetch Volatility Surface Loader from Deribit Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/volatility_surface.md Use the Deribit client to fetch option quotes for a given asset and assemble them into a VolSurfaceLoader. This is the initial step for building a volatility surface. ```python import asyncio from quantflow.data.deribit import Deribit async def load(): async with Deribit() as cli: loader = await cli.volatility_surface_loader("btc") return loader loader = asyncio.run(load()) ``` -------------------------------- ### Import necessary modules Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/heston-vol-surface.md Imports the fetchJson function for API calls and the Plot module for charting. ```javascript import {fetchJson} from "./lib/api.js"; import * as Plot from "npm:@observablehq/plot"; ``` -------------------------------- ### Poisson Process Input Controls Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Sets up interactive input controls for the Poisson process simulation, including intensity (lambda) and the number of samples. ```javascript const pIntensityInput = Inputs.range([2, 20], {step: 0.1, value: 2.0, label: "Intensity (λ)"}); const pIntensity = Generators.input(pIntensityInput); const pSamplesInput = Inputs.range([100, 10000], {step: 100, value: 1000, label: "Samples"}); const pSamples = Generators.input(pSamplesInput); ``` -------------------------------- ### Kalman Filter Initialization and Usage Source: https://github.com/quantmind/quantflow/blob/main/docs/theory/kalman.md Initialize a KalmanFilter with a LinearGaussianModel and use its filter method to process observations. This returns filtered states and log-likelihood. ```python from quantflow.ta.kalman import KalmanFilter, LinearGaussianModel model = LinearGaussianModel(F=..., Q=..., H=..., R=...) kf = KalmanFilter(model) states, log_lik = kf.filter(observations, dt) ``` -------------------------------- ### Import FederalReserve Class Source: https://github.com/quantmind/quantflow/blob/main/docs/api/data/fed.md Import the FederalReserve class from the quantflow.data.fed module. This is the initial step to access Federal Reserve data. ```python from quantflow.data.fed import FederalReserve ``` -------------------------------- ### Inspect Surface Inputs (Output) Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/volatility_surface.md View the output format for inspecting volatility surface inputs, showing option details and their corresponding implied volatilities. ```text --8<-- "docs/examples/output/vol_surface_inputs.out" ``` -------------------------------- ### Import FMP Module Source: https://github.com/quantmind/quantflow/blob/main/docs/api/data/fmp.md Import the FMP class from the quantflow data module. This is the primary way to access FMP data functionalities. ```python from quantflow.data.fmp import FMP ``` -------------------------------- ### Fetch Gaussian Sampling Data Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Fetches simulation data for the Gaussian process from the API, using the current values of kappa, samples, and antithetic variates. A short delay is introduced before fetching. ```javascript await new Promise(r => setTimeout(r, 300)); const gaussianData = await fetchJson(`/.api/gaussian-sampling?kappa=${gKappa}&samples=${gSamples}&antithetic=${gAntithetic}`); ``` -------------------------------- ### Import Deribit Module Source: https://github.com/quantmind/quantflow/blob/main/docs/api/data/deribit.md Import the Deribit class from the quantflow data module to access Deribit API functionalities. ```python from quantflow.data.deribit import Deribit ``` -------------------------------- ### Display Input Controls Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Renders the input controls for 'log(κ) asymmetry' and 'Samples' in a horizontal layout. This allows users to interact with the parameters. ```javascript display(html`
${deLogKappaInput}${deSamplesInput}
`); ``` -------------------------------- ### Populate Implied Volatilities Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/volatility_surface.md Use the Black-Scholes model to populate implied volatilities by inverting option prices. This process marks each option as converged or not. ```python surface.bs() ``` -------------------------------- ### Initialize CIR Process and Check Feller Condition Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/cir.md Instantiate a CIR process with specified parameters and print its Feller condition status. The Feller condition ensures the process remains strictly positive. ```python from quantflow.sp.cir import CIR cir = CIR(kappa=2.0, theta=0.5, sigma=0.8, rate=1.0) print(cir.feller_condition) # positive: process stays strictly positive print(cir.is_positive) ``` -------------------------------- ### Unscented Kalman Filter Initialization and Usage Source: https://github.com/quantmind/quantflow/blob/main/docs/theory/kalman.md Initialize an UnscentedKalmanFilter with a model and specific sigma-point parameters. Use its filter method to process observations, returning filtered states and log-likelihood. ```python from quantflow.ta.kalman import UnscentedKalmanFilter ukf = UnscentedKalmanFilter(model, alpha=1e-3, beta=2.0, kappa=0.0) states, log_lik = ukf.filter(observations, dt) ``` -------------------------------- ### Display Vasicek Process Statistics Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/hurst.md Displays Hurst exponent estimates calculated from the Vasicek process, showing how mean reversion affects the exponent. ```javascript display(html`
Hurst (realized): ${vasicek.hurst_realized.toFixed(4)}
Hurst (Parkinson): ${vasicek.hurst_pk.toFixed(4)}
Hurst (Garman-Klass): ${vasicek.hurst_gk.toFixed(4)}
Hurst (Rogers-Satchell): ${vasicek.hurst_rs.toFixed(4)}
`); ``` -------------------------------- ### black_vega Source: https://github.com/quantmind/quantflow/blob/main/docs/api/options/black.md Calculates the Black-Scholes vega for an option. ```APIDOC ## black_vega ### Description Calculates the Black-Scholes vega for an option. ### Method Not specified (likely a function call in a library) ### Endpoint Not applicable (function within a library) ### Parameters Not specified in the provided text. ### Request Example Not applicable. ### Response Not specified in the provided text. ``` -------------------------------- ### Download Input Data Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/volatility-surface.md Provides a button to download the raw input data used for generating the volatility surface as a JSON file. This is useful for debugging or further analysis. ```javascript const downloadInputs = () => { const blob = new Blob([JSON.stringify(data.inputs, null, 2)], {type: "application/json"}); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `volsurface_${asset}_${d3.utcFormat("%Y%m%d_%H%M%S")(refDate)}.json`; a.click(); URL.revokeObjectURL(url); }; display(html``); ``` -------------------------------- ### Build Volatility Surface Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/volatility_surface.md Construct a VolSurface object from the loaded market data. This object will hold the raw data and methods for further processing. ```python surface = loader.surface() ``` -------------------------------- ### Display Vasicek Process Kappa Input Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/hurst.md Displays the kappa input slider to the user. ```javascript display(kappaInput); ``` -------------------------------- ### Asset Selection Input Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/volatility-surface.md Creates a dropdown input for selecting the asset (e.g., BTC, ETH, SPY). The selected value is made available for use in subsequent operations. ```javascript const assetInput = Inputs.select(["BTC", "ETH", "SPY", "AAPL", "NVDA"], {label: "Asset", value: "BTC"}); const asset = Generators.input(assetInput); ``` -------------------------------- ### SpotInput Source: https://github.com/quantmind/quantflow/blob/main/docs/api/options/vol_surface.md Input related to the spot price for surface construction. ```APIDOC ## SpotInput ### Description Input parameter specifically for the spot price of the underlying asset. ### Class quantflow.options.inputs.SpotInput ``` -------------------------------- ### BNS Calibration Output Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/bns_calibration.md Displays the calibrated parameters for the BNS model, including initial variance, long-run variance, mean reversion speed, jump-size distribution decay rate, and leverage parameter. Shows the fit quality across different maturities. ```text BNS Calibration ============= Model: BNS Parameters: v0: 0.020169 theta: 0.040000 kappa: 0.000000 beta: 0.500000 rho: -0.700000 Fit: RMSD: 0.003456 MaxAbsErr: 0.008765 Implied Volatility Surface Fit: Maturities: [0.083333, 0.25, 0.5, 1.0, 2.0, 3.0, 5.0] RMSD: [0.003456, 0.003456, 0.003456, 0.003456, 0.003456, 0.003456, 0.003456] MaxAbsErr: [0.008765, 0.008765, 0.008765, 0.008765, 0.008765, 0.008765, 0.008765] ``` -------------------------------- ### Price Option with Black-Scholes and Validate Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/option_pricing.md Prices a European option using the Black-Scholes model and validates the results against the analytical Black formula. Ensure the implied volatility, deltas, and gammas match the model's output within numerical precision. ```python --8<-- "docs/examples/wiener_volatility_pricer.py" ``` -------------------------------- ### Configure Plotting Scales and SVG Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/yield-curve.md Sets up the dimensions, margins, and scales (linear/log for x-axis, linear for y-axis) for the plot. It also creates the SVG container and appends axis elements. ```javascript const width = 640; const height = 400; const marginTop = 30; const marginRight = 20; const marginBottom = 40; const marginLeft = 50; const allRates = inputRates.map(d => d.rate); const rateMin = Math.min(...allRates); const rateMax = Math.max(...allRates); const padding = Math.max((rateMax - rateMin) * 0.2, 0.005); const yMin = rateMin - padding; const yMax = rateMax + padding; const x = (xScaleType === "linear" ? d3.scaleLinear().domain([0, 32]) : d3.scaleLog().domain([1/365, 32])) .range([marginLeft, width - marginRight]); const y = d3.scaleLinear() .domain([yMin, yMax]) .range([height - marginBottom, marginTop]); const svg = d3.create("svg") .attr("width", width) .attr("height", height) .attr("viewBox", [0, 0, width, height]) .attr("style", "max-width: 100%; height: auto;"); svg.append("g") .attr("transform", `translate(0,${height - marginBottom}) .call(d3.axisBottom(x) .tickValues(xScaleType === "linear" ? [0, 1, 2, 5, 10, 15, 20, 25, 30] : [1/365, 1/52, 1/12, 0.25, 0.5, 1, 2, 5, 10, 30]) .tickFormat(d => d === 0 ? "0" : d < 1/12 ? `${Math.round(d*365)}d` : d < 1 ? `${Math.round(d*12)}m` : `${d}y`) ) .append("text") .attr("x", width / 2) .attr("y", 35) .attr("fill", "currentColor") .attr("text-anchor", "middle") .text("Time to Maturity (years)"); svg.append("g") .attr("transform", `translate(${marginLeft},0)`) .call(d3.axisLeft(y).tickFormat(d3.format(".1%"))) .append("text") .attr("x", -marginLeft + 10) .attr("y", marginTop - 15) .attr("fill", "currentColor") .attr("text-anchor", "start") .text("Rate"); ``` -------------------------------- ### Display Asset Input Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/volatility-surface.md Renders the asset selection input element in the UI. ```javascript display(assetInput); ``` -------------------------------- ### Download Input Rates as JSON Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/yield-curve.md Generates a JSON file containing the current input rates and initiates a download. This is useful for saving or sharing the rate data. ```javascript const downloadRates = () => { const blob = new Blob([JSON.stringify(inputRates, null, 2)], {type: "application/json"}); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `rates_${curveType}.json`; a.click(); URL.revokeObjectURL(url); }; display(html``); ``` -------------------------------- ### Display Reference Date and Spot Price Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/volatility-surface.md Formats and displays the reference date and the calculated mid-point spot price. This provides context for the volatility surface data. ```javascript const refDate = new Date(data.inputs.quote_curve.ref_date); const formatDate = d3.utcFormat("%d %b %Y %H:%M:%S UTC"); display(html`

${formatDate(refDate)} · Spot: ${spotMid ? d3.format(",.0f")(spotMid) : "N/A"} USD · ${enriched.length} options across ${maturities.length} maturities

`); ``` -------------------------------- ### Fetch Vasicek Process Data Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/hurst.md Fetches Vasicek process data from the API based on the selected kappa value. A short delay is included before fetching. ```javascript await new Promise(r => setTimeout(r, 300)); const vasicek = await fetchJson(`/.api/hurst-vasicek?kappa=${kappa}`); ``` -------------------------------- ### Fetch Poisson Sampling Data Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Fetches simulation data for the Poisson process from the API, using the current values of intensity and number of samples. A short delay is introduced before fetching. ```javascript await new Promise(r => setTimeout(r, 300)); const poissonData = await fetchJson(`/.api/poisson-sampling?intensity=${pIntensity}&samples=${pSamples}`); ``` -------------------------------- ### Black-Scholes Option Pricing Output Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/option_pricing.md Displays the output of the Black-Scholes option pricing, including price, delta, gamma, and implied Black volatility. ```json --8<-- "docs/examples/output/wiener_volatility_pricer.out" ``` -------------------------------- ### BNS2 Calibration Output Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/bns_calibration.md Displays the calibrated parameters for the two-factor BNS model, including initial variance, decay rates, and leverages. ```text v01: 0.01 v02: 0.01 theta: 0.5 beta: 0.5 kappa2: 0.1 kappa_delta: 0.5 rho1: -0.5 rho2: -0.5 w: 0.5 ``` -------------------------------- ### CIR PDF Comparison and Characteristic Function Analysis Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/cir.md This snippet, included via a "code include" directive, likely contains Python code for comparing the analytical PDF of a CIR process with one derived from its characteristic function, and potentially visualizes the characteristic function itself. It is intended for detailed analysis of the CIR model's behavior over different time horizons. ```python --8<-- "docs/examples/cir_pdf_comparison.py" ``` -------------------------------- ### VolSurfaceLoader Source: https://github.com/quantmind/quantflow/blob/main/docs/api/options/vol_surface.md Base class or specific implementation for loading volatility surfaces. ```APIDOC ## VolSurfaceLoader ### Description Abstract or concrete class responsible for the process of loading volatility surface data. ### Class quantflow.options.surface.VolSurfaceLoader ``` -------------------------------- ### Calibrate and Plot BNS Smile Source: https://github.com/quantmind/quantflow/blob/main/docs/tutorials/bns_calibration.md This Python script calibrates the BNS volatility model to an implied volatility surface and plots the resulting calibrated smile. It requires the quantflow library and uses a specific output file for calibration results. ```python import matplotlib.pyplot as plt from quantflow.options.calibration.bns import BNSCalibration from quantflow.options.calibration.base import VolModelCalibration # Load implied volatility surface data # For demonstration, assume surface_data is loaded from a file or generated # surface_data = ... # Instantiate BNSCalibration calibrator = BNSCalibration() # Perform calibration calibrator.fit(surface_data) # Print calibration results to a file calibrator.save("docs/examples/output/vol_surface_bns_calibration.out") # Plot the calibrated smile fig, ax = plt.subplots() calibrator.plot(ax=ax) plt.show() ``` -------------------------------- ### GenericVolSurfaceLoader Source: https://github.com/quantmind/quantflow/blob/main/docs/api/options/vol_surface.md A generic loader for volatility surfaces, capable of handling various input formats. ```APIDOC ## GenericVolSurfaceLoader ### Description Provides a generic interface for loading volatility surfaces from different data sources or formats. ### Class quantflow.options.surface.GenericVolSurfaceLoader ``` -------------------------------- ### Plot Vasicek Process Path Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/hurst.md Visualizes the simulated Vasicek process path over time. This plot helps to observe the mean-reverting behavior. ```javascript const vasicekPath = vasicek.dates.map((d, i) => ({date: new Date(d), value: vasicek.values[i]})); display(Plot.plot({ width: 800, height: 350, marginLeft: 60, marginBottom: 50, style: {background: "transparent"}, x: {label: "Time", type: "utc"}, y: {label: "Value"}, marks: [ Plot.line(vasicekPath, {x: "date", y: "value", stroke: "var(--theme-foreground-focus)", strokeWidth: 1.5}), ] })); ``` -------------------------------- ### Plot Gaussian Process Simulation vs. Analytical Distribution Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/sampling.md Visualizes the simulated and analytical probability densities for the Gaussian process using Plot.js. It also displays the Kolmogorov-Smirnov test statistic and p-value if available. ```javascript const gBarData = gaussianData.x.map((x, i) => ({x, y: gaussianData.simulation[i], series: "Simulation"})); const gLineData = gaussianData.x.map((x, i) => ({x, y: gaussianData.analytical[i], series: "Analytical"})); const gBinWidth = gaussianData.x[1] - gaussianData.x[0]; display(Plot.plot({ width: 800, height: 450, marginLeft: 60, marginBottom: 50, style: {background: "transparent"}, x: {label: "Value"}, y: {label: "Density"}, color: {legend: true, domain: ["Simulation", "Analytical"], range: ["var(--theme-foreground-muted)", "var(--theme-foreground-focus)"]}, marks: [ Plot.rectY(gBarData, {x1: d => d.x - gBinWidth / 2, x2: d => d.x + gBinWidth / 2, y: "y", fill: "series", fillOpacity: 0.6, tip: true}), Plot.line(gLineData, {x: "x", y: "y", stroke: "series", strokeWidth: 2}), ] })); if (gaussianData.ks_statistic != null) { const ksColor = gaussianData.ks_pvalue < 0.05 ? "var(--theme-red)" : "var(--theme-green)"; display(html`

KS statistic: ${gaussianData.ks_statistic.toFixed(4)}  |  p-value: ${gaussianData.ks_pvalue.toFixed(4)}

`); } ``` -------------------------------- ### OptionInput Source: https://github.com/quantmind/quantflow/blob/main/docs/api/options/vol_surface.md A general input for option-related data. ```APIDOC ## OptionInput ### Description Generic input class for option-specific data used in surface calculations. ### Class quantflow.options.inputs.OptionInput ``` -------------------------------- ### Define interactive input controls Source: https://github.com/quantmind/quantflow/blob/main/frontend/src/heston-vol-surface.md Sets up various input controls (select, range) for model parameters like volatility, correlation, and jump characteristics. These controls allow users to dynamically adjust the model inputs. ```javascript const modelInput = Inputs.select(new Map([["Jump Diffusion", "jd"], ["Heston with Jumps", "hj"]]), {label: "Model", value: "jd"}); const modelVal = Generators.input(modelInput); const volInput = Inputs.range([0.1, 0.8], {step: 0.01, value: 0.4, label: "Long term volatility"}); const volVal = Generators.input(volInput); const sigmaInput = Inputs.range([0.1, 2], {step: 0.1, value: 0.5, label: "Vol of vol"}); const sigmaVal = Generators.input(sigmaInput); const kappaInput = Inputs.range([0.1, 2], {step: 0.1, value: 0.5, label: "Variance mean reversion"}); const kappaVal = Generators.input(kappaInput); const rhoInput = Inputs.range([-0.6, 0.6], {step: 0.1, value: 0, label: "Correlation"}); const rhoVal = Generators.input(rhoInput); const rInput = Inputs.range([0.6, 1.6], {step: 0.1, value: 1.0, label: "Initial vol ratio"}); const rVal = Generators.input(rInput); const jfInput = Inputs.range([0.1, 0.9], {step: 0.05, value: 0.5, label: "Jump fraction"}); const jfVal = Generators.input(jfInput); const jiInput = Inputs.range([10, 100], {step: 5, value: 10, label: "Jump intensity"}); const jiVal = Generators.input(jiInput); const jaInput = Inputs.range([-2, 2], {step: 0.1, value: 0, label: "Jump asymmetry"}); const jaVal = Generators.input(jaInput); ``` -------------------------------- ### OptionPrices Source: https://github.com/quantmind/quantflow/blob/main/docs/api/options/vol_surface.md Container for multiple option prices. ```APIDOC ## OptionPrices ### Description Holds a collection of OptionPrice objects. ### Class quantflow.options.surface.OptionPrices ```