Skip to content

Commit b7b5276

Browse files
committed
Fix bug on CRR
1 parent 5c68e17 commit b7b5276

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

Indicators/OptionGreekIndicatorsHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ internal static decimal CRRTheoreticalPrice(decimal volatility, decimal spotPric
8585
for (int i = 0; i <= period; i++)
8686
{
8787
var binomialValue = values[i] * probDown + values[i + 1] * probUp;
88-
var exerciseValue = OptionPayoff.GetIntrinsicValue(values[i], strikePrice, optionType);
88+
var nextPrice = spotPrice * Convert.ToDecimal(Math.Pow((double)upFactor, 2 * i - period));
89+
var exerciseValue = OptionPayoff.GetIntrinsicValue(nextPrice, strikePrice, optionType);
8990
values[i] = Math.Max(binomialValue, exerciseValue);
9091
}
9192
}

Tests/Indicators/ImpliedVolatilityTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,26 @@ public override void ComparesAgainstExternalDataAfterReset()
129129
// Not used
130130
}
131131

132-
[TestCase(27.50, 450.0, OptionRight.Call, 60, 0.084)]
133-
[TestCase(29.35, 450.0, OptionRight.Put, 60, 0.093)]
134-
[TestCase(37.86, 470.0, OptionRight.Call, 60, 0.021)]
135-
[TestCase(5.74, 470.0, OptionRight.Put, 60, 0.0)] // Volatility of deep OTM American put option will not converge in CRR model
136-
[TestCase(3.44, 430.0, OptionRight.Call, 60, 0.026)]
137-
[TestCase(40.13, 430.0, OptionRight.Put, 60, 0.189)]
138-
[TestCase(17.74, 450.0, OptionRight.Call, 180, 0.014)]
139-
[TestCase(19.72, 450.0, OptionRight.Put, 180, 0.040)]
140-
[TestCase(38.45, 470.0, OptionRight.Call, 180, 0.038)]
141-
[TestCase(0.43, 470.0, OptionRight.Put, 180, 0.0)] // Volatility of deep OTM American put option will not converge in CRR model
142-
[TestCase(1.73, 430.0, OptionRight.Call, 180, 0.016)]
143-
[TestCase(12.46, 430.0, OptionRight.Put, 180, 0.072)]
132+
[TestCase(27.50, 450.0, OptionRight.Call, 60, 0.304)]
133+
[TestCase(29.35, 450.0, OptionRight.Put, 60, 0.511)]
134+
[TestCase(37.86, 470.0, OptionRight.Call, 60, 0.273)]
135+
[TestCase(5.74, 470.0, OptionRight.Put, 60, 0.204)] // Volatility of deep OTM American put option will not converge in CRR model
136+
[TestCase(3.44, 430.0, OptionRight.Call, 60, 0.131)]
137+
[TestCase(40.13, 430.0, OptionRight.Put, 60, 0.541)]
138+
[TestCase(17.74, 450.0, OptionRight.Call, 180, 0.093)]
139+
[TestCase(19.72, 450.0, OptionRight.Put, 180, 0.208)]
140+
[TestCase(38.45, 470.0, OptionRight.Call, 180, 0.134)]
141+
[TestCase(0.43, 470.0, OptionRight.Put, 180, 0.056)] // Volatility of deep OTM American put option will not converge in CRR model
142+
[TestCase(1.73, 430.0, OptionRight.Call, 180, 0.045)]
143+
[TestCase(12.46, 430.0, OptionRight.Put, 180, 0.0)]
144144
public void ComparesIVOnCRRModel(decimal price, decimal spotPrice, OptionRight right, int expiry, double refIV)
145145
{
146146
// Under CRR framework
147147
var symbol = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, right, 450m, _reference.AddDays(expiry));
148-
var indicator = new ImpliedVolatility(_symbol, 0.04m, optionModel: OptionPricingModelType.BinomialCoxRossRubinstein);
148+
var indicator = new ImpliedVolatility(symbol, 0.04m, optionModel: OptionPricingModelType.BinomialCoxRossRubinstein);
149149

150-
var optionTradeBar = new TradeBar(_reference, _symbol, price, price, price, price, 0m);
151-
var spotTradeBar = new TradeBar(_reference, _underlying, spotPrice, spotPrice, spotPrice, spotPrice, 0m);
150+
var optionTradeBar = new TradeBar(_reference, symbol, price, price, price, price, 0m);
151+
var spotTradeBar = new TradeBar(_reference, symbol.Underlying, spotPrice, spotPrice, spotPrice, spotPrice, 0m);
152152
indicator.Update(optionTradeBar);
153153
indicator.Update(spotTradeBar);
154154

0 commit comments

Comments
 (0)