def plot_payoff( current_price: float, options: List[Dict[Any, Any]], underlying: int, ticker: str, expiration: str, external_axes: Optional[List[plt.Axes]] = None, ) -> None: """Generate a graph showing the option payoff diagram""" x, yb, ya = generate_data(current_price, options, underlying) if external_axes is None: _, ax = plt.subplots(figsize=plot_autoscale(), dpi=cfp.PLOT_DPI) else: if len(external_axes) != 1: logger.error("Expected list of one axis item.") console.print("[red]Expected list of one axis item./n[/red]") return (ax, ) = external_axes if ya: ax.plot(x, yb, label="Payoff Before Premium") ax.plot(x, ya, label="Payoff After Premium") else: ax.plot(x, yb, label="Payoff") ax.set_title(f"Option Payoff Diagram for {ticker} on {expiration}") ax.set_ylabel("Profit") ax.set_xlabel("Underlying Asset Price at Expiration") ax.xaxis.set_major_formatter("${x:.2f}") ax.yaxis.set_major_formatter("${x:.2f}") theme.style_primary_axis(ax) if external_axes is None: theme.visualize_output()
def plot_payoff( current_price: float, options: List[Dict[Any, Any]], underlying: int, ticker: str, expiration: str, ) -> None: """Generate a graph showing the option payoff diagram""" x, yb, ya = generate_data(current_price, options, underlying) _, ax = plt.subplots() if ya: ax.plot(x, yb, label="Payoff Before Premium") ax.plot(x, ya, label="Payoff After Premium") else: ax.plot(x, yb, label="Payoff") ax.set_title(f"Option Payoff Diagram for {ticker} on {expiration}") ax.set_ylabel("Profit") ax.set_xlabel("Underlying Asset Price at Expiration") ax.xaxis.set_major_formatter("${x:.2f}") ax.yaxis.set_major_formatter("${x:.2f}") plt.legend() if gtff.USE_ION: plt.ion() plt.show() print("")