P/L graphs
POST /calculate returns the grid behind the calculator's chart: profit or loss
for a range of stock prices on each date up to expiry.
Request a grid
Same body as /pop, plus an optional price range and volatility shift. It counts as 2 requests.
curl -X POST https://www.optionsprofitcalculator.com/api/v1/calculate \
-H "Authorization: Bearer $OPC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"legs": [
{"type": "call", "action": "buy", "strike": 345, "expiry": "2026-12-18"},
{"type": "call", "action": "sell", "strike": 360, "expiry": "2026-12-18"}
],
"priceMin": 320,
"priceMax": 380
}'import os
import requests
r = requests.post(
"https://www.optionsprofitcalculator.com/api/v1/calculate",
json={
"symbol": "AAPL",
"legs": [
{"type": "call", "action": "buy", "strike": 345, "expiry": "2026-12-18"},
{"type": "call", "action": "sell", "strike": 360, "expiry": "2026-12-18"}
],
"priceMin": 320,
"priceMax": 380
},
headers={"Authorization": "Bearer " + os.environ["OPC_API_KEY"]},
)
data = r.json()
if not data["success"]:
raise RuntimeError(data["error"]["message"])
print(data["data"])const res = await fetch("https://www.optionsprofitcalculator.com/api/v1/calculate", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPC_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"symbol": "AAPL",
"legs": [
{"type": "call", "action": "buy", "strike": 345, "expiry": "2026-12-18"},
{"type": "call", "action": "sell", "strike": 360, "expiry": "2026-12-18"}
],
"priceMin": 320,
"priceMax": 380
}),
});
const { success, data, error } = await res.json();
if (!success) throw new Error(error.message);
console.log(data);function callOpcApi() {
const key = PropertiesService.getScriptProperties().getProperty('OPC_API_KEY');
const body = {
"symbol": "AAPL",
"legs": [
{"type": "call", "action": "buy", "strike": 345, "expiry": "2026-12-18"},
{"type": "call", "action": "sell", "strike": 360, "expiry": "2026-12-18"}
],
"priceMin": 320,
"priceMax": 380
};
const res = UrlFetchApp.fetch('https://www.optionsprofitcalculator.com/api/v1/calculate', {
method: 'post',
contentType: 'application/json',
headers: { Authorization: 'Bearer ' + key },
payload: JSON.stringify(body),
muteHttpExceptions: true,
});
const json = JSON.parse(res.getContentText());
if (!json.success) throw new Error(json.error.message);
return json.data;
}The grid
graph.prices: the stock prices (columns).graph.dates: the dates (rows), each withdaysFromTodayandatExpiry. The first row isn't necessarily today; the last is the earliest expiry.graph.profitLoss[d][p]: dollars if you close atprices[p]ondates[d].graph.expiry.profitLoss: the expiry row on its own, for a classic payoff diagram.
Chart it
A heatmap of profitLoss (green for profit, red for loss) looks like the calculator's table. A line chart of
graph.expiry.profitLoss against graph.prices is the payoff at expiry.
import matplotlib.pyplot as plt
g = data["graph"]
plt.plot(g["prices"], g["expiry"]["profitLoss"], label="At expiry")
plt.plot(g["prices"], g["profitLoss"][0], label=g["dates"][0]["date"])
plt.axhline(0, color="grey", linewidth=0.5)
plt.xlabel("Stock price")
plt.ylabel("Profit / loss ($)")
plt.legend()
plt.show()What-if volatility
Set ivChange to shift every leg's implied volatility, e.g. -10 to see the effect of a volatility crush after earnings.