Skip to content

Commit

Permalink
threaded calc
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Sep 18, 2024
1 parent d002b19 commit b57fc16
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Qwack.Options/VolSurfaces/LocalVol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
using Qwack.Core.Models;
using Qwack.Options.VolSurfaces;
using Qwack.Transport.BasicTypes;
using Qwack.Utils.Parallel;
using static System.Math;

namespace Qwack.Options
{
public static class LocalVol
{
public static double[][] ComputeLocalVarianceOnGrid(this IVolSurface VanillaSurface, double[][] strikes, double[] timeSteps, Func<double, double> forwardFunc)
public static double[][] ComputeLocalVarianceOnGrid(this IVolSurface VanillaSurface, double[][] strikes, double[] timeSteps, Func<double, double> forwardFunc, int firstTimeStep = 0)
{
var numberOfTimesteps = timeSteps.Length;
var deltaK = 0.001 * forwardFunc(timeSteps[0]);
Expand All @@ -26,7 +27,7 @@ public static double[][] ComputeLocalVarianceOnGrid(this IVolSurface VanillaSurf
}


for (var it = 1; it < numberOfTimesteps; it++)
for (var it = firstTimeStep + 1; it < numberOfTimesteps; it++)
{
var numberOfStrikes = strikes[it - 1].Length;
lvGrid[it - 1] = new double[numberOfStrikes];
Expand Down Expand Up @@ -140,8 +141,8 @@ public static double[][] ComputeLocalVarianceOnGridFromCalls2(this IVolSurface V

var fwds = timeSteps.Select(t => forwardFunc(t)).ToArray();

//ParallelUtils.Instance.For(1, numberOfTimesteps, 1, it =>
for (var it = firstTimeStep + 1; it < numberOfTimesteps; it++)
ParallelUtils.Instance.For(firstTimeStep + 1, numberOfTimesteps, 1, it =>
//for (var it = firstTimeStep + 1; it < numberOfTimesteps; it++)
{
var T = timeSteps[it];
var T1 = timeSteps[it - 1];
Expand Down Expand Up @@ -194,7 +195,7 @@ public static double[][] ComputeLocalVarianceOnGridFromCalls2(this IVolSurface V
var V = VanillaSurface.GetVolForAbsoluteStrike(K, T, fwd);
lvGrid[it - 1][0] = V * V;
}
}//, false).Wait();
}, false).Wait();

return lvGrid;
}
Expand Down

0 comments on commit b57fc16

Please sign in to comment.