using System;
using System.Linq;

namespace LibraryPricer.Engines
{
    public static class GbmEngine
    {
        public static double RunSimulation(
            double[] pricesUL,
            double[,] corrMatrix,
            int numAssets,
            int daysToMaturity,
            int numSimulations,
            double rate,
            double[] dividends,
            double[] volatilities,
            Payoffs.PayoffContext context)
        {
            double[] results = new double[numSimulations];
            var evaluator = Payoffs.PayoffFactory.GetEvaluator(context.Caso);

            for (int i = 0; i < numSimulations; i++)
            {
                var path = CalcFunctions.GBMMultiEquity(
                    pricesUL,
                    corrMatrix,
                    numAssets,
                    daysToMaturity,
                    rate,
                    dividends,
                    volatilities
                );

                results[i] = evaluator.Evaluate(path, context) * 100.0; // Scale to FV
            }

            return results.Average();
        }
    }
}
