#include <stdio.h>
#include <vector.h>
#include <stack.h>
#include <math.h>

#include "treenode.h"
#include "visitor.h"
#include "iterators.h"
#include "dstruct.h"
#include "multiplicative.h"

#include "underlying/binom.h"

#include "underlying.h"

int main(void);

int main(void)
{
  IP_Binom param;
  
  param.dt = vector<double>(1);

  param.S0 = 100.0;
  param.N = 3;
  param.dt[0] = 1.0/3.0;
  param.U = 1.1;
  param.D = 0.9091;
  param.r = 0.06;

  Underlying<UNDERLYING(Binom), Tree<Complete, Multiplicative> > *tree = new Underlying<UNDERLYING(Binom), Tree<Complete, Multiplicative> >(param);

  printf("Tree Iterator Breadth First\n");
  
  BreadthFirstIterator<double>& iterb = tree->getStockBreadthFirstIterator();
  TreeNode<double> *node;
  
  while(! iterb.isDone())
    {
      node = *iterb;
      
      printf("%f\n", node->value);

      ++iterb;
    }

  printf("\nTree Iterator Post Order\n");

  PostOrderIterator<double>& iterp = tree->getStockPostOrderIterator();
  
  iterp.Reset();

  while(! iterp.isDone())
    {
      node = *iterp;
      
      printf("%f\n", node->value);

      ++iterp;
    }

#ifdef GRAPHICS
  tree->graphStock("tree.png", 400, 800);
#endif

  printf("\n\nMatrix\n");
  
  Underlying<UNDERLYING(Binom), Matrix<Complete, Multiplicative> > *matrix = new Underlying<UNDERLYING(Binom), Matrix<Complete, Multiplicative> >(param);
  
  for(unsigned int colNum = 0; colNum < (unsigned)param.N+1; colNum++)
    {
      for(unsigned int rowNum = 0; rowNum < matrix->getStockHeight(colNum); rowNum++)
	printf(" %.2f ", matrix->getStockValue(colNum, rowNum));
	
      printf("\n");
    }
  
#ifdef GRAPHICS
  matrix->graphStock("matrix.png", 400, 800);
#endif

}

