I have built Manipulate to see the impact of a change in time and volatility to the profit of an option strategy, bull spread. To calculate the price of the option, I built the good old Black-Scholes:

optionValue[s0_, x_, t_, sigmasq_, rf_] := Module[{d1, d2},
d1 = (Log[s0/x] + (rf + sigmasq/2) t)/Sqrt[sigmasq t];
d2 = d1 - Sqrt[sigmasq t];
s0 CDF[NormalDistribution[], d1] - x Exp[-rf t] CDF[NormalDistribution[], d2]]

Then I call the optionValue function with


Finally, I build the Manipulate so I can plot the profit of the strategy and the profit for each option by itself with the ability to change time and volatility:

 premiumLong = premiumLongCall[tic, vol];
 premiumShort = premiumShortCall[tic, vol];

 option11[stockPrice_ /; stockPrice > 230] := 
  stockPrice - 230 - premiumLong;
 option11[stockPrice_] := -premiumLong;
 option22[stockPrice_ /; stockPrice > 270] := 
  270 - stockPrice + premiumShort;
 option22[stockPrice_] := premiumShort;

 Plot[{option11[s] + option22[s], option11[s], option22[s]}, {s, 170, 
   320}, PlotLabel -> "Bull spread", 
  AxesLabel -> {"Stock price", "Profit"}, ImageSize -> Large, 
  PlotLegends -> {"Total profit", "Long call profit", 
    "Short call profit"}, PlotTheme -> "Working", 
  PlotStyle -> {Blue, Dashed, Dashed}], {{tic, 0.5}, {0.5, 
   5/12}}, {{vol, 0.35}, {0.35, 0.2625}}]

I get the plot but Mathematica enters into an eternal loop.

I checked this link but I am having trouble relocating the functions outside of Manipulate while keeping tic and vol inside.

I have also tried using Module like here but then my plot looks incomplete.

Please let me know how to best redesign this code to stop the endless evaluation loop.

Thanks in advance, Thad


1 Answer 1


Adding TrackedSymbols :> {tic, vol} to Manipulate's options helps a lot.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.