option-price automates option valuation when a tax-loss-harvesting decision must weigh a tax benefit against the cost of losing exposure to future price declines. Create an Option with contract, market, and rate inputs, then request a pricing method. section 14.3.2
An Option requires:
- Style and payoff type: european is True or False; kind is put or call. section 14.3.2
- Market inputs: current asset price (s0), strike (k), life in days (t), annualized volatility (sigma), risk-free rate (r), and dividend yield (dv). section 14.3.2
- A method and, for trees or simulations, an iteration count: BT for binomial trees, BSM for Black–Scholes, or MC for Monte Carlo. section 14.3.2
Pricing an American put
Instantiate an American put with s0=150, k=140, 30 days remaining, sigma=.45, r=.03, and dv=.01; getPrice('BT', iteration=1000) returns about $3.4284. An invalid method such as BSM for an American put returns None rather than raising an error. section 14.3.2
from optionprice import Option
x = Option(european=False, kind='put', s0=150, k=140, t=30,
sigma=.45, r=.03, dv=.01)
p = x.getPrice('BT', iteration=1000)
This listing shows the minimal import, Option construction, and binomial-tree pricing call. section 14.3.2
