public static MoneynessProvider DivAdjusted(double spot, DividendQuote[] dividends, DiscountCurve discountCurve, ITimeMeasure time) { return(new DivAdjustedMoneyness(spot, new AffineDivCurveUtils(dividends, discountCurve, time))); }
public VolatilityMatrix(ITimeMeasure time, DateTime[] pillars, double[] strikes, double[,] vols) { Pillars = pillars; Strikes = strikes; Vols = vols; Time = time; }
public Hw1ModelZcRepresentation(Hw1Model hw1Model) : base(hw1Model.Currency) { time = hw1Model.Time; meanReversion = hw1Model.MeanReversion; driftTerm = hw1Model.DriftTerm(); }
public Hw1Model(ITimeMeasure time, Currency currency, double meanReversion, RrFunction sigma) { Sigma = sigma; MeanReversion = meanReversion; Currency = currency; Time = time; }
internal ISection GetOrCreateSection(string[] chain, params object[] args) { if (chain == null) { throw new ArgumentNullException(nameof(chain)); } if (chain.Length == 0) { throw new ArgumentException("empty collection", nameof(chain)); } for (int i = 0; i < chain.Length; i++) { if (string.IsNullOrWhiteSpace(chain[i])) { throw new ArgumentException("at least one of chain items is null or whitespace", nameof(chain)); } } var queue = _pool.GetOrAdd(chain, k => new ConcurrentQueue <Section>()); if (!queue.TryDequeue(out Section section)) { ITimeMeasure timeMeasure = _factory.CreateTimeMeasure() ?? throw new InvalidOperationException($"factory returns null {nameof(IReportWriter)}"); section = new Section(this, timeMeasure, _traceWriter, chain, queue); _reportWriter.Add(section); } section.Enter(args); return(section); }
/// <summary>The initialize.</summary> /// <param name="configuration">The configuration.</param> /// <param name="logManager">The log manager.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="preprocessingManager">The preprocessing manager.</param> /// <param name="runStartTime">The run start time.</param> /// <param name="timeMeasure">The time measure.</param> private void Initialize( WebGreaseConfiguration configuration, LogManager logManager, ICacheManager cacheManager, PreprocessingManager preprocessingManager, DateTimeOffset runStartTime, ITimeMeasure timeMeasure) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (configuration.Global.TreatWarningsAsErrors != null) { logManager.TreatWarningsAsErrors = configuration.Global.TreatWarningsAsErrors == true; } // Note: Configuration needs to be set before the other ones. this.Configuration = configuration; this.Configuration.Validate(); this.Measure = timeMeasure; this.Log = logManager; this.Cache = cacheManager; this.Preprocessing = preprocessingManager; this.SessionStartTime = runStartTime; this.Cache.SetContext(this); this.Preprocessing.SetContext(this); }
public AffineDivCurveUtils(DividendQuote[] dividends, DiscountCurve discountCurve, ITimeMeasure time) { Contract.Requires(EnumerableUtils.IsSorted(dividends.Select(div => div.Date))); if (dividends.Length > 0) { double[] divDates = dividends.Map(div => time[div.Date]); double[] spotYieldGrowths = dividends.Scan(1.0, (prev, div) => prev * (1.0 - div.Yield)); var spotYieldGrowth = new StepFunction(divDates, spotYieldGrowths, 1.0); assetGrowth = t => spotYieldGrowth.Eval(t) / discountCurve.Zc(t); double[] discountedCashs = dividends.Map(div => div.Cash / assetGrowth(time[div.Date])); double[] cashBpvs = discountedCashs.Scan(0.0, (prev, c) => prev + c); cashDivBpv = new StepFunction(divDates, cashBpvs, 0.0); cashBpvIntegral = cashDivBpv.Integral(0.0); double[] squareTimeWeightedCashs = discountedCashs.ZipWith(divDates, (c, t) => c * t * t); squareTimeWeightedCash = new StepFunction(divDates, squareTimeWeightedCashs, 0.0); } else { assetGrowth = t => 1.0 / discountCurve.Zc(t); cashDivBpv = new StepFunction(new[] { 0.0 }, new[] { 0.0 }, double.NaN); cashBpvIntegral = RrFunctions.Zero; squareTimeWeightedCash = new StepFunction(new[] { 0.0 }, new[] { 0.0 }, double.NaN); } }
public AssetForwardCurve(double spot, DividendQuote[] dividends, DiscountCurve assetFinancingCurve, ITimeMeasure time) { Contract.Requires(EnumerableUtils.IsSorted(dividends.Select(div => div.Date))); this.time = time; Spot = spot; divCurveUtils = new AffineDivCurveUtils(dividends, assetFinancingCurve, time); }
private VolatilitySurface(ITimeMeasure time, MoneynessProvider moneyness, VarianceInterpoler varianceInterpoler, LocalVariance localVariance) { Time = time; VarianceInterpoler = varianceInterpoler; Moneyness = moneyness; LocalVariance = localVariance; }
private static VolatilityMatrix AssetVolMatrix(object[,] bag, ITimeMeasure time, string assetName) { var volId = String.Format("Vol.{0}", assetName); var eqtyVolMatrix = bag.ProcessEqtyVolMatrix(volId); var pillars = eqtyVolMatrix.RowLabels.Map(d => d.ToDate(time.RefDate)); return(new VolatilityMatrix(time, pillars, eqtyVolMatrix.ColLabels, eqtyVolMatrix.Values)); }
public static BlackScholesWithDividendOption Build(double spot, DividendQuote[] dividends, DiscountCurve discountCurve, ITimeMeasure time) { var divUtils = new AffineDivCurveUtils(dividends, discountCurve, time); return(new BlackScholesWithDividendOption(spot, divUtils)); }
public override IModel Build(Bergomi2FModelDescription b2F, Market market) { ITimeMeasure time = ModelFactoryUtils.DefaultTime(market.RefDate); var assetMkt = market.AssetMarketFromName(b2F.Asset); var localDividends = b2F.WithDivs ? assetMkt.Dividends.Map(div => div.DivModel()) : new DiscreteLocalDividend[0]; return(new Bergomi2FModel(assetMkt.Asset, localDividends, time, BuildXi(b2F.Sigma, time), b2F.K1, b2F.K2, b2F.Theta, b2F.Nu, b2F.RhoXY, b2F.RhoSX, b2F.RhoSY)); }
/// <summary>Initialized method to be called once in each application session by the caller planning to use the preprocessors. /// This will try to load the plugins from the plugin folder, and try to initialize each of them. /// Will report progess to the log information action.</summary> /// <param name="pluginPath">The plugin path</param> /// <param name="logManager">The log Manager.</param> /// <param name="timeMeasure">The time Measure.</param> private void Initialize(string pluginPath, LogManager logManager, ITimeMeasure timeMeasure) { timeMeasure.Start(false, SectionIdParts.Preprocessing, SectionIdParts.Initialize); logManager.Information(ResourceStrings.PreprocessingInitializeStart.InvariantFormat(pluginPath)); // If no plugin path was provided, we use the assembly path. if (string.IsNullOrWhiteSpace(pluginPath)) { var assemblyFilInfo = new FileInfo(Assembly.GetCallingAssembly().FullName); pluginPath = assemblyFilInfo.DirectoryName; } if (!string.IsNullOrWhiteSpace(pluginPath)) { if (!Directory.Exists(pluginPath)) { logManager.Error( new DirectoryNotFoundException(pluginPath), ResourceStrings.PreprocessingCouldNotFindThePluginPath.InvariantFormat(pluginPath)); return; } // And now use MEF to load all possible plugins. logManager.Information(ResourceStrings.PreprocessingPluginPath.InvariantFormat(pluginPath)); using (var addInCatalog = new AggregateCatalog()) { addInCatalog.Catalogs.Add(new DirectoryCatalog(pluginPath)); using (var addInContainer = new CompositionContainer(addInCatalog)) { // Fill the imports of this object try { addInContainer.ComposeParts(this); } catch (CompositionException compositionException) { logManager.Error(compositionException, ResourceStrings.PreprocessingLoadingError); } foreach (var registeredPreprocessingEngine in this.registeredPreprocessingEngines) { logManager.Information( ResourceStrings.PreprocessingEngineFound.InvariantFormat(registeredPreprocessingEngine.Name)); } } } } logManager.Information(ResourceStrings.PreprocessingInitializeEnd); timeMeasure.End(false, SectionIdParts.Preprocessing, SectionIdParts.Initialize); }
public Bergomi2FModel(AssetId asset, DiscreteLocalDividend[] dividends, ITimeMeasure time, RrFunction xi, double k1, double k2, double theta, double nu, double rhoXy, double rhoSx, double rhoSy) : base(asset, dividends, time) { Xi = xi; K1 = k1; K2 = k2; Theta = theta; Nu = nu; RhoXY = rhoXy; RhoSX = rhoSx; RhoSY = rhoSy; }
public Section( Profiler profiler, ITimeMeasure timeMeasure, ITraceWriter traceWriter, string[] chain, ConcurrentQueue <Section> queue) { _profiler = profiler ?? throw new ArgumentNullException(nameof(profiler)); _timeMeasure = timeMeasure ?? throw new ArgumentNullException(nameof(timeMeasure)); _traceWriter = traceWriter ?? throw new ArgumentNullException(nameof(traceWriter)); _chain = chain ?? throw new ArgumentNullException(nameof(chain)); _queue = queue ?? throw new ArgumentNullException(nameof(queue)); }
public AssetMarket(AssetId asset, DateTime refDate, ITimeMeasure time, double spot, DiscountCurve riskFreeDiscount, DiscountCurve repoCurve, DividendQuote[] dividends, VolatilityMatrix volMatrix) { Time = time; Spot = spot; RiskFreeDiscount = riskFreeDiscount; RepoCurve = repoCurve; Dividends = dividends; VolMatrix = volMatrix; RefDate = refDate; Asset = asset; if (refDate != repoCurve.RefDate || refDate != time.RefDate) { throw new Exception("AssetMarket : incompatible ref date !"); } }
private static RrFunction BuildXi(MapRawDatas <DateOrDuration, double> sigma, ITimeMeasure time) { var matVars = EnumerableUtils.For(0, sigma.Pillars.Length, i => { var mat = time[sigma.Pillars[i].ToDate(time.RefDate)]; var variance = sigma.Values[i] * sigma.Values[i] * mat; return(new { Mat = mat, Variance = variance }); }).OrderBy(t => t.Mat).ToArray(); if (!DoubleUtils.EqualZero(matVars.First().Mat)) { matVars = matVars.Concat(new[] { new { Mat = 0.0, Variance = 0.0 } }) .OrderBy(t => t.Mat).ToArray(); } var varianceFunc = RrFunctions.LinearInterpolation(matVars.Map(t => t.Mat), matVars.Map(t => t.Variance), 0.0, double.NaN); return(varianceFunc.Derivative()); }
protected EquityModel(AssetId asset, DiscreteLocalDividend[] dividends, ITimeMeasure time) { Asset = asset; Dividends = dividends; Time = time; }
public BlackScholesModel(ITimeMeasure time, AssetId asset, RrFunction sigma, DiscreteLocalDividend[] dividends) : base(asset, dividends, time) { Sigma = sigma; }
public static RrFunction ToStepFunction(this MapRawDatas <DateOrDuration, double> rawDatasFunc, ITimeMeasure time) { var abscissae = rawDatasFunc.Pillars.Map(d => time[d.ToDate(time.RefDate)]); return(new StepFunction(abscissae, rawDatasFunc.Values, rawDatasFunc.Values.First())); }
public static DiscountCurve LinearRateInterpol(FinancingId financing, DateTime[] pillars, double[] zcs, ITimeMeasure time) { if (pillars.Length != zcs.Length) throw new Exception("LinearRateDiscountProvider : Incompatible size"); var dates = time[pillars]; var zcRates = new double[pillars.Length]; if (DoubleUtils.EqualZero(dates[0])) { if (!DoubleUtils.MachineEquality(1.0, zcs[0])) throw new Exception("LinearRateInterpol : Discount for refDate must equal to 1.0 "); zcRates[0] = 0.0; } else { zcRates[0] = -Math.Log(zcs[0]) / dates[0]; } for (int i = 1; i < zcs.Length; i++) { zcRates[i] = -Math.Log(zcs[i]) / dates[i]; } return new DiscountCurveFromRate(financing, time, RrFunctions.LinearInterpolation(dates, zcRates)); }
public DiscountCurveFromRate(FinancingId financing, ITimeMeasure time, RrFunction zcRate) : base(time.RefDate, financing) { this.time = time; this.zcRate = zcRate; }
public LocalVolatilityModel(ITimeMeasure time, AssetId asset, VolatilitySurface volSurface, MoneynessProvider moneyness, DiscreteLocalDividend[] dividends) : base(asset, dividends, time) { VolSurface = volSurface; Moneyness = moneyness; }
/// <summary>Initializes a new instance of the <see cref="PreprocessingManager"/> class. /// Initializes a new instance of the <see cref="PreprocessingManager"/>. /// Can only be called from within the class by the Singleton construction.</summary> /// <param name="webGreaseConfiguration">The web Grease Configuration.</param> /// <param name="logManager">The log Manager.</param> /// <param name="timeMeasure">The time Measure.</param> internal PreprocessingManager(WebGreaseConfiguration webGreaseConfiguration, LogManager logManager, ITimeMeasure timeMeasure) { if (webGreaseConfiguration == null) { throw new ArgumentNullException("webGreaseConfiguration"); } if (logManager == null) { throw new ArgumentNullException("logManager"); } if (timeMeasure == null) { throw new ArgumentNullException("timeMeasure"); } this.Initialize(webGreaseConfiguration.PreprocessingPluginPath, logManager, timeMeasure); }