As promised, here is now a snippet of the code or the free Option Payoff utility that you have downloaded.
This can be useful in case you wish to write your own "calculator". I will give you the code that I wrote to compute the value of any option (this plugin can accommodate unlimited options of any kind).
I think you may like it because this code can compute ANY option, independent of it being a CALL or PUT, or long or short.
That is, it unifies all cases into a unique one. The function could be made more compact obviously, but I wrote it this way for greater clarity.
where clearly:
This can be useful in case you wish to write your own "calculator". I will give you the code that I wrote to compute the value of any option (this plugin can accommodate unlimited options of any kind).
I think you may like it because this code can compute ANY option, independent of it being a CALL or PUT, or long or short.
That is, it unifies all cases into a unique one. The function could be made more compact obviously, but I wrote it this way for greater clarity.
Code:
public double Funct(double X)
{
if (this.PositionSignedMultiplied == 0)
return 0;
double GainLossAtX = this.PutSignInvertor * (X - this.Strike) * this.PositionSignedMultiplied;
double Y = Premium;
if (this.PutSignInvertor * X >= this.PutSignInvertor * Strike)
Y += GainLossAtX;
return Y;
}
where clearly:
Code:
this.PositionSignedMultiplied = this.PositionSigned * this.Multiplier;
this.TransactionPrice = (double)Interaction.IIf(this.PositionSigned < 0, this.PriceBID, this.PriceASK);
this.Premium = -this.TransactionPrice * this.PositionSignedMultiplied;
this.PutSignInvertor = (int)Interaction.IIf(this.IsPutOption, -1, 1);
Last edited:
