Update app.py
Browse files
app.py
CHANGED
|
@@ -62,18 +62,18 @@ def plot_opciones(df_put, df_call, ticker_input, expiration_date):
|
|
| 62 |
calls_itm = df_call[df_call['strike'] < spot_price]
|
| 63 |
calls_otm = df_call[df_call['strike'] >= spot_price]
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
marker=dict(color='black', size=10),
|
| 72 |
text=[f'Spot: {spot_price}'],
|
| 73 |
textposition='top center',
|
| 74 |
name='Spot Price'))
|
| 75 |
# Agrega la línea vertical discontinua
|
| 76 |
-
|
| 77 |
x=[spot_price, spot_price],
|
| 78 |
y=[0, max(max(puts_itm['volume']), max(puts_otm['volume']), max(calls_itm['volume']), max(calls_otm['volume'])) * 1.1],
|
| 79 |
mode='lines',
|
|
@@ -84,12 +84,44 @@ def plot_opciones(df_put, df_call, ticker_input, expiration_date):
|
|
| 84 |
))
|
| 85 |
|
| 86 |
|
| 87 |
-
|
| 88 |
xaxis_title='Strike',
|
| 89 |
yaxis_title='Volumen',
|
| 90 |
barmode='stack',
|
| 91 |
template='plotly_white')
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
|
|
@@ -208,7 +240,7 @@ with gr.Blocks(title="Análisis de Opciones") as demo:
|
|
| 208 |
btn_plot.click(
|
| 209 |
fn=plot_opciones,
|
| 210 |
inputs=[df_put_state, df_call_state, ticker_input, expiration_date],
|
| 211 |
-
outputs=
|
| 212 |
)
|
| 213 |
|
| 214 |
|
|
|
|
| 62 |
calls_itm = df_call[df_call['strike'] < spot_price]
|
| 63 |
calls_otm = df_call[df_call['strike'] >= spot_price]
|
| 64 |
|
| 65 |
+
fig1 = go.Figure()
|
| 66 |
+
fig1.add_trace(go.Bar(x=puts_itm['strike'], y=puts_itm['volume'], name='PUT ITM', marker_color='green', width=0.3))
|
| 67 |
+
fig1.add_trace(go.Bar(x=puts_otm['strike'], y=puts_otm['volume'], name='PUT OTM', marker_color='red',width=0.3))
|
| 68 |
+
fig1.add_trace(go.Bar(x=calls_itm['strike'], y=calls_itm['volume'], name='CALL ITM', marker_color='blue',width=0.3))
|
| 69 |
+
fig1.add_trace(go.Bar(x=calls_otm['strike'], y=calls_otm['volume'], name='CALL OTM', marker_color='orange',width=0.3))
|
| 70 |
+
fig1.add_trace(go.Scatter(x=[spot_price], y=[0], mode='markers+text',
|
| 71 |
marker=dict(color='black', size=10),
|
| 72 |
text=[f'Spot: {spot_price}'],
|
| 73 |
textposition='top center',
|
| 74 |
name='Spot Price'))
|
| 75 |
# Agrega la línea vertical discontinua
|
| 76 |
+
fig1.add_trace(go.Scatter(
|
| 77 |
x=[spot_price, spot_price],
|
| 78 |
y=[0, max(max(puts_itm['volume']), max(puts_otm['volume']), max(calls_itm['volume']), max(calls_otm['volume'])) * 1.1],
|
| 79 |
mode='lines',
|
|
|
|
| 84 |
))
|
| 85 |
|
| 86 |
|
| 87 |
+
fig1.update_layout(title=f"Options Volume Ditr {ticker_input}, {expiration_date}",
|
| 88 |
xaxis_title='Strike',
|
| 89 |
yaxis_title='Volumen',
|
| 90 |
barmode='stack',
|
| 91 |
template='plotly_white')
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
fig2 = go.Figure()
|
| 95 |
+
|
| 96 |
+
fig2.add_trace(go.Scatter(
|
| 97 |
+
x=df_put['strike'],
|
| 98 |
+
y=df_put['impliedVolatility'],
|
| 99 |
+
mode='markers+lines',
|
| 100 |
+
name='PUT',
|
| 101 |
+
marker=dict(color='red')
|
| 102 |
+
|
| 103 |
+
))
|
| 104 |
+
|
| 105 |
+
fig2.add_trace(go.Scatter(
|
| 106 |
+
x=df_call['strike'],
|
| 107 |
+
y=df_call['impliedVolatility'],
|
| 108 |
+
mode='markers+lines',
|
| 109 |
+
name='CALL',
|
| 110 |
+
marker=dict(color='blue')
|
| 111 |
+
|
| 112 |
+
))
|
| 113 |
+
|
| 114 |
+
# Agrega la línea vertical aquí
|
| 115 |
+
fig2.add_vline(x=spot_price_value, line_width=2, line_dash="dot", line_color="black")
|
| 116 |
+
|
| 117 |
+
fig2.update_layout(
|
| 118 |
+
title='Volatilidad Implícita por Strike',
|
| 119 |
+
xaxis_title='Strike',
|
| 120 |
+
yaxis_title='Volatilidad Implícita',
|
| 121 |
+
template='plotly_white'
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
return fig1, fig2
|
| 125 |
|
| 126 |
|
| 127 |
|
|
|
|
| 240 |
btn_plot.click(
|
| 241 |
fn=plot_opciones,
|
| 242 |
inputs=[df_put_state, df_call_state, ticker_input, expiration_date],
|
| 243 |
+
outputs=[output_plot1, output_plot2]
|
| 244 |
)
|
| 245 |
|
| 246 |
|