public void FillCalculatedFields(TradingAccount tradingAccount) { this.Quantity = (int)Math.Ceiling(tradingAccount.TradeSize / this.ContractAsk); #region Delta this.DeltaPL = ((this.Bid + (tradingAccount.ExpectedPriceChange * this.Delta)) * this.Quantity * 100m) - (19.98m + (this.Quantity * tradingAccount.RoundTripCommission)) - (this.Quantity * this.ContractAsk); this.DeltaPLPercent = this.DeltaPL / (this.Quantity * this.ContractAsk); #endregion #region Black Scholes this.BlackScholesPrice = this.CalculateBlackScholesPrice(tradingAccount, this.UnderlyingPrice); this.BlackScholesPriceTarget = this.CalculateBlackScholesPrice(tradingAccount, this.UnderlyingPrice + (this.OptionType == OptionTypes.Call ? tradingAccount.ExpectedPriceChange : -tradingAccount.ExpectedPriceChange)); this.BlackScholesPriceChange = this.BlackScholesPriceTarget - this.BlackScholesPrice; this.BlackScholesPL = ((this.Bid + this.BlackScholesPriceChange) * this.Quantity * 100m) - (19.98m + (this.Quantity * tradingAccount.RoundTripCommission)) - (this.Quantity * this.ContractAsk); this.BlackScholesPLPercent = this.BlackScholesPL / (this.Quantity * this.ContractAsk); #endregion }
public Decimal CalculateBlackScholesPrice(TradingAccount tradingAccount, Decimal underlyingPrice) { Double S0 = (Double)underlyingPrice; Double X = (Double)this.Strike; Double sigma = (Double)this.ImpliedVolatility; Double r = (Double)tradingAccount.RiskFreeInterestRate; Double t = ((Double)this.ExpiryDays) / 365.0; Double d1 = (Math.Log(S0 / X) + (t * (r + (Math.Pow(sigma, 2) / 2)))) / (sigma * Math.Sqrt(t)); Double d2 = d1 - (sigma * Math.Sqrt(t)); if (this.OptionType == OptionTypes.Call) { return((Decimal)((S0 * StaticStuff.N(d1)) - (X * Math.Pow(Math.E, -(r * t)) * StaticStuff.N(d2)))); } else { return((Decimal)((X * Math.Pow(Math.E, -(r * t)) * StaticStuff.N(-d2)) - (S0 * StaticStuff.N(-d1)))); } }