66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using Qdp.Pricing.Base.Enums;
|
|
using Qdp.Pricing.Library.Common.Interfaces;
|
|
using Qdp.Pricing.Library.Options.MonteCarlo;
|
|
using Qdp.Pricing.Library.Options.Products.Autocall.Phoenix.Numerical;
|
|
|
|
namespace YLErp.BLL.Calculation.Engine
|
|
{
|
|
class AutoCallEngineFactory : OptionEngineFactoryBase
|
|
{
|
|
public static AutoCallEngineFactory Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = new AutoCallEngineFactory();
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
protected AutoCallEngineFactory() { }
|
|
protected static AutoCallEngineFactory _instance;
|
|
|
|
public override IEngine GetEngine(
|
|
string engineName = null,
|
|
OptionExercise exercise = OptionExercise.European,
|
|
params object[] additionalParams)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(engineName))
|
|
{
|
|
return DefaultEngine(additionalParams);
|
|
}
|
|
else if (engineName.ToUpper() == "GBMMONTECARLOENGINE")
|
|
{
|
|
return new GbmMonteCarloEngine(100000, 1e-3, 1e-6, 1);
|
|
}
|
|
else if (engineName.IsValidEngineName())
|
|
{
|
|
return OptionEngineRepository.CreateEngine(engineName);
|
|
}
|
|
else
|
|
{
|
|
throw new Exception($"无法创建计算引擎{engineName}");
|
|
}
|
|
}
|
|
|
|
private IEngine DefaultEngine(params object[] additionalParams)
|
|
{
|
|
var quadratureFastMode = false;
|
|
if (additionalParams.Length > 0)
|
|
{
|
|
quadratureFastMode = (bool)additionalParams[0];
|
|
}
|
|
|
|
if (quadratureFastMode)
|
|
{
|
|
return new QuadAutoCallEngine(parallelDegree: Environment.ProcessorCount);
|
|
}
|
|
else
|
|
{
|
|
return new QuadAutoCallEngine(parallelDegree: PS.Config.ErpElement.QdpParallelDegree);
|
|
}
|
|
}
|
|
}
|
|
}
|