testbintree.cpp
来自「financal instrument pricing using c」· C++ 代码 · 共 43 行
CPP
43 行
// tetbintree.cpp
//
// Creating a structure for the binomial tree
//
// (C) Datasim Education BV 2003
//
#include "vector.cpp"
#include "arraymechanisms.cpp"
int main()
{
int N = 2; // Number of periods
Vector<Vector<double, int>, int> tree(N+1, 1);
// Initialise tree vectors (give sizes of vectors)
for(int ii = tree.MaxIndex(); ii >= tree.MinIndex(); ii--)
{
tree[ii] = Vector<double, int>(ii);
}
for(int i = tree.MaxIndex(); i>= tree.MinIndex(); i--)
{
for(int j = 1;j <= i;j++)
{
tree[i][j] = i;
}
}
for(int k = tree.MaxIndex(); k >= tree.MinIndex(); k--)
{
print (tree[k]);
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?