【bokeh】线性绘制

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Original

from bokeh.io import output_notebook, push_notebook, show
from bokeh.plotting import figure
output_notebook()
from IPython.display import Math, Markdown
import numpy as np
from bokeh.models import Range1d

class vanilla_payoff(object):
    def __init__(self, strike):
        self.strike = strike
    
    def pay(self, spots):
        payout = (spots - self.strike)
        payout[payout <= 0] = 0
        return payout
        
strike = 1.3
spots = np.linspace(1.2, 1.4, 101)
vanilla = vanilla_payoff(strike)
payout = vanilla.pay(spots)
p = figure(sizing_mode="stretch_both", active_drag=None)
p.line(spots, payout, line_width=5)
p.circle([strike], [0], size=10, color='red')
show(p)

在这里插入图片描述

Result

from bokeh.io import output_notebook, push_notebook, show
from bokeh.plotting import figure

output_notebook()
from IPython.display import Math, Markdown
import numpy as np
from bokeh.models import Range1d


class vanilla_payoff(object):
    def __init__(self, strike):
        self.strike = strike

    def pay(self, spots):
        payout = (spots - self.strike)
        payout[payout <= 0] = 0
        return payout


strike = 1.3
spots = np.linspace(1.2, 1.31, 101)
_spots = np.linspace(1.31, 1.4, 101)
vanilla = vanilla_payoff(strike)
payout = vanilla.pay(spots)
p = figure(sizing_mode="stretch_both", active_drag=None)
p.line(spots, payout, line_width=5)
p.line(_spots, 0.1, line_width=5)
p.circle([strike], [0], size=10, color='red')
p.circle([strike+0.01], [0.1], size=10, color='red')
show(p)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43359312/article/details/107759471