山证bug修复及功能 迁移

This commit is contained in:
吴方海
2024-06-04 18:19:49 +08:00
parent df65cd0add
commit acbd2e7678
39 changed files with 709 additions and 406 deletions
@@ -55,14 +55,10 @@ namespace YLErp.Modules.DataProviderModule
/// </summary>
public EodPriceProvider Initialize(IEnumerable<string> underlyingCodes = null)
{
if (!PreValueDate.HasValue)
{
PreValueDate = QdpCalendarHelper.GetNonHoliday(ValueDate.AddDays(-1));
}
using var db = DbContextFactory.GetYLDbContext();
var predicate1 = PredicateBuilder.Create<eod_commodity_future_price>(eodprice => eodprice.ValueDate == ValueDate);
var predicate2 = PredicateBuilder.Create<eod_stock_price>(eodprice => eodprice.ValueDate == ValueDate);
var predicate3 = PredicateBuilder.Create<ChinaBondValuation>(eodprice => eodprice.valuation_date == PreValueDate);
var predicate3 = PredicateBuilder.Create<ChinaBondValuation>(eodprice => eodprice.valuation_date == ValueDate);
if (underlyingCodes != null && underlyingCodes.Any(n => !string.IsNullOrEmpty(n)))
{
var set = underlyingCodes.Where(n => n != null && !_priceDic.ContainsKey(n)).ToHashSet();
@@ -114,24 +110,24 @@ namespace YLErp.Modules.DataProviderModule
DeciReferencePrice = 0,
};
var eodBondQuery = from eodprice in db.china_bond_valuation.Where(predicate3)
join um in db.underlying_manager on eodprice.bond_id equals um.UnderlyingCode
select new EodPrice
{
IsStock = false,
ValueDate = ValueDate,
UnderlyingId = um.id,
UnderlyingCode = um.UnderlyingCode,
ClosePrice = 0,
SettlePrice = 0,
HighPrice = 0,
LowPrice = 0,
UnderlyingStatus = "正常运行",
UnderlyingInstrumentType = "Bonds",
ReferencePrice =0,
DeciSettlePrice = eodprice.dirty_price_close,
DeciClosePrice = eodprice.net_price,
DeciReferencePrice = eodprice.yield,
};
join um in db.underlying_manager on eodprice.bond_id equals um.UnderlyingCode
select new EodPrice
{
IsStock = false,
ValueDate = ValueDate,
UnderlyingId = um.id,
UnderlyingCode = um.UnderlyingCode,
ClosePrice = 0,
SettlePrice = 0,
HighPrice = 0,
LowPrice = 0,
UnderlyingStatus = "正常运行",
UnderlyingInstrumentType = "Bonds",
ReferencePrice = 0,
DeciSettlePrice = eodprice.dirty_price_close,
DeciClosePrice = eodprice.net_price,
DeciReferencePrice = eodprice.yield,
};
//数据加载到字典中
var list = eodFutureQuery.Concat(eodStockQuery).Concat(eodBondQuery).ToArray();
@@ -143,7 +139,7 @@ namespace YLErp.Modules.DataProviderModule
{
if (item.UnderlyingInstrumentType == "Bonds")
{
item.SettlePrice = Convert.ToDouble(item.DeciSettlePrice*ConsGlobal.bondPriceMultiple);
item.SettlePrice = Convert.ToDouble(item.DeciSettlePrice * ConsGlobal.bondPriceMultiple);
item.ClosePrice = Convert.ToDouble(item.DeciClosePrice * ConsGlobal.bondPriceMultiple);
item.ReferencePrice = Convert.ToDouble(item.DeciReferencePrice * ConsGlobal.bondPriceMultiple);
}
@@ -13,12 +13,12 @@ namespace YLErp.Modules.DataProviderModule
/// <summary>
/// 检查数据库是否有数据
/// </summary>
public static bool CheckDbExists(DateTime valueDate,DateTime preSettleDate)
public static bool CheckDbExists(DateTime valueDate)
{
using var db = DbContextFactory.GetYLDbContext();
return db.eod_commodity_future_price.Any(n => n.ValueDate == valueDate)
|| db.eod_stock_price.Any(n => n.ValueDate == valueDate)
|| db.china_bond_valuation.Any(n=>n.valuation_date== preSettleDate && n.dirty_price_close>0);
|| db.china_bond_valuation.Any(n => n.valuation_date == valueDate && n.dirty_price_close > 0);
}
/// <summary>
@@ -41,7 +41,7 @@ namespace YLErp.Modules.DataProviderModule
//日终估值全价必须有值才算
var query = from e in db.china_bond_valuation
where e.bond_id == underlyingCode
&& e.valuation_date >= startDate && e.valuation_date <= valueDate &&e.dirty_price_close>0
&& e.valuation_date >= startDate && e.valuation_date <= valueDate && e.dirty_price_close > 0
select e;
return query.Any();
@@ -110,7 +110,30 @@ namespace YLErp.Modules.DataProviderModule
{
return (eodPrice = GetEodPrice(valueDate, underlyingId)) != null;
}
/// <summary>
/// 获取某日之前最新价格
/// </summary>
/// <param name="valueDate"></param>
/// <param name="underlyingCode"></param>
/// <param name="price"></param>
/// <returns></returns>
public static bool TryGetPrice(DateTime valueDate, string underlyingCode, out double price)
{
price = 0;
valueDate = valueDate.Date;
using var db = DbContextFactory.GetYLDbContext();
var data = db.eod_commodity_future_price.Where(x => x.ValueDate <= valueDate && x.UnderlyingCode == underlyingCode).OrderByDescending(o => o.ValueDate).FirstOrDefault();
if (data != null)
{
price = data.ReferencePrice ?? 0;
return true;
}
return false;
}
/// <summary>
/// 尝试获取标的某日的日终价
/// </summary>
@@ -147,14 +170,14 @@ namespace YLErp.Modules.DataProviderModule
{
rp1 = epCommodity.ReferencePrice,
rp2 = epStock.ReferencePrice,
rp3= epBond.dirty_price_close
rp3 = epBond.dirty_price_close
};
var data = eodQuery.FirstOrDefault();
if (data != null && (data.rp1 != null || data.rp2 != null||data.rp3 != null))
if (data != null && (data.rp1 != null || data.rp2 != null || data.rp3 != null))
{
price = data.rp1 ?? data.rp2 ?? Convert.ToDouble((data.rp3??0)*ConsGlobal.bondPriceMultiple);
price = data.rp1 ?? data.rp2 ?? Convert.ToDouble((data.rp3 ?? 0) * ConsGlobal.bondPriceMultiple);
return true;
}
@@ -186,17 +209,17 @@ namespace YLErp.Modules.DataProviderModule
public static EodPrice GetBondPrice(DateTime valueDate, string underlyingCode)
{
using var db = DbContextFactory.GetYLDbContext();
var bondPrice = db.china_bond_valuation.Where(x=>x.bond_id== underlyingCode&&x.valuation_date<=valueDate).OrderByDescending(o=>o.credibility).ThenByDescending(o=>o.valuation_date).FirstOrDefault();
if (bondPrice==null)
var bondPrice = db.china_bond_valuation.Where(x => x.bond_id == underlyingCode && x.valuation_date <= valueDate).OrderByDescending(o => o.credibility).ThenByDescending(o => o.valuation_date).FirstOrDefault();
if (bondPrice == null)
{
return null;
}
return new EodPrice
{
Vobp= bondPrice.vobp,
Vobp = bondPrice.vobp,
ValueDate = valueDate,
UnderlyingCode = underlyingCode,
ClosePrice = Convert.ToDouble(bondPrice.dirty_price_close*ConsGlobal.bondPriceMultiple),
ClosePrice = Convert.ToDouble(bondPrice.dirty_price_close * ConsGlobal.bondPriceMultiple),
SettlePrice = Convert.ToDouble(bondPrice.net_price * ConsGlobal.bondPriceMultiple),
ReferencePrice = Convert.ToDouble(bondPrice.yield * ConsGlobal.bondPriceMultiple)
};
@@ -216,9 +239,8 @@ namespace YLErp.Modules.DataProviderModule
}
if (data.IsBond())
{
var valuedate = QdpCalendarHelper.GetNonHolidayDefore(settleDate.AddDays(-1));
var eodBondPrice = GetBondPrice(valuedate, code);
return eodBondPrice?.ClosePrice??0;
var eodBondPrice = GetBondPrice(settleDate, code);
return eodBondPrice?.ClosePrice ?? 0;
}
var price = data.Price ?? 0;
if (TryGetEodPrice(settleDate, code, out var eodPrice))