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()
Share
Improve this question
edited Mar 3 at 13:32
Márton Horváth
5561 silver badge16 bronze badges
asked Mar 3 at 4:08
nani869nani869
91 bronze badge
1
- Not sure why you used the "matplotlib" tag although your code uses plotly. Do you want a plotly-specific answer or is matplotlib also viable? – simon Commented Mar 3 at 9:12
1 Answer
Reset to default 1you 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)")
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745110091a4611795.html
评论列表(0条)