从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
using YLErp.Enums;
|
||||
using YLErp.Modules.PricingModule;
|
||||
|
||||
namespace YLErp.Web.WebAPI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 期权定价
|
||||
/// </summary>
|
||||
public class PricingController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算pv margin greeks
|
||||
/// </summary>
|
||||
[HttpPost("m/api/pricing/calc-basic")]
|
||||
public JsonResult Calc(OtcOptionTradeFull req)
|
||||
{
|
||||
if (req is null)
|
||||
{
|
||||
return JsonError("错误:请求参数为空");
|
||||
}
|
||||
|
||||
var trade = InitialTrade(req);
|
||||
|
||||
var result = new PriceCalcService(CurUser).CalcOptionPrice(trade, false, CalcScenarioEnum.Pricing, true);
|
||||
|
||||
return JsonSuccess(new { result.calcResult, result.Day1Pnl });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据权利金反算
|
||||
/// </summary>
|
||||
[HttpPost("m/api/pricing/calc-target")]
|
||||
public JsonResult CalcTargetValue(OtcOptionTradeFull req, int calTarget)
|
||||
{
|
||||
if (req is null)
|
||||
{
|
||||
return JsonError("错误:请求参数为空");
|
||||
}
|
||||
|
||||
var trade = InitialTrade(req);
|
||||
trade.TradePrice = trade.TradeSinglePrice;
|
||||
|
||||
var targetValue = new PriceCalcService(CurUser).CalcSnowballSpecialistTargetValue(trade, calTarget);
|
||||
//敲出票息和红利票息
|
||||
if (calTarget == 1)
|
||||
{
|
||||
var obsInfos = trade.KOObservationDates.Split(';');
|
||||
var kORebates = obsInfos[2].Split(',');
|
||||
trade.KOObservationDates = string.Join(";", new[] {
|
||||
obsInfos[0],
|
||||
obsInfos[1],
|
||||
string.Join(",",kORebates.Select(x => String.IsNullOrEmpty(x) ? targetValue.ToString() : x))
|
||||
});
|
||||
trade.Coupon = targetValue;
|
||||
}
|
||||
//敲出票息
|
||||
else if (calTarget == 2)
|
||||
{
|
||||
var obsInfos = trade.KOObservationDates.Split(';');
|
||||
var kORebates = obsInfos[2].Split(',');
|
||||
trade.KOObservationDates = string.Join(";", new[] {
|
||||
obsInfos[0],
|
||||
obsInfos[1],
|
||||
string.Join(",",kORebates.Select(x => String.IsNullOrEmpty(x) ? targetValue.ToString() : x))
|
||||
});
|
||||
}
|
||||
//红利票息
|
||||
else if (calTarget == 3)
|
||||
{
|
||||
trade.Coupon = targetValue;
|
||||
}
|
||||
|
||||
var result = new PriceCalcService(CurUser).CalcOptionPrice(trade, false, CalcScenarioEnum.Pricing, false);
|
||||
|
||||
return JsonSuccess(new { TargetValue = double.IsNaN(targetValue) ? 0 : targetValue, result.calcResult });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定价页面初始值
|
||||
/// </summary>
|
||||
[HttpPost("m/api/pricing/init-values")]
|
||||
public JsonResult GetInitValues(PricingInitValuesRequest req)
|
||||
{
|
||||
var result = new PricingDataService(CurUser).GetPricingInitValues(req);
|
||||
return JsonSuccess(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化交易参数
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
private OtcOptionTradeFull InitialTrade(OtcOptionTradeFull trade)
|
||||
{
|
||||
//OtcOptionTradeFull trade = new OtcOptionTradeFull();
|
||||
//YLAutoMapper.Map<OptionPricingModelV3, OtcOptionTradeFull>(req, trade);
|
||||
|
||||
// initial trade params
|
||||
trade.PrepaymentUsed = true;
|
||||
if (string.IsNullOrEmpty(trade.CouponDayCount) || trade.CouponDayCount == "非年化")
|
||||
{
|
||||
trade.CouponDayCount = string.Empty;
|
||||
trade.IsFixedCoupon = true;
|
||||
}
|
||||
trade.TradeDate = trade.StartDate;
|
||||
trade.AnnualizeFactor2 = 1;
|
||||
trade.NumOfSmoothingDays = 1;
|
||||
trade.ParentTradeId = 0;
|
||||
trade.TradeCloseVolatility = trade.Vol;
|
||||
trade.TradeOpenVolatility = trade.Vol;
|
||||
trade.AnnualizeFactor = 1;
|
||||
trade.ParticipationRate = 1;
|
||||
trade.IsGroup = 0;
|
||||
trade.CountRatio = 1;
|
||||
if (!trade.MetaDic.ContainsKey("敲入观察周期"))
|
||||
{
|
||||
trade.MetaDic.Add("敲入观察周期", "1D");
|
||||
}
|
||||
return trade;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user