从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
using Qdp.Foundation.Implementations;
|
||||
using YLErp.QdpModule;
|
||||
|
||||
namespace YLErp.Modules.TradeModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 交易观察频率帮助类(迁移自tradeController)
|
||||
/// </summary>
|
||||
public static class TradeObservationHelper
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="observationDates"></param>
|
||||
/// <param name="valueDate"></param>
|
||||
/// <returns></returns>
|
||||
public static double? GetPriceByDate(string observationDates, DateTime valueDate)
|
||||
{
|
||||
var customizedResults = QdpHelper.ParseAutocallCustomizedInfo(observationDates);
|
||||
return GetPriceByDate(customizedResults, valueDate);
|
||||
}
|
||||
/// <summary>
|
||||
/// 与GetPriceByDate 区别 处理 凤凰敲出观察频率 与 票息观察频率区分 ,现在 敲出观察频率只有 观察日期 和障碍价格
|
||||
/// </summary>
|
||||
public static double? GetPriceByDateV2(string observationDates, DateTime valueDate)
|
||||
{
|
||||
var customizedResults = QdpHelper.ParseAutocallCustomizedInfoV3(observationDates);
|
||||
return GetPriceByDateV2(customizedResults, valueDate);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="customizedResults"></param>
|
||||
/// <param name="valueDate"></param>
|
||||
/// <returns></returns>
|
||||
public static double? GetPriceByDate(Tuple<Date[], double[], double[]> customizedResults, DateTime valueDate)
|
||||
{
|
||||
var dates = customizedResults.Item1;
|
||||
|
||||
if (dates == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var prices = customizedResults.Item2;
|
||||
var date = dates.FirstOrDefault(x => x.DateTime == valueDate);
|
||||
|
||||
if (date != null)
|
||||
{
|
||||
if (prices != null && prices.Any())
|
||||
{
|
||||
var price = prices[GetDateIndex(dates, date)];
|
||||
return price;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static double? GetPriceByDateV2(Tuple<Date[], double[]> customizedResults, DateTime valueDate)
|
||||
{
|
||||
var dates = customizedResults.Item1;
|
||||
|
||||
if (dates == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var prices = customizedResults.Item2;
|
||||
var date = dates.FirstOrDefault(x => x.DateTime == valueDate);
|
||||
|
||||
if (date != null)
|
||||
{
|
||||
if (prices != null && prices.Any())
|
||||
{
|
||||
var price = prices[GetDateIndex(dates, date)];
|
||||
return price;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static int GetDateIndex(Date[] source, Date value)
|
||||
{
|
||||
var index = 0;
|
||||
foreach (var item in source)
|
||||
{
|
||||
if (item.DateTime == value.DateTime)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// 凤凰 观察频率处理
|
||||
/// </summary>
|
||||
/// <param name="KOObservationDates"></param>
|
||||
/// <param name="CouponBarrier"></param>
|
||||
/// <returns></returns>
|
||||
public static (string, string) GetAutocallKOObservationAndCoupon(string KOObservationDates, double CouponBarrier)
|
||||
{
|
||||
var KOObservationStr = KOObservationDates.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
if (KOObservationStr.Count > 0)
|
||||
{
|
||||
|
||||
var KoDates = KOObservationStr[0].Split(new char[] { ',' }).ToList();
|
||||
var KoBarriers = KOObservationStr[1].Split(new char[] { ',' }).ToList();
|
||||
var KoBarriers1 = KOObservationStr[1].Split(new char[] { ',' }).ToList();
|
||||
var KoCoupon = new List<string>();
|
||||
//当所有障碍价为空
|
||||
if (KOObservationStr.Count == 2)
|
||||
{
|
||||
KoBarriers = null;
|
||||
KoBarriers1 = null;
|
||||
KoCoupon = KOObservationStr[1].Split(new char[] { ',' }).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
KoCoupon = KOObservationStr[2].Split(new char[] { ',' }).ToList();
|
||||
}
|
||||
//票息观察处理 补充票息列
|
||||
string[] CouponBarriers = new string[KoDates.Count];
|
||||
for (int i = 0; i < KoDates.Count; i++)
|
||||
{
|
||||
CouponBarriers[i] = CouponBarrier.ToString();
|
||||
}
|
||||
var Couponinfo = string.Join(",", KoDates) + ";" + string.Join(",", CouponBarriers) + ";" + string.Join(",", KoCoupon);
|
||||
|
||||
//敲出观察处理 障碍价为空删除该观察日期
|
||||
var KOinfo = "";
|
||||
if (KoBarriers1 != null)
|
||||
{
|
||||
for (int i = 0; i < KoBarriers1.Count; i++)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(KoBarriers1[i]))
|
||||
{
|
||||
KoDates.RemoveAt(i);
|
||||
KoBarriers1.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
if (KoBarriers1.Any())
|
||||
{
|
||||
KOinfo = string.Join(",", KoDates) + ";" + string.Join(",", KoBarriers1);
|
||||
}
|
||||
}
|
||||
|
||||
return (Couponinfo, KOinfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (string.Empty, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user