有问题
感谢薛定谔的猫通过求和定义函数的可视化,我修改了他的答案,以显示在一定时间内支付固定金额(息票)的债券证券的价值\C
。这是图标题中的等式。
问题
当我尝试显示 DF 功能时,DF(\n,\r)=pow((1+\r),-\n)
它很流畅。
为什么当我引入和时会得到这个奇怪的小波?
平均能量损失
\documentclass[tikz,export,fleqn]{standalone}
\usepackage{animate}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\newcounter{isum}
\pgfplotsset{summand/.initial=max}
%-------- On définit la somme ----------------
\pgfmathdeclarefunction{sum}{2}{%
\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\edef\myfun{\pgfkeysvalueof{/pgfplots/summand}}%
\pgfmathsetmacro{\mysum}{0}%
\pgfmathsetmacro{\myx}{#2}%
\pgfmathtruncatemacro{\imax}{#1}%
\setcounter{isum}{1}%
\loop
\pgfmathsetmacro{\mysum}{\mysum+\myfun(\value{isum},#2)}%
\ifnum\value{isum}<\imax\relax
\stepcounter{isum}\repeat
\pgfmathparse{\mysum}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
\begin{document}
%Different levels of \C, they represent percentage to a dollar
\pgfplotsinvokeforeach{0.01,0.02,...,0.04}{
\begin{tikzpicture}[
declare function={DF(\n,\r)=pow((1+\r),-\n);},
]
\begin{axis}[
xlabel=Rates,
ylabel=Time to Maturity,
zlabel=Bond value,,
title={$P=\sum_{k=1}^{n} \frac{#1}{(1+r)^{k}}+\frac{1}{(1+r)^{n}}$},
domain=0.0:0.05, % Interest rates
y domain=0:10, % Maturity
view={30}{20},
]
\def\C{0.05}
\addplot3[summand=DF,surf] {#1*sum(y,x)+ DF(y,x)};
% \addplot3[summand=DF,surf] {\C*sum(y,x)+ DF(y,x)};
% \addplot3[summand=DF,surf] {DF(y,x)};
\end{axis}
\end{tikzpicture}
}
\end{document}