最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plotly - efficient frontier plotting in python - Stack Overflow

programmeradmin2浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

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)")
发布评论

评论列表(0)

  1. 暂无评论