111 lines
3.7 KiB
C#
111 lines
3.7 KiB
C#
using CsvHelper;
|
|
using NPOI.OpenXmlFormats.Dml;
|
|
using Qdp.Foundation.Implementations;
|
|
using Qdp.Pricing.Base.Enums;
|
|
using Qdp.Pricing.Base.Implementations;
|
|
using Qdp.Pricing.Base.Utilities;
|
|
using Qdp.Pricing.Ecosystem.Trade.Options;
|
|
using Qdp.Pricing.Library.Options.Products.Autocall.Phoenix;
|
|
using Qdp.Pricing.Library.Options.Products.Autocall.Snowball;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using YLErp.Abstract;
|
|
using YLErp.BLL;
|
|
using YLErp.BLL.Eod;
|
|
using YLErp.DBModels;
|
|
using YLErp.DBModels.Helpers;
|
|
using YLErp.Model;
|
|
using YLErp.Models;
|
|
using YLErp.Modules.CalculationModule.Abstract;
|
|
using YLErp.Modules.TradeModule;
|
|
using YLErp.Modules.TradeModule.AccumulatorOptionModule;
|
|
using YLErp.Modules.TradeModule.KnockOutModule;
|
|
using YLErp.Modules.TradeModule.KnockOutModule.Dto;
|
|
using YLErp.QdpModule;
|
|
|
|
namespace YLErp.Modules.CalculationModule
|
|
{
|
|
/// <summary>
|
|
/// 交易敲出收益计算服务
|
|
/// </summary>
|
|
public class TradeKnockOutPayoffCalcService : ITradeKnockOutPayoffCalcService
|
|
{
|
|
|
|
private ITradeExtendDataProvider _tradeExtendDataProvider;
|
|
private DateTime _valueDate;
|
|
|
|
public TradeKnockOutPayoffCalcService(ITradeExtendDataProvider tradeExtendDataProvider, DateTime valueDate)
|
|
{
|
|
_tradeExtendDataProvider = tradeExtendDataProvider;
|
|
_valueDate = valueDate;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用于定价页面 敲出收益计算 此时交易未入库
|
|
/// </summary>
|
|
/// <param name="valueDate"></param>
|
|
public TradeKnockOutPayoffCalcService(DateTime valueDate)
|
|
{
|
|
this._tradeExtendDataProvider = null;
|
|
_valueDate = valueDate;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取敲出payoff
|
|
/// </summary>
|
|
/// <param name="td"></param>
|
|
/// <param name="underlyingPrice"></param>
|
|
/// <returns></returns>
|
|
public GetKnockOutPayoffResult GetKnockOutPayoff(trade td,double underlyingPrice)
|
|
{
|
|
GetKnockOutPayoffResult result = new GetKnockOutPayoffResult { IsKnockOut = false };
|
|
if (td.ExerciseDate < _valueDate)
|
|
{
|
|
return result;
|
|
}
|
|
ITradeKnockOutService knockOutService = null;
|
|
switch (td.TradeType)
|
|
{
|
|
case "障碍期权":
|
|
knockOutService = new BarrierOptionTradeKnockOutService();
|
|
break;
|
|
case "二元期权":
|
|
if ("American".Equals(td.ExerciseMode))
|
|
{
|
|
knockOutService = new AmericanBinaryOptionTradeKnockOutService();
|
|
}
|
|
break;
|
|
case "双鲨期权":
|
|
knockOutService = new DoubleSharkTradeKnockOutService();
|
|
break;
|
|
case "凤凰期权":
|
|
knockOutService = new AutocallTradeKnockOutService();
|
|
break;
|
|
case "雪球期权":
|
|
knockOutService = new SnowBallTradeKnockOutService();
|
|
break;
|
|
case "累计期权":
|
|
knockOutService=new AccumulatorTradeKnockOutService();
|
|
break;
|
|
|
|
}
|
|
|
|
if(knockOutService != null)
|
|
{
|
|
if (this._tradeExtendDataProvider != null)
|
|
{
|
|
return knockOutService.GetKnockOutPayoff(td, underlyingPrice, _valueDate, _tradeExtendDataProvider);
|
|
}
|
|
else
|
|
{
|
|
return knockOutService.GetKnockOutPayoff(td, underlyingPrice, _valueDate);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|