예제 #1
0
LPXLFOPER EXCEL_EXPORT
xlPayOffEvaluation(
LPXLFOPER PayOffTablea,
double Spot)
{
EXCEL_BEGIN;

	if (XlfExcel::Instance().IsCalledByFuncWiz())
		return XlfOper(true);

XlfOper PayOffTableb(
	(PayOffTablea));
CellMatrix PayOffTablec(
	PayOffTableb.AsCellMatrix("PayOffTablec"));
ArgumentList PayOffTabled(
	ArgumentList(PayOffTablec,"PayOffTabled"));
Wrapper<PayOff> PayOffTable(
	GetFromFactory<PayOff>(PayOffTabled));


 double t = (clock()+0.0)/CLOCKS_PER_SEC;
double result(
	PayOffEvaluation(
		PayOffTable,
		Spot)
	);
  t = (clock()+0.0)/CLOCKS_PER_SEC-t;
CellMatrix resultCells(result);
CellMatrix time(1,2);
time(0,0) = "time taken";
time(0,1) = t;
resultCells.PushBottom(time);
return XlfOper(resultCells);
EXCEL_END
}
예제 #2
0
LPXLFOPER EXCEL_EXPORT
xlEchoArgList(
LPXLFOPER argsa)
{
EXCEL_BEGIN;

	if (XlfExcel::Instance().IsCalledByFuncWiz())
		return XlfOper(true);

XlfOper argsb(
	(argsa));
CellMatrix argsc(
	argsb.AsCellMatrix("argsc"));
ArgumentList args(
	ArgumentList(argsc,"args"));

 double t = (clock()+0.0)/CLOCKS_PER_SEC;
CellMatrix result(
	EchoArgList(
		args)
	);
  t = (clock()+0.0)/CLOCKS_PER_SEC-t;
CellMatrix resultCells(result);
CellMatrix time(1,2);
time(0,0) = "time taken";
time(0,1) = t;
resultCells.PushBottom(time);
return XlfOper(resultCells);
EXCEL_END
}
예제 #3
0
ArgumentList ArgumentList::GetArgumentListArgumentValue(const std::string& ArgumentName_)
{
	std::string ArgumentName(ArgumentName_);
	MakeLowerCase(ArgumentName);
	std::map<std::string, CellMatrix>::const_iterator it = ListArguments.find(ArgumentName);

    if (it == ListArguments.end())
        throw(StructureName+std::string(" unknown ArgList argument asked for :")+ArgumentName);

    UseArgumentName(ArgumentName);
	return ArgumentList(it->second,ArgumentName); 
}
예제 #4
0
  std::vector<ArgumentList> FileConversion(const std::vector<char>& inputFile,
    unsigned long gapSize)
  {
    std::vector<char>::const_iterator it = inputFile.begin();


    std::vector<std::vector<std::string> > Cells;
    Cells.resize(1);
    std::string currentCell;

    while (it != inputFile.end())
    {
      char c = *it;
      ++it;

      switch (c)
      {
      case  ',' : // end of cell but not line
        {
          (*Cells.rbegin()).push_back(currentCell);
          currentCell = "";
          break;
        }
      case '\n' : // new line so move on;
        {
          Cells.push_back(std::vector<std::string>());
          if (currentCell != "")
          {
            (*Cells.rbegin()).push_back(currentCell);
            currentCell = "";
          }
          break;
        }
      default:
        {
          currentCell.push_back(c);
        }
      }

    }


    std::vector<std::vector<CellValue> > cellValues(Cells.size());
    for (unsigned long i=0; i < Cells.size(); ++i)
    {

      cellValues[i].reserve(Cells[i].size());
      for (unsigned long j=0; j < Cells[i].size(); ++j)
        cellValues[i].push_back( CellFromString(Cells[i][j]));
    }


    size_t rows =cellValues.size();
    std::vector<CellMatrix> cellMatrices;

    size_t currentRow=0;


    // now divide into CellMatrices

    while (currentRow < rows)
    {
      while( currentRow < rows && cellValues[currentRow].size() == 0)
        ++currentRow;

      size_t startRow = currentRow;


      if (currentRow < rows)
      {
        size_t firstEmpty;
        bool endNotFound = true;
        do
        {
          while( currentRow < rows && cellValues[currentRow].size() != 0)
            ++currentRow;

          if (currentRow < rows)
          {
            firstEmpty = currentRow;

            while( currentRow < rows && cellValues[currentRow].size() == 0)
              ++currentRow;

            if (currentRow == rows || (currentRow - firstEmpty) >=gapSize)
              endNotFound = false;

          }
          else
            endNotFound=false;
        }
        while (endNotFound);

        if (currentRow == rows)
          firstEmpty = rows;

        if (startRow < firstEmpty)
        {
          size_t maxColSize=0;

          for (size_t j=startRow; j < firstEmpty; ++j)
            maxColSize = std::max<size_t>(maxColSize, cellValues.size());

          CellMatrix thisOne(firstEmpty-startRow,maxColSize);

          for (size_t i=startRow; i < firstEmpty; ++i)
            for (size_t j=0; j < cellValues[i].size(); ++j)
              thisOne(i-startRow,j) = cellValues[i][j];

          cellMatrices.push_back(thisOne);

        }
      }
    }

    std::vector<ArgumentList> args;
    for (unsigned long i=0; i < cellMatrices.size(); ++i)
      args.push_back(ArgumentList(cellMatrices[i],"clw"));

    return args;


  }