Adds StandardDeviationOfReturns configurability and improves greeks warmup for Futures/Index Options (#5495)
* Improves greeks configurability and defaults for all option asset types
* Makes `StandardDeviationOfReturns` configurable by users, so that
greeks can be loaded according to user expectations and the series
of returns that they'd like to compute for `n` periods and timespan
of `T`, as well as resolution of the data in live mode.
* Changes resolution to max resolution available for the default
volatility model created for the security. Usually this only applies
to live mode, but if creating an instance of the
`StandardDeviationOfReturns` volatility model and no `updateFrequency`
is provided, the resolution's time span will be used as the default
value. Backwards compatibility for equities is maintained.
* Changes defaults for `StandardDeviationOfReturnsVolatilityModel`
to warmup greeks faster for other derivative asset types
* Improves comments on `StandardDeviationOfReturns` for clarity on how
to use the volatility model for end users
* Fixes bug where TradeBar could not have proper Symbol set when getting
max resolution
* Applies to QCAlgorithm.Universe and StandardDeviationOfReturnsVolatilityModel
* Adds tests to check volatility model is updated at specified config intervals
* Address review: add shared method for (Relative)StandardDeviation
volatility models
* Adjusts logic to determine bar type
* Address review: order by TickType when getting configs inside volatility models
This commit is contained in:
@@ -11,10 +11,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Data import *
|
||||
from QuantConnect.Securities import *
|
||||
from QuantConnect.Securities.Option import *
|
||||
from QuantConnect.Securities.Volatility import *
|
||||
from QuantConnect import *
|
||||
|
||||
### <summary>
|
||||
@@ -29,7 +31,9 @@ class IndexOptionCallITMGreeksExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2021, 1, 4)
|
||||
self.SetEndDate(2021, 1, 31)
|
||||
|
||||
self.spx = self.AddIndex("SPX", Resolution.Minute).Symbol
|
||||
spx = self.AddIndex("SPX", Resolution.Minute)
|
||||
spx.VolatilityModel = StandardDeviationOfReturnsVolatilityModel(60, Resolution.Minute, timedelta(minutes=1))
|
||||
self.spx = spx.Symbol
|
||||
|
||||
# Select a index option call expiring ITM, and adds it to the algorithm.
|
||||
self.spxOption = list(self.OptionChainProvider.GetOptionContractList(self.spx, self.Time))
|
||||
@@ -74,11 +78,12 @@ class IndexOptionCallITMGreeksExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
if any([i for i in deltas if i == 0]):
|
||||
raise Exception("Option contract Delta was equal to zero")
|
||||
|
||||
#if any([i for i in gammas if i == 0]):
|
||||
# raise AggregateException("Option contract Gamma was equal to zero")
|
||||
# Delta is 1, therefore we expect a gamma of 0
|
||||
if any([i for i in gammas if i == 0]):
|
||||
raise AggregateException("Option contract Gamma was equal to zero")
|
||||
|
||||
#if any([i for i in lambda_ if lambda_ == 0]):
|
||||
# raise AggregateException("Option contract Lambda was equal to zero")
|
||||
if any([i for i in lambda_ if lambda_ == 0]):
|
||||
raise AggregateException("Option contract Lambda was equal to zero")
|
||||
|
||||
if any([i for i in rho if i == 0]):
|
||||
raise Exception("Option contract Rho was equal to zero")
|
||||
@@ -86,8 +91,10 @@ class IndexOptionCallITMGreeksExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
if any([i for i in theta if i == 0]):
|
||||
raise Exception("Option contract Theta was equal to zero")
|
||||
|
||||
#if any([i for i in vega if vega == 0]):
|
||||
# raise AggregateException("Option contract Vega was equal to zero")
|
||||
# The strike is far away from the underlying asset's price, and we're very close to expiry.
|
||||
# Zero is an expected value here.
|
||||
if any([i for i in vega if vega == 0]):
|
||||
raise AggregateException("Option contract Vega was equal to zero")
|
||||
|
||||
if not self.invested:
|
||||
self.SetHoldings(list(list(data.OptionChains.Values)[0].Contracts.Values)[0].Symbol, 1)
|
||||
|
||||
Reference in New Issue
Block a user