class_docstr: Represents a batch of American Equity Options.
  
  An American equity option is a contract that gives the holder an opportunity
  to buy (call) or sell (put) an equity for a predefined value (strike) at
  any date before the expiry.
  
  The AmericanOption class can be used to create and price multiple options
  simultaneously.
  
  #### Example:
  The following example illustrates the construction of a batch of American
  options and pricing them.
  
  ```None
  american_option_proto = american_option_pb2.AmericanEquityOption(
      short_position=True,
      expiry_date=date_pb2.Date(year=2022, month=5, day=21),
      contract_amount=decimal_pb2.Decimal(units=10000),
      strike=decimal_pb2.Decimal(units=1500),
      equity="GOOG",
      currency=Currency.USD(),
      business_day_convention=BusinessDayConvention.MODIFIED_FOLLOWING(),
      is_call_option=False)
  
  market = market_data.MarketDataDict(...)
  am_option_portfolio = AmericanOption.from_protos([american_option_proto])
  am_option_portfolio[0].price(market)
  ```
class_docstr_tok: ["Represents","a","batch","of","American","Equity","Options",".","An","American","equity","option","is","a","contract","that","gives","the","holder","an","opportunity","to","buy","(","call",")","or","sell","(","put",")","an","equity","for","a","predefined","value","(","strike",")","at","any","date","before","the","expiry",".","The","AmericanOption","class","can","be","used","to","create","and","price","multiple","options","simultaneously",".","#","#","#","#","Example",":","The","following","example","illustrates","the","construction","of","a","batch","of","American","options","and","pricing","them",".","``","`","None","american_option_proto","=","american_option_pb2.AmericanEquityOption","(","short_position=True",",","expiry_date=date_pb2.Date","(","year=2022",",","month=5",",","day=21",")",",","contract_amount=decimal_pb2.Decimal","(","units=10000",")",",","strike=decimal_pb2.Decimal","(","units=1500",")",",","equity=","''","GOOG","''",",","currency=Currency.USD","(",")",",","business_day_convention=BusinessDayConvention.MODIFIED_FOLLOWING","(",")",",","is_call_option=False",")","market","=","market_data.MarketDataDict","(","...",")","am_option_portfolio","=","AmericanOption.from_protos","(","[","american_option_proto","]",")","am_option_portfolio","[","0","]",".price","(","market",")","``","`"]
docstr: Initializes the batch of American Equity Options.
  
  Args:
    short_position: Whether the price is computed for the contract holder.
      Default value: `True` which means that the price is for the contract
      holder.
    currency: The denominated currency.
    expiry_date: A `DateTensor` specifying the dates on which the options
      expire.
    equity: A string name of the underlyings.
    contract_amount: A `Tensor` of real dtype and shape compatible with
      with `short_position`.
    strike: `Tensor` of real dtype and shape compatible with
      with `short_position`. Option strikes.
    is_call_option: A bool `Tensor` of shape compatible with with
      `short_position`. Indicates which options are of call type.
    business_day_convention: A business count convention.
    calendar: A calendar to specify the weekend mask and bank holidays.
    settlement_days: An integer `Tensor` of the shape broadcastable with the
      shape of `fixing_date`.
    discount_curve_type: An optional instance of `CurveType` or a list of
      those. If supplied as a list and `discount_curve_mask` is not supplied,
      the size of the list should be the same as the number of priced
      instruments. Defines discount curves for the instruments.
      Default value: `None`, meaning that discount curves are inferred
      from `currency` and `config`.
    discount_curve_mask: An optional integer `Tensor` of values ranging from
      `0` to `len(discount_curve_type) - 1` and of shape `batch_shape`.
      Identifies a mapping between `discount_curve_type` list and the
      underlying instruments.
      Default value: `None`.
    equity_mask: An optional integer `Tensor` of values ranging from
      `0` to `len(equity) - 1` and of shape `batch_shape`. Identifies
      a mapping between `equity` list and the underlying instruments.
      Default value: `None`.
    config: Optional `AmericanOptionConfig` or a dictionary. If dictionary,
      then the keys should be the same as the field names of
      `AmericanOptionConfig`.
    batch_names: A string `Tensor` of instrument names. Should be of shape
      `batch_shape + [2]` specying name and instrument type. This is useful
      when the `from_protos` method is used and the user needs to identify
      which instruments got batched together.
    dtype: `tf.Dtype` of the input and output real `Tensor`s.
      Default value: `None` which maps to `float64`.
    name: Python str. The name to give to the ops created by this class.
      Default value: `None` which maps to 'AmericanOption'.
docstr_tok: ["Initializes","the","batch","of","American","Equity","Options",".","Args",":","short_position",":","Whether","the","price","is","computed","for","the","contract","holder",".","Default","value",":","`","True","`","which","means","that","the","price","is","for","the","contract","holder",".","currency",":","The","denominated","currency",".","expiry_date",":","A","`","DateTensor","`","specifying","the","dates","on","which","the","options","expire",".","equity",":","A","string","name","of","the","underlyings",".","contract_amount",":","A","`","Tensor","`","of","real","dtype","and","shape","compatible","with","with","`","short_position","`",".","strike",":","`","Tensor","`","of","real","dtype","and","shape","compatible","with","with","`","short_position","`",".","Option","strikes",".","is_call_option",":","A","bool","`","Tensor","`","of","shape","compatible","with","with","`","short_position","`",".","Indicates","which","options","are","of","call","type",".","business_day_convention",":","A","business","count","convention",".","calendar",":","A","calendar","to","specify","the","weekend","mask","and","bank","holidays",".","settlement_days",":","An","integer","`","Tensor","`","of","the","shape","broadcastable","with","the","shape","of","`","fixing_date","`",".","discount_curve_type",":","An","optional","instance","of","`","CurveType","`","or","a","list","of","those",".","If","supplied","as","a","list","and","`","discount_curve_mask","`","is","not","supplied",",","the","size","of","the","list","should","be","the","same","as","the","number","of","priced","instruments",".","Defines","discount","curves","for","the","instruments",".","Default","value",":","`","None","`",",","meaning","that","discount","curves","are","inferred","from","`","currency","`","and","`","config","`",".","discount_curve_mask",":","An","optional","integer","`","Tensor","`","of","values","ranging","from","`","0","`","to","`","len","(","discount_curve_type",")","-","1","`","and","of","shape","`","batch_shape","`",".","Identifies","a","mapping","between","`","discount_curve_type","`","list","and","the","underlying","instruments",".","Default","value",":","`","None","`",".","equity_mask",":","An","optional","integer","`","Tensor","`","of","values","ranging","from","`","0","`","to","`","len","(","equity",")","-","1","`","and","of","shape","`","batch_shape","`",".","Identifies","a","mapping","between","`","equity","`","list","and","the","underlying","instruments",".","Default","value",":","`","None","`",".","config",":","Optional","`","AmericanOptionConfig","`","or","a","dictionary",".","If","dictionary",",","then","the","keys","should","be","the","same","as","the","field","names","of","`","AmericanOptionConfig","`",".","batch_names",":","A","string","`","Tensor","`","of","instrument","names",".","Should","be","of","shape","`","batch_shape","+","[","2","]","`","specying","name","and","instrument","type",".","This","is","useful","when","the","`","from_protos","`","method","is","used","and","the","user","needs","to","identify","which","instruments","got","batched","together",".","dtype",":","`","tf.Dtype","`","of","the","input","and","output","real","`","Tensor","`","s",".","Default","value",":","`","None","`","which","maps","to","`","float64","`",".","name",":","Python","str",".","The","name","to","give","to","the","ops","created","by","this","class",".","Default","value",":","`","None","`","which","maps","to","'AmericanOption","'","."]
code: def __init__(
      self,
      short_position: types.BoolTensor,
      currency: Union[
          types.CurrencyProtoType, List[types.CurrencyProtoType]
      ],
      expiry_date: types.DateTensor,
      equity: List[str],
      contract_amount: types.FloatTensor,
      strike: types.FloatTensor,
      is_call_option: List[bool],
      business_day_convention: types.BusinessDayConventionProtoType,
      calendar: types.BankHolidaysProtoType,
      settlement_days: Optional[types.IntTensor] = 0,
      discount_curve_type: curve_types_lib.CurveType = None,
      discount_curve_mask: types.IntTensor = None,
      equity_mask: types.IntTensor = None,
      config: Union[AmericanOptionConfig, Dict[str, Any]] = None,
      batch_names: Optional[types.StringTensor] = None,
      dtype: Optional[types.Dtype] = None,
      name: Optional[str] = None,
  ):
      """Initializes the batch of American Equity Options.
  
      Args:
        short_position: Whether the price is computed for the contract holder.
          Default value: `True` which means that the price is for the contract
          holder.
        currency: The denominated currency.
        expiry_date: A `DateTensor` specifying the dates on which the options
          expire.
        equity: A string name of the underlyings.
        contract_amount: A `Tensor` of real dtype and shape compatible with
          with `short_position`.
        strike: `Tensor` of real dtype and shape compatible with
          with `short_position`. Option strikes.
        is_call_option: A bool `Tensor` of shape compatible with with
          `short_position`. Indicates which options are of call type.
        business_day_convention: A business count convention.
        calendar: A calendar to specify the weekend mask and bank holidays.
        settlement_days: An integer `Tensor` of the shape broadcastable with the
          shape of `fixing_date`.
        discount_curve_type: An optional instance of `CurveType` or a list of
          those. If supplied as a list and `discount_curve_mask` is not supplied,
          the size of the list should be the same as the number of priced
          instruments. Defines discount curves for the instruments.
          Default value: `None`, meaning that discount curves are inferred
          from `currency` and `config`.
        discount_curve_mask: An optional integer `Tensor` of values ranging from
          `0` to `len(discount_curve_type) - 1` and of shape `batch_shape`.
          Identifies a mapping between `discount_curve_type` list and the
          underlying instruments.
          Default value: `None`.
        equity_mask: An optional integer `Tensor` of values ranging from
          `0` to `len(equity) - 1` and of shape `batch_shape`. Identifies
          a mapping between `equity` list and the underlying instruments.
          Default value: `None`.
        config: Optional `AmericanOptionConfig` or a dictionary. If dictionary,
          then the keys should be the same as the field names of
          `AmericanOptionConfig`.
        batch_names: A string `Tensor` of instrument names. Should be of shape
          `batch_shape + [2]` specying name and instrument type. This is useful
          when the `from_protos` method is used and the user needs to identify
          which instruments got batched together.
        dtype: `tf.Dtype` of the input and output real `Tensor`s.
          Default value: `None` which maps to `float64`.
        name: Python str. The name to give to the ops created by this class.
          Default value: `None` which maps to 'AmericanOption'.
      """
      self._name = name or "AmericanOption"
      with tf.name_scope(self._name):
          if batch_names is not None:
              self._names = tf.convert_to_tensor(
                  batch_names, name="batch_names"
              )
          else:
              self._names = None
          self._dtype = dtype or tf.float64
          ones = tf.constant(1, dtype=self._dtype)
          self._short_position = tf.where(
              short_position, ones, -ones, name="short_position"
          )
          self._contract_amount = tf.convert_to_tensor(
              contract_amount, dtype=self._dtype, name="contract_amount"
          )
          self._strike = tf.convert_to_tensor(
              strike, dtype=self._dtype, name="strike"
          )
          self._is_call_option = tf.convert_to_tensor(
              is_call_option, dtype=tf.bool, name="strike"
          )
          settlement_days = tf.convert_to_tensor(settlement_days)
          # Business day roll convention and the end of month flag
          (
              roll_convention,
              eom,
          ) = market_data_utils.get_business_day_convention(
              business_day_convention
          )
          # TODO(b/160446193): Calendar is ignored at the moment
          calendar = dateslib.create_holiday_calendar(
              weekend_mask=dateslib.WeekendMask.SATURDAY_SUNDAY
          )
          if isinstance(expiry_date, types.IntTensor):
              self._expiry_date = dateslib.dates_from_tensor(
                  expiry_date
              )
          else:
              self._expiry_date = dateslib.convert_to_date_tensor(
                  expiry_date
              )
          self._settlement_days = settlement_days
          self._roll_convention = roll_convention
          # Get discount and reference curves
          self._currency = cashflow_streams.to_list(currency)
          self._equity = cashflow_streams.to_list(equity)
          if len(self._currency) != len(self._equity):
              if len(self._currency) > 1 and len(self._equity) > 1:
                  raise ValueError(
                      "Number of currencies and equities should be the same "
                      "but it is {0} and {1}".format(
                          len(self._currency), len(self._equity)
                      )
                  )
  
          config = _process_config(config)
          [
              self._model,
              self._num_samples,
              self._seed,
              self._num_exercise_times,
              self._num_calibration_samples,
          ] = _get_config_values(config)
  
          if discount_curve_type is None:
              discount_curve_type = []
              for currency in self._currency:
                  if currency in config.discounting_curve:
                      curve_type = config.discounting_curve[currency]
                  else:
                      # Default discounting curve
                      curve_type = curve_types_lib.RiskFreeCurve(
                          currency=currency
                      )
                  discount_curve_type.append(curve_type)
  
          # Get masks for discount curves and vol surfaces
          [
              self._discount_curve_type,
              self._discount_curve_mask,
          ] = cashflow_streams.process_curve_types(
              discount_curve_type, discount_curve_mask
          )
          [
              self._equity,
              self._equity_mask,
          ] = equity_utils.process_equities(self._equity, equity_mask)
          # Get batch shape
          self._batch_shape = tf.shape(strike)
  
imports: from typing import Any, Optional, List, Dict, Union, Tuple
  import dataclasses
  import tensorflow.compat.v2
  from tf_quant_finance import datetime
  from tf_quant_finance.experimental.pricing_platform.framework.core import curve_types
  from tf_quant_finance.experimental.pricing_platform.framework.core import instrument
  from tf_quant_finance.experimental.pricing_platform.framework.core import processed_market_data
  from tf_quant_finance.experimental.pricing_platform.framework.core import types
  from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments import utils
  from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments.american_option import proto_utils
  from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments.american_option import utils
  from tf_quant_finance.experimental.pricing_platform.framework.market_data import utils
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import cashflow_streams
  from tf_quant_finance.experimental.pricing_platform.instrument_protos import american_equity_option_pb2
label_desc: Use image node_id 1 to create a new AmericanOption object from inherited base classes: instrument with example: obj = AmericanOption(short_position, currency, expiry_date, equity, contract_amount, strike, is_call_option, business_day_convention, calendar, settlement_days, discount_curve_type, discount_curve_mask, equity_mask, config, batch_names, dtype, name)