I am working on efficient frontier optimization, the objective function is maximizing volatility where my output is dataframe of returns and risks respectively, I plotted it I got the bullet shaped curve but I want to connect those points as well how to do that ?
import plotly.express as px
import pandas as pd
# Sort the data by 'Volatility' to ensure a smooth curve
data = data.sort_values(by="Volatility")
# Create an interactive line plot
fig = px.scatter(data, x="Volatility", y="Returns",
title="Efficient Frontier (Risk-Return Tradeoff)")
# Show the figure
fig.show()
I am working on efficient frontier optimization, the objective function is maximizing volatility where my output is dataframe of returns and risks respectively, I plotted it I got the bullet shaped curve but I want to connect those points as well how to do that ?
import plotly.express as px
import pandas as pd
# Sort the data by 'Volatility' to ensure a smooth curve
data = data.sort_values(by="Volatility")
# Create an interactive line plot
fig = px.scatter(data, x="Volatility", y="Returns",
title="Efficient Frontier (Risk-Return Tradeoff)")
# Show the figure
fig.show()
you can try px.line
as described here https://plotly/python/line-charts/
so your
fig = px.scatter(data, x="Volatility", y="Returns",
title="Efficient Frontier (Risk-Return Tradeoff)")
will become
fig = px.line(data, x="Volatility", y="Returns", markers=True,
title="Efficient Frontier (Risk-Return Tradeoff)")