我正在努力制作下图所示的图表:
我该如何重现它?到目前为止,我的试验结果很糟糕。以下是我的 MWE:
\documentclass[12pt,a4paper]{book}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes, arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=10cm, width=12cm,
axis x line=bottom, axis y line=left,
xlabel = Volatility (standard deviation), ylabel = Expected Return,
ymin=0, ymax=15, xmin=0, xmax=40,
extra x ticks={65}, extra x tick labels={$\sigma$},
extra x tick style={major tick length=0mm, grid=none},
extra y ticks={25}, extra y tick
,
extra y tick style={major tick length=0mm, grid=none},
enlargelimits=true,
scatter/classes={
a={mark=o,draw=black, mark size = 3pt},
b={mark=*, mark size = 3pt,draw=red, fill = red},
c={mark=*, mark size = 3pt,draw=black, fill = green}
}
]
\addplot[scatter,only marks, scatter src=explicit symbolic]
coordinates {
(14, 4) [c]
(17, 3) [c]
(18, 6) [c]
(23, 22) [c]
(28, 5) [c]
(37, 3) [c]
(29, 13) [c]
(32, 10) [c]
(38, 8.5) [c]
(35, 14) [c]
(15, 8) [b]
};
\node at (axis cs:14, 4) [anchor=north west] {MacDonalds};
\node at (axis cs:17,3) [anchor=north west] {Walmart};
\node at (axis cs:18,6) [anchor=north west] {IBM};
\node at (axis cs:23,22) [anchor=north west] {Nike};
\node at (axis cs:28,5) [anchor=north west] {Molson-Coors};
\node at (axis cs:37,3) [anchor=north west] {Newmont Mining};
\node at (axis cs:29,13) [anchor=north west] {GE};
\node at (axis cs:32,10) [anchor=north west] {Apple};
\node at (axis cs:38,8.5) [anchor=north west] {Amazon};
\node at (axis cs:35,14) [anchor=north west] {Tiffany};
\addplot[red, very thick, domain=-1:2.5, samples=200, variable=\t](
{(20^2*t^2 + 12^2*(1-t)^2)^(0.5) }, %{(t^2 * 20^2 + (1-t)^2 * 12)},
{11 * t + (1-t) * 5}
);
\node[color=red] at (axis cs:30, 0) [anchor=south west] {\textbf{Efficient Frontier}};
\addplot[black, very thick, domain=-10:50, samples=100, variable=\x](
({x}, {1 + .4666667 * x});
\node[rotate = 25, color=black] at (axis cs:30, 15) [anchor=south west] {\textbf{Optimal CAL}};
\node[pin={[pin edge={thick}, text width=3cm, pin distance=2cm]90:{{\centering Mean Variance Efficient Porfolio}}}] at (axis cs:15, 8) {};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您的代码中的函数没有经过红点,所以我认为它是错误的,只需添加一些其他随机曲线。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=10cm, width=12cm,
axis lines=center,
xlabel=Volatility (standard deviation), ylabel=Expected Return,
xmin=0, xmax=40,
ymin=0, ymax=15,
enlargelimits=true,
node near coords style={font=\small, right=1pt},
]
\addplot[scatter, only marks, mark size=3pt, fill=green, point meta=explicit symbolic, nodes near coords]
coordinates {
(14, 4) [MacDonalds]
(17, 3) [Walmart]
(18, 6) [IBM]
(23, 22) [Nike]
(28, 5) [Molson-Coors]
(37, 3) [Newmont Mining]
(29, 13) [GE]
(32, 10) [Apple]
(38, 8.5) [Amazon]
(35, 14) [Tiffany]
};
\addplot[black, very thick, domain=-10:50, samples=2] {1+7/15*x};
\addplot[mark=*, mark size=3pt, red, forget plot] coordinates {(15,8)};
\draw[cyan, very thick] (13.5,0) to[out=135, in=-90, looseness=0.7] (9.5,3.5);
\draw[red, very thick] (9.5,3.5) to[out=90, in=-136, looseness=0.7] (15,8) to[out=44, in=-140, looseness=0.7] (37,17);
\end{axis}
\end{tikzpicture}
\end{document}