Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Mar 19, 2020
1 parent dbc08c6 commit d4bb112
Show file tree
Hide file tree
Showing 25 changed files with 247 additions and 179 deletions.
12 changes: 6 additions & 6 deletions clients/Qwack.Excel/Capital/CapitalFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CapitalFunctions
{
private static readonly ILogger _logger = ContainerStores.GlobalContainer.GetService<ILoggerFactory>()?.CreateLogger<CapitalFunctions>();

[ExcelFunction(Description = "Computes SA-CCR EAD", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeEAD), IsThreadSafe = true)]
[ExcelFunction(Description = "Computes SA-CCR EAD", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeEAD))]
public static object ComputeEAD(
[ExcelArgument(Description = "Portfolio object")] string PortfolioName,
[ExcelArgument(Description = "AssetFx model")] string VanillaModel,
Expand All @@ -39,7 +39,7 @@ public class CapitalFunctions
}


[ExcelFunction(Description = "Computes CVA from an EPE profile", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCVA), IsThreadSafe = true)]
[ExcelFunction(Description = "Computes CVA from an EPE profile", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCVA))]
public static object ComputeCVA(
[ExcelArgument(Description = "Hazzard curve")] string HazzardCurveName,
[ExcelArgument(Description = "Origin date")] DateTime OriginDate,
Expand Down Expand Up @@ -76,7 +76,7 @@ public class CapitalFunctions
});
}

[ExcelFunction(Description = "Computes approximate CVA for a portfolio", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCVAApprox), IsThreadSafe = true)]
[ExcelFunction(Description = "Computes approximate CVA for a portfolio", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCVAApprox))]
public static object ComputeCVAApprox(
[ExcelArgument(Description = "Hazzard curve")] string HazzardCurveName,
[ExcelArgument(Description = "Origin date")] DateTime OriginDate,
Expand All @@ -99,7 +99,7 @@ public class CapitalFunctions
});
}

[ExcelFunction(Description = "Solves strike for a target RoC", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(SolveStrikeForTargetRoC), IsThreadSafe = true)]
[ExcelFunction(Description = "Solves strike for a target RoC", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(SolveStrikeForTargetRoC))]
public static object SolveStrikeForTargetRoC(
[ExcelArgument(Description = "Hazzard curve")] string HazzardCurveName,
[ExcelArgument(Description = "Discount curve")] string DiscountCurve,
Expand All @@ -124,7 +124,7 @@ public class CapitalFunctions
});
}

[ExcelFunction(Description = "Computes Basel II CVA risk weighted assets from an EPE profile", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCvaRwaBaselII_IMM), IsThreadSafe = true)]
[ExcelFunction(Description = "Computes Basel II CVA risk weighted assets from an EPE profile", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCvaRwaBaselII_IMM))]
public static object ComputeCvaRwaBaselII_IMM(
[ExcelArgument(Description = "Origin date")] DateTime OriginDate,
[ExcelArgument(Description = "EPE profile, cube or array")] object EPEProfile,
Expand Down Expand Up @@ -158,7 +158,7 @@ public class CapitalFunctions
}


[ExcelFunction(Description = "Computes Basel III CVA capital from an EPE profile", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCVACapitalBaselIII), IsThreadSafe = true)]
[ExcelFunction(Description = "Computes Basel III CVA capital from an EPE profile", Category = CategoryNames.Capital, Name = CategoryNames.Capital + "_" + nameof(ComputeCVACapitalBaselIII))]
public static object ComputeCVACapitalBaselIII(
[ExcelArgument(Description = "Origin date")] DateTime OriginDate,
[ExcelArgument(Description = "EPE profile, cube or array")] object EPEProfile,
Expand Down
34 changes: 26 additions & 8 deletions clients/Qwack.Excel/ContainerStores.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -37,24 +39,26 @@ static ContainerStores()

PnLAttributor = new PnLAttributor();
}
catch(Exception ex)
catch (Exception ex)
{
if(Directory.Exists(@"C:\Temp"))
if (Directory.Exists(@"C:\Temp"))
{
File.WriteAllText($@"C:\Temp\QwackInitializationError_{DateTime.Now:yyyyMMdd_HHmmss}.txt", ex.ToString());
}
}
}
}

public static IServiceProvider GlobalContainer { get; internal set; }
public static IServiceProvider SessionContainer { get;set;}
public static IServiceProvider SessionContainer { get; set; }
public static ICurrencyProvider CurrencyProvider => GlobalContainer.GetRequiredService<ICurrencyProvider>();
public static ICalendarProvider CalendarProvider => GlobalContainer.GetRequiredService<ICalendarProvider>();
public static IFutureSettingsProvider FuturesProvider => GlobalContainer.GetRequiredService<IFutureSettingsProvider>();
public static ILogger GetLogger<T>() => GlobalContainer.GetRequiredService<ILoggerFactory>().CreateLogger<T>();

public static IPnLAttributor PnLAttributor { get; set; }
private static Dictionary<Type, IFlushable> _registeredTypes = new Dictionary<Type, IFlushable>();

public static IPnLAttributor PnLAttributor { get; set; }

private static string GetFutureSettingsFile() => Path.Combine(GetRunningDirectory(), _futureSettingsFile);

private static string GetRunningDirectory()
Expand All @@ -68,8 +72,22 @@ private static string GetRunningDirectory()
private static string GetCalendarFilename() => Path.Combine(GetRunningDirectory(), _calendarJSONFile);
private static string GetCurrenciesFilename() => Path.Combine(GetRunningDirectory(), _currenciesFile);

public static IObjectStore<T> GetObjectCache<T>() => SessionContainer.GetService<IObjectStore<T>>();
public static IObjectStore<T> GetObjectCache<T>()
{
var os = SessionContainer.GetService<IObjectStore<T>>();
_registeredTypes[typeof(T)] = os;
return os;
}
public static T GetObjectFromCache<T>(string name) => SessionContainer.GetService<IObjectStore<T>>().GetObject(name).Value;
public static void PutObjectToCache<T>(string name, T obj) => SessionContainer.GetService<IObjectStore<T>>().PutObject(name, new SessionItem<T> { Name = name, Value = obj, Version = 1 });
public static void PutObjectToCache<T>(string name, T obj) => GetObjectCache<T>().PutObject(name, new SessionItem<T> { Name = name, Value = obj, Version = 1 });

public static void FlushCache<T>() => SessionContainer.GetService<IObjectStore<T>>().Clear();
public static void FlushAllCaches()
{
foreach (var t in _registeredTypes)
{
t.Value.Clear();
}
}
}
}
22 changes: 11 additions & 11 deletions clients/Qwack.Excel/Cubes/CubeFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CubeFunctions
{
private static readonly ILogger _logger = ContainerStores.GlobalContainer.GetService<ILoggerFactory>()?.CreateLogger<CubeFunctions>();

[ExcelFunction(Description = "Displays a cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(DisplayCube), IsThreadSafe = true)]
[ExcelFunction(Description = "Displays a cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(DisplayCube))]
public static object DisplayCube(
[ExcelArgument(Description = "Cube name")] string ObjectName,
[ExcelArgument(Description = "Pad output with whitespace beyond edges of result - defualt false")] object PaddedOutput)
Expand Down Expand Up @@ -55,7 +55,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Displays value of a cube object for given row", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(DisplayCubeValueForRow), IsThreadSafe = true)]
[ExcelFunction(Description = "Displays value of a cube object for given row", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(DisplayCubeValueForRow))]
public static object DisplayCubeValueForRow(
[ExcelArgument(Description = "Cube name")] string ObjectName,
[ExcelArgument(Description = "Row index, zero-based")] int RowIndex)
Expand All @@ -75,7 +75,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Creates a cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CreateCube), IsThreadSafe = true)]
[ExcelFunction(Description = "Creates a cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CreateCube))]
public static object CreateCube(
[ExcelArgument(Description = "Cube name")] string ObjectName,
[ExcelArgument(Description = "Header range")] object[] Headers,
Expand Down Expand Up @@ -109,7 +109,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Creates a new cube object by aggregating another cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(AggregateCube), IsThreadSafe = true)]
[ExcelFunction(Description = "Creates a new cube object by aggregating another cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(AggregateCube))]
public static object AggregateCube(
[ExcelArgument(Description = "Output cube name")] string OutputObjectName,
[ExcelArgument(Description = "Input cube name")] string InputObjectName,
Expand All @@ -130,7 +130,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Creates a new cube object by filtering another cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(FilterCube), IsThreadSafe = true)]
[ExcelFunction(Description = "Creates a new cube object by filtering another cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(FilterCube))]
public static object FilterCube(
[ExcelArgument(Description = "Output cube name")] string OutputObjectName,
[ExcelArgument(Description = "Input cube name")] string InputObjectName,
Expand All @@ -152,7 +152,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Creates a new cube object by sorting another cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(SortCube), IsThreadSafe = true)]
[ExcelFunction(Description = "Creates a new cube object by sorting another cube object", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(SortCube))]
public static object SortCube(
[ExcelArgument(Description = "Output cube name")] string OutputObjectName,
[ExcelArgument(Description = "Input cube name")] string InputObjectName,
Expand All @@ -172,7 +172,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Lists distinct values in a specified field for a given cube", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(FieldValues), IsThreadSafe = true)]
[ExcelFunction(Description = "Lists distinct values in a specified field for a given cube", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(FieldValues))]
public static object FieldValues(
[ExcelArgument(Description = "Input cube name")] string InputObjectName,
[ExcelArgument(Description = "Field name")] string FieldName)
Expand All @@ -188,7 +188,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Produces a matrix for two given fields from a given cube", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CubeToMatrix), IsThreadSafe = true)]
[ExcelFunction(Description = "Produces a matrix for two given fields from a given cube", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CubeToMatrix))]
public static object CubeToMatrix(
[ExcelArgument(Description = "Input cube name")] string InputObjectName,
[ExcelArgument(Description = "Field name vertical")] string FieldNameV,
Expand All @@ -206,7 +206,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Writes contents of cube object to csv", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CubeToCSV), IsThreadSafe = true)]
[ExcelFunction(Description = "Writes contents of cube object to csv", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CubeToCSV))]
public static object CubeToCSV(
[ExcelArgument(Description = "Input cube name")] string InputObjectName,
[ExcelArgument(Description = "Output filename")] string FileName)
Expand All @@ -222,7 +222,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Reads contents of cube object from csv", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CubeFromCSV), IsThreadSafe = true)]
[ExcelFunction(Description = "Reads contents of cube object from csv", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(CubeFromCSV))]
public static object CubeFromCSV(
[ExcelArgument(Description = "Output cube name")] string ObjectName,
[ExcelArgument(Description = "Input filename")] string FileName)
Expand All @@ -234,7 +234,7 @@ public class CubeFunctions
});
}

[ExcelFunction(Description = "Creates a new cube, adding a bucketed time field", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(BucketTimeAxis), IsThreadSafe = true)]
[ExcelFunction(Description = "Creates a new cube, adding a bucketed time field", Category = CategoryNames.Cubes, Name = CategoryNames.Cubes + "_" + nameof(BucketTimeAxis))]
public static object BucketTimeAxis(
[ExcelArgument(Description = "Output cube name")] string OutputObjectName,
[ExcelArgument(Description = "Input cube name")] string InputObjectName,
Expand Down
Loading

0 comments on commit d4bb112

Please sign in to comment.