Ejemplo n.º 1
0
    public static void Main()
    {
        int typeB = 2;  // Binomial Lattice Type
        int typeT = 3;  // Trinomial Lattice Type

        int depth = 4;  // Number of periods of time

        double val = 0.0;

        Lattice <double> lattice1 = new Lattice <double>(depth, typeB, val);
        Lattice <double> lattice2 = new Lattice <double>(depth, typeT, val);

        // Trinomial lattice with matrix NRows X NCols entries
        int                        NRows            = 3;
        int                        NCols            = 2;
        int                        startIndex       = 1;
        int                        N                = 10; // Number of time steps
        Matrix <double>            nodeStructure    = new Matrix <double>(NRows, NCols, startIndex, startIndex);
        Lattice <Matrix <double> > trinomialLattice = new Lattice <Matrix <double> >(N, typeT, nodeStructure);


        // Examining the vector at base of lattice
        Vector <double> base1 = lattice1.BasePyramidVector();
        Vector <double> base2 = lattice2.BasePyramidVector();


        Console.WriteLine(base1.Size); Console.WriteLine(base2.Size);
    }
    public static void Main()
    {
        int typeB = 2;  // Binomial Lattice Type
        int typeT = 3;  // Trinomial Lattice Type

        int depth = 4;  // Number of periods of time

        double val = 4.0;

        Lattice <double> lattice1 = new Lattice <double>(depth, typeB, val);
        Lattice <double> lattice2 = new Lattice <double>(depth, typeT, val);


        // Examining the vector at base of lattice
        Vector <double> base1 = lattice1.BasePyramidVector();
        Vector <double> base2 = lattice2.BasePyramidVector();

        // Print columms of lattice
        for (int j = lattice1.MinIndex; j <= lattice1.MaxIndex; j++)
        {
            lattice1.PyramidVector(j).print();
        }

        string s = Console.ReadLine();

        // Arrays
        int             startIndex = lattice1.MinIndex;
        Vector <double> xarr       = new Vector <double>(depth + 1, startIndex);

        xarr[xarr.MinIndex] = 0.0;
        double T       = 1.0;
        int    NT      = 10;
        double delta_T = T / NT;

        for (int j = xarr.MinIndex + 1; j <= xarr.MaxIndex; j++)
        {
            xarr[j] = xarr[j - 1] + delta_T;
        }

        Console.WriteLine(base1.Size); Console.WriteLine(base2.Size);

        ExcelMechanisms exl = new ExcelMechanisms();

        try
        {
            exl.printLatticeInExcel(lattice2, xarr, "Lattice");
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
Ejemplo n.º 3
0
 public Vector <double> BasePyramidVector()
 {
     return(lattice.BasePyramidVector());
 }