using YLErp.Enums;
using YLErp.Modules.ApiModule.PricingModule;
using YLErp.Modules.ApiModule.PricingModule.CustomizedAsianPricing;
using YLErp.Modules.PricingModule;
namespace YLWebAPI.ApiModule.ManagerApi
{
///
/// 交易定价API
///
public class TradePricingController : BaseApiController
{
///
/// 期权定价
///
[HttpPost, Route("api/v1/optionPricing"), ManagerAuth]
public ApiResponseModel optionPricing2([FromBody] OptionPricingModelV1 reqModel)
{
if (reqModel == null)
{
return JsonError("参数为null");
}
var result = new PriceCalcService(CurUser).CalcOptionPrice(reqModel.Trades, reqModel.IsCalcMargin, CalcScenarioEnum.Pricing, td => reqModel.IsCalcGreeks);
return JsonSuccess(result);
}
///
/// 期权定价
///
[HttpPost, Route("api/v1/otc-option/pricing"), ManagerAuth]
public ApiResponseModel OtcOptionPricing([FromBody] OptionPricingModelV2 req)
{
if (req is null)
{
return JsonError("参数不能为空");
}
var result = new OptionPricingApiService().GetOptionPrice(req);
return JsonSuccess(new
{
req.CalcId,
InitialMargin = result.initialMargin,
ContractSize = result.contractSize,
result.calcResult.Pv,
result.calcResult.Delta,
result.calcResult.Gamma,
result.calcResult.Vega,
result.calcResult.Theta,
result.calcResult.Rho
});
}
///
/// 保险加期货等奇异但不太常用的奇异期权定价,如各种亚式变种等
///
[HttpPost, Route("api/v1/otc-option/customized_asian_pricing"), ManagerAuth]
public ApiResponseModel CustomizedAsianPricing([FromBody] CustomizedAsianPricingModel req)
{
if (req is null)
{
return JsonError("参数不能为空");
}
if (req.ExoticAsianType == "触碰锁定增强亚式期权") // 宏源恒利的保险加期货产品2022
{
var result = new OptionPricingApiService().GetCustomizedAsianOptionPrice(req);
return JsonSuccess(new
{
req.CalcId,
InitialMargin = result.initialMargin,
ContractSize = result.contractSize,
result.calcResult.Pv,
result.calcResult.Delta,
result.calcResult.Gamma,
result.calcResult.Vega,
result.calcResult.Theta,
result.calcResult.Rho
});
}
else
{
return JsonError("不支持的期权类型");
}
}
///
/// 雪球期权反算票息
///
[HttpPost, Route("api/v1/otc-option/snowball/calc_korebate"), ManagerAuth]
public ApiResponseModel CalcSnowballKoRebate([FromBody] OptionPricingModelV2 req)
{
OptionPricingApiHelper.CheckPricingRequestData(req);
req.TradeType = "雪球期权";
var korebate = new PriceCalcService(CurUser).CalcSnowballKORebate(req);
return JsonSuccess(korebate);
}
}
}