public IPricingResult Price(IProduct product, IModel model, Market market) { var simulatedDates = product.RetrieveEventDates(); McModel mcModel = mcModelFactory.Build(model, market, simulatedDates); var mcEngine = McEngine(product, mcModel); PathFlows <double, CouponFlowLabel> result = mcEngine.Run(nbPaths); return(pricingResult.PricingResult(result, product, market)); }
public static ProductPathFlowCalculator Build(IProduct product, McModel model) { IFixing[][] fixings = FixingsByDate(product); Func <double[], double>[][] fixingFromFactors = fixings.Map(fs => fs.Map(f => model.FactorRepresentation[f])); ArrayPathCalculator <IFixing> fixingPathCalc = FixingPathCalc(model.SimulatedDates, fixings, fixingFromFactors); PaymentInfo[][] paymentsByDate = PaymentsByDate(product); ArrayPathCalculator <PaymentInfo> numerairePathCalc = NumerairePathCalc(paymentsByDate, model); var pathFlowVisitor = new ProductPathFlowVisitor(fixings, paymentsByDate); IProductPathFlow productPathFlow = product.Accept(pathFlowVisitor); return(new ProductPathFlowCalculator(fixingPathCalc, numerairePathCalc, productPathFlow)); }
private static Func <double[], double> FlowRebasement(PaymentInfo payment, McModel model) { var modelMeasure = model.ProbaMeasure; if (modelMeasure.Date < payment.Date || !modelMeasure.Currency.Equals(payment.Currency) || !modelMeasure.Financing.Equals(payment.Financing)) { throw new NotImplementedException("Flow Rebasement not yet handled !"); //TODO finish the job ! } var zc = new Zc(payment.Date, modelMeasure.Date, payment.Currency, payment.Financing); var zcFunc = model.FactorRepresentation[zc]; double num0 = model.Numeraire0; return(f => num0 / zcFunc(f)); }
private static ArrayPathCalculator <PaymentInfo> NumerairePathCalc(PaymentInfo[][] payments, McModel model) { var payDates = payments.Map(ps => ps.Map(p => p.Date).Single()); int[] datesIndexes = payDates.Map(model.SimulatedDates.FindIndex); Func <double[], double>[][] funcsByDate = payments.Map(ps => ps.Map(p => FlowRebasement(p, model))); return(new ArrayPathCalculator <PaymentInfo>(datesIndexes, payments, funcsByDate)); }
private McEngine <CouponPathFlows, CouponPathFlows> McEngine(IProduct product, McModel mcModel) { var productPathFlowCalculator = ProductPathFlowFactory.Build(product, mcModel); var processPathFlowGen = new ProcessPathFlowGenerator <double, CouponFlowLabel> (mcModel.BrownianBridge, mcModel.ProcessPathGen, productPathFlowCalculator); return(new McEngine <CouponPathFlows, CouponPathFlows> (mcModel.RandomGenerator, processPathFlowGen, new PriceFlowsAggregator <CouponFlowLabel>())); }