Plotly figure is not displayed even though it's not empty

25 Views Asked by At

I created this function using plotly but, when calling it, nothing is displayed, only a huge white space which has the same size of the table that there should be. I checked whether the figure is empty or not (print(fig)) or whether the initial input are not correct (print(VaR)) but everything is printed out, but not the figure!

Any suggestion?

def RiskMeasure(VaR, CVaR, initial_price,percentilesamev,volaforecast, histovol):
    # Create a table trace
    lossvarperc = (VaR/initial_price - 1) * 100
    table_trace = go.Table(
        header=dict(values=['Measure of Risk', 'Value']),
        cells=dict(values=[['VaR (Value at Risk)', 'CVaR (Expected Shortfall)', 'Loss will be greater than: (5% probability) ','Average Loss','Forecast Volatility vs Historical','The probability of a lower price than today is: '],
                           [round(VaR, 3), round(CVaR, 3), str(round(initial_price - VaR,3)) +' ('+ (str(round(lossvarperc,2)) +'%')+')' , round(initial_price - CVaR,3), str(round(volaforecast*100, 2)) +'% vs ' + str(round(histovol))+'%', f'{percentilesamev}%']], height=40)
    )

    # Create layout
    layout = go.Layout(
        title='VaR (Value at Risk) and CVaR (Expected Shortfall)',
        title_x=0.5,  # Center the title horizontally
        height=400,   # Adjust the height of the table
        margin=dict(t=50, b=10)  # Adjust the margin
    )

    # Create figure with table trace and layout
    fig = go.Figure(data=table_trace, layout=layout)
    print(fig)
    fig.show()
    VaR
    

This is the print of the fig:

Figure({
'data': [{'cells': {'height': 40,
                    'values': [['VaR (Value at Risk)', 'CVaR (Expected
                               Shortfall)', 'Loss will be greater than: (5%
                               probability) ', 'Average Loss', 'Forecast
                               Volatility vs Historical', 'The probability of a
                               lower price than today is: '], [7442.781,
                               7102.915, '994.119 (-11.78%)', 1333.985, '12.04%
                               vs 7%', '27%']]},
          'header': {'values': ['Measure of Risk', 'Value']},
          'type': 'table'}],
'layout': {'height': 400,
           'margin': {'b': 10, 't': 50},
           'template': '...',
           'title': {'text': 'VaR (Value at Risk) and CVaR (Expected Shortfall)', 'x': 0.5}}
})
0

There are 0 best solutions below