void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const { auto activePaintingResource = this->activePaintingResource(); if (!activePaintingResource) { // TODO: We're only supporting simple filled HTML text so far. RenderSVGResourceSolidColor* solidPaintingResource = RenderSVGResource::sharedSolidPaintingResource(); solidPaintingResource->setColor(context->fillColor()); activePaintingResource = solidPaintingResource; } auto& elementRenderer = renderer().isRenderElement() ? toRenderElement(renderer()) : *renderer().parent(); RenderStyle& style = elementRenderer.style(); ASSERT(activePaintingResource); RenderSVGResourceMode resourceMode = context->textDrawingMode() == TextModeStroke ? ApplyToStrokeMode : ApplyToFillMode; auto translator(createGlyphToPathTranslator(*fontData, glyphBuffer, from, numGlyphs, point)); while (translator->containsMorePaths()) { Path glyphPath = translator->nextPath(); if (activePaintingResource->applyResource(elementRenderer, style, context, resourceMode)) { float strokeThickness = context->strokeThickness(); if (renderer().isSVGInlineText()) context->setStrokeThickness(strokeThickness * toRenderSVGInlineText(renderer()).scalingFactor()); activePaintingResource->postApplyResource(elementRenderer, context, resourceMode, &glyphPath, 0); context->setStrokeThickness(strokeThickness); } } }
// returns 1 on success, 0 if we're already on the last cube extern int nextCube( int r, int n, int cube[] ) { while(1) { int ret = nextPath( r, n, cube ); if( ret == 1 ) return 1; if( ret == -1 ) return 0; } }
CatBond::results MonteCarloCatBondEngine::npv(bool includeSettlementDateFlows, Date settlementDate, Date npvDate) const { const size_t MAX_PATHS = 10000; //TODO CatBond::results result; result.reset(); double lossProbability = 0.0; double exhaustionProbability = 0.0; double expectedLoss = 0.0; //GenericRiskStatistics<GeneralStatistics> statistics; GeneralStatistics statistics; if (arguments_.cashflows.empty()) { return result; } if (settlementDate == Date()) settlementDate = Settings::instance().evaluationDate(); if (npvDate == Date()) npvDate = settlementDate; Real totalNPV = 0.0; Date effectiveDate = std::max(arguments_.startDate, settlementDate); Date maturityDate = (*arguments_.cashflows.rbegin())->date(); auto catSimulation = catRisk_->newSimulation(effectiveDate, maturityDate); std::vector<std::pair<Date, Real> > eventsPath; NotionalPath notionalPath; Real riskFreeNPV = pathNpv(includeSettlementDateFlows, settlementDate, notionalPath); size_t pathCount=0; while(catSimulation->nextPath(eventsPath) && pathCount<MAX_PATHS) { arguments_.notionalRisk->updatePath(eventsPath, notionalPath); if(notionalPath.loss()>0) { //optimization, most paths will not include any loss double thisNpv = pathNpv(includeSettlementDateFlows, settlementDate, notionalPath); totalNPV += thisNpv; lossProbability+=1; if (notionalPath.loss()==1) exhaustionProbability+=1; expectedLoss+=notionalPath.loss(); statistics.add(thisNpv, 1.0); } else { totalNPV += riskFreeNPV; statistics.add(riskFreeNPV, 1.0); } pathCount++; } lossProbability/=pathCount; exhaustionProbability/=pathCount; expectedLoss/=pathCount; result.valuationDate = settlementDate; result.value = totalNPV/(pathCount*discountCurve_->discount(npvDate)); result.settlementValue = result.value; result.lossProbability = lossProbability; result.exhaustionProbability = exhaustionProbability; result.expectedLoss = expectedLoss; if(Null<Real>()!=varLevel_) { result.var = result.value - statistics.percentile(1.0-varLevel_); result.stdDev = statistics.standardDeviation(); result.skew = statistics.skewness(); result.kurtosis = statistics.kurtosis(); } return result; }