当前位置: 首页>>代码示例>>C++>>正文


C++ Lattice::MaxIndex方法代码示例

本文整理汇总了C++中Lattice::MaxIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ Lattice::MaxIndex方法的具体用法?C++ Lattice::MaxIndex怎么用?C++ Lattice::MaxIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lattice的用法示例。


在下文中一共展示了Lattice::MaxIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
	cout << "Forward sweep, Wilmott, Student Edition p. 193\n";

	int depth;
	cout << "How many subdivisions? ";
	cin >> depth;

	// Create the binomal lattice data conainer
	const int n = 2;
	Lattice<double, int, n> lattice1(depth);


	// Test data; change to suit your own needs
	double rootValue = 12.0;// Stock price now
	double D0 = 0.04;		// Dividend yield
	double vol = 0.3;		// Volatility
	double r = 0.06;		// Interest
	double T = 1.0;				// Time to expiry

	cout << "Give value for expiry T: ";
	cin >> T;

	// Create the 'special' parameters
	double k = T / double (depth);
	double e = ::exp((r-D0)*k);
	double sr = ::sqrt(exp(vol*vol*k) - 1.0);

	double up = e * (1.0 + sr);
	double down = e * (1.0 - sr);

	// Populate lattice: forward induction
	Lattice<double, int, 2> newLattice = 
			StandardLattice::createLattice(depth, rootValue, up, down);

	// Now work back from the payoff function; BACKWARD INDUCTION

	// First make the discrete payoff
	double K = 10.0;
	Vector<double, int> RHS = CallPayOff(K, newLattice[newLattice.MaxIndex()]);
	Vector<double, int> RHS2 = PutPayOff(K, lattice1[lattice1.MaxIndex()]);

	double p = 0.5;
	double discounting = ::exp(- r*k);
	
	double optionPrice = StandardLattice::traverse(newLattice, RHS, p, discounting);
	double optionPrice2 = StandardLattice::traverse(newLattice, RHS2, p, discounting);

	cout << "\nOption price C " << optionPrice << endl;
	cout << "\nOption price P " << optionPrice2 << endl;

	return 0;
}
开发者ID:coderxiaok,项目名称:Evaluation-of-the-Impact-of-Earning-Report-on-Stock-Price,代码行数:53,代码来源:TestLattice.cpp

示例2: print

template <class V, class I, int NumberNodes> void print(const Lattice<V, I, NumberNodes>& source)
{
	
	for (I j = source.MinIndex(); j <= source.MaxIndex(); j++)
	{

		cout << "\nBranch Number " << j << ": [";
		for (I i = source[j].MinIndex(); i <= source[j].MaxIndex(); i++)
		{
			cout << source[j][i] << ", ";
	
		}

		cout << "]";
			
	}

}
开发者ID:coderxiaok,项目名称:Evaluation-of-the-Impact-of-Earning-Report-on-Stock-Price,代码行数:18,代码来源:TestLattice.cpp


注:本文中的Lattice::MaxIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。