<jupyter_start><jupyter_text>Black-Scholes Autodifferentiation ExampleIn this example we are calculating $\theta$ values using the Black-Scholes model via a Lazy Stream.<jupyter_code># Imports & Constants
import tributary.lazy as tl
import math
TRADING_DAYS = 252<jupyter_output><empty_output><jupyter_text>We can use the tributary $\textit{Erf}$ operator to define a Standard Normal CDFThe CDF is defined using $\Phi(x, \mu, \sigma) = \frac{1}{2}\left(1 + Erf\left(\frac{x-\mu}{\sigma\sqrt{2}}\right)\right)$ for $\mu = 0, \sigma = 1$<jupyter_code>def normal_cdf(x):
    return ((tl.Erf(x / tl.Node((math.sqrt(2),0), use_dual=True)) + tl.Node((1,0), use_dual=True))
            / tl.Node((2,0), use_dual=True))<jupyter_output><empty_output><jupyter_text>Now we can define our streamFor this example we are going use a Call Option.We define the model as follows:$C_p = S\Phi(d_1) - Xe^{-rt}\Phi(d_2)$$d_1 = \frac{ln\left(\frac{S}{X}\right) + \left(r + \frac{\sigma^2}{2}\right)t}{\sigma\sqrt{t}}$$d_2 = d_1 - \sigma\sqrt{t}$Where$C_p$ - Price of Call Option$S$ - Stock Price$X$ - Strike Price$r$ - Risk Free Interest Rate$\sigma$ - Stock Price Volatility$t$ - Time to Maturity$\Phi$ - Standard Normal CDF (defined above)  Lazy Graph<jupyter_code>strike_price = tl.Node(value=(203, 0), name='Strike Price', use_dual=True)
stock_price = tl.Node(value=(210, 0), name='Stock Price', use_dual=True)
r = tl.Node(value=(0.2175, 0), name='Risk Free Interest Rate', use_dual=True)
time = tl.Div(
              tl.Node(value=(4, 1), name='Time to Maturity', use_dual=True), 
              tl.Node(value=(TRADING_DAYS,0), use_dual=True)
        )
vol = tl.Node(value=(14.04, 0), name='Stock Price Volatility', use_dual=True)

d1 = ((tl.Log(stock_price / strike_price) + time * (r + (vol**2 / tl.Node((2,0), use_dual=True)))) 
      / (vol * tl.Sqrt(time)))
    

d2 = d1 - vol * tl.Sqrt(time)

opt_price_lazy = stock_price * normal_cdf(d1)- strike_price *tl.Exp(tl.Negate(r * time)) * normal_cdf(d2)      
# Run it
opt_price_lazy()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17073170731707318, 'fraction_numerical': 0.025365853658536587, 'mean_word_length': 4.558265582655826, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '231762', 'license': 'Apache-2.0', 'n_tokens_mistral': 832, 'n_tokens_neox': 784, 'n_words': 174, 'path': 'examples/lazy_blackscholes_autodiff.ipynb', 'repo_name': 'ceball/tributary', 'size': '2050'}