150 lines
5.3 KiB
C#
150 lines
5.3 KiB
C#
using YLErp.BLL;
|
|
using YLErp.Modules.DataProviderModule;
|
|
using YLErp.Modules.UnderlyingModule;
|
|
using YLErp.QdpModule;
|
|
|
|
namespace YLErp.Modules.PricingModule
|
|
{
|
|
/// <summary>
|
|
/// 定价页面数据服务
|
|
/// </summary>
|
|
public class PricingDataService : YLBaseService
|
|
{
|
|
public PricingDataService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取定价页面初始数据
|
|
/// </summary>
|
|
public PricingInitValueResult GetPricingInitValues(PricingInitValuesRequest req)
|
|
{
|
|
if (req is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(req));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(req.UnderlyingCode))
|
|
{
|
|
throw new ServiceException("缺少标的代码");
|
|
}
|
|
|
|
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(req.UnderlyingCode);
|
|
|
|
if (um == null)
|
|
{
|
|
throw new ServiceException("找不到标的数据:" + req.UnderlyingCode);
|
|
}
|
|
|
|
//create result
|
|
|
|
var result = new PricingInitValueResult
|
|
{
|
|
ValueDate = valuedateBLL.ValueDate,
|
|
StartDate = valuedateBLL.ValueDate,
|
|
MaturityDate = um.MaturityDate ?? DateTime.Today,
|
|
CountRatio = um.CountRatio,
|
|
TradeUnit = um.TradeUnit,
|
|
QuoteUnit = um.QuoteUnitString,
|
|
PriceDigits = 2
|
|
};
|
|
|
|
if (!um.IsFutures())
|
|
{
|
|
result.MaturityDate = DateTime.Today.AddYears(10);
|
|
if (um.UnderlyingInstrumentType == ConsGlobal.InstrumentType.Shibor)
|
|
{
|
|
result.PriceDigits = 6;
|
|
}
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(result.QuoteUnit))
|
|
{
|
|
var va = DataCacheProvider.GetVarietyDataSource().GetData(um.UnderlyingTypeId);
|
|
result.QuoteUnit = "JD".Equals(va?.VarietyCode, StringComparison.OrdinalIgnoreCase) ? "半吨" : va?.QuoteUnit;
|
|
if (string.IsNullOrWhiteSpace(result.TradeUnit))
|
|
{
|
|
result.TradeUnit = va?.TradeUnitSingle;
|
|
}
|
|
}
|
|
|
|
//开始日期
|
|
if (result.StartDate > result.MaturityDate)
|
|
{
|
|
result.StartDate = result.MaturityDate.AddMonths(-1);
|
|
}
|
|
|
|
//结束日期
|
|
result.ExerciseDate = QdpCalendarHelper.GetNonHoliday(result.StartDate.AddYears(2).AddDays(-1));
|
|
if (result.MaturityDate < result.ExerciseDate)
|
|
{
|
|
result.ExerciseDate = QdpCalendarHelper.GetNonHolidayDefore(result.MaturityDate);
|
|
}
|
|
|
|
//期初标的价格
|
|
result.SpotPrice = um.Price ?? 0;
|
|
|
|
if (result.StartDate != valuedateBLL.ValueDate)
|
|
{
|
|
if (um.CommodityCode == "组合标的")
|
|
{
|
|
result.Synthetic = new SyntheticUnderlyingPriceService(OptUser).GetPriceModel(um.UnderlyingCode, result.StartDate);
|
|
|
|
if (result.Synthetic == null)
|
|
{
|
|
throw new ServiceException("组合标的信息未找到:" + um.UnderlyingCode);
|
|
}
|
|
|
|
result.SpotPrice = result.Synthetic.Price;
|
|
}
|
|
else if (EodPriceQueryService.TryGetEodPrice(result.StartDate, um.UnderlyingCode, out var eodPrice))
|
|
{
|
|
result.SpotPrice = eodPrice.ClosePrice;
|
|
}
|
|
}
|
|
else if (um.CommodityCode == "组合标的")
|
|
{
|
|
//返回组合标的中组成标的的现价
|
|
result.Synthetic = new SyntheticUnderlyingPriceService(OptUser).GetPriceModel(um.UnderlyingCode);
|
|
result.SpotPrice = result.Synthetic.Price;
|
|
}
|
|
|
|
//是否名义本金方式
|
|
result.IsUsePremiumRate = um.CalcTypeIsStock();
|
|
|
|
//是否相对行权价
|
|
result.IsMoneynessOption = result.IsUsePremiumRate ? "是" : "否";
|
|
|
|
//无风险利率
|
|
result.NoRiskRate = valuedateBLL.GetRiskFreeRateFromCurveV2(result.StartDate, result.ExerciseDate);
|
|
|
|
//分红率
|
|
result.DividenRate = um.DividendRate ?? 0;
|
|
|
|
//标的对应的日历
|
|
var market = string.IsNullOrWhiteSpace(um.MarketCode)
|
|
? null : DataCacheProvider.GetMarketDataSource().AsQueryable().FirstOrDefault(n => n.ExchangeNo == um.MarketCode);
|
|
|
|
result.CalendarName = market?.CalendarName ?? "chn";
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取不超过到期日的实行日
|
|
/// 1个月,2周,1周,到日期这样的规则向前计算
|
|
/// </summary>
|
|
public static DateTime GetUnderlyingExerciseDate(DateTime underlyingMaturityDate, DateTime SystemDate)
|
|
{
|
|
var exerciseDate = QdpCalendarHelper.GetNonHoliday(SystemDate.AddYears(2).AddDays(-1));
|
|
|
|
if (underlyingMaturityDate < exerciseDate)
|
|
{
|
|
exerciseDate = QdpCalendarHelper.GetNonHolidayDefore(underlyingMaturityDate);
|
|
}
|
|
|
|
return exerciseDate;
|
|
}
|
|
}
|
|
}
|