ForwardPriceSimulationService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using Framework;
using Holworth.RiskInterface;
using Contract.Domain;
using Contract.IService;
using Holworth.RiskEngine;
using Framework.IDao;
using HraModel;
namespace Holworth.Services.Risk
{
public class ForwardPriceSimulationService : BaseService.EntityService<Framework.Domain.Entity>, IForwardPriceSimulationService
{
#region Serive Area
IRskCoreFactorService _riskCoreFactorService = null;
public IRskCoreFactorService riskCoreFactorService
{
get
{
if (_riskCoreFactorService == null)
{
_riskCoreFactorService = ctx["RskCoreFactorService"] as IRskCoreFactorService;
}
return _riskCoreFactorService;
}
}
IRskFactorService _riskFactorService = null;
public IRskFactorService riskFactorService
{
get
{
if (_riskFactorService == null)
{
_riskFactorService = ctx["RskFactorService"] as IRskFactorService;
}
return _riskFactorService;
}
}
IRandomNumberService _randNumberService = null;
IRandomNumberService randNumberService
{
get
{
if (_randNumberService == null)
{
_randNumberService = ctx["RandomNumberService"] as IRandomNumberService;
}
return _randNumberService;
}
}
IMktPriceMarketDataService _indexPriceService = null;
IMktPriceMarketDataService indexPriceService
{
get
{
if (_indexPriceService == null)
{
_indexPriceService = ctx["MktPriceMarketDataService"] as IMktPriceMarketDataService;
}
return _indexPriceService;
}
}
IRskFactorVolatilityDataService _riskVolatilityService = null;
IRskFactorVolatilityDataService riskVolatilityService
{
get
{
if (_riskVolatilityService == null)
{
_riskVolatilityService = ctx["RskFactorVolatilityDataService"] as IRskFactorVolatilityDataService;
}
return _riskVolatilityService;
}
}
IRiskCorrelationDecompositionService _decomposeSerive = null;
IRiskCorrelationDecompositionService decomposeSerive
{
get
{
if (_decomposeSerive == null)
{
_decomposeSerive = ctx["RiskCorrelationDecompositionService"] as IRiskCorrelationDecompositionService;
}
return _decomposeSerive;
}
}
IGaussianDistributionService _gaussianDistService = null;
IGaussianDistributionService gaussianDistService
{
get
{
if (_gaussianDistService == null)
{
_gaussianDistService = ctx["GaussianDistributionService"] as IGaussianDistributionService;
}
return _gaussianDistService;
}
}
#endregion
public void SimulateForwardPriceForMultiPeriod(DateTime simulateDate, int simulateNumber, int horizonNumber, double timeStepLength, int windowSize, int periodTypeLookupID, int simulationMethodLookupID)
{
IList<RskCoreFactor> riskCoreFactors = riskCoreFactorService.GetValidListByIDWithSpringDao(Constants.VALID);
int riskCoreFactorNumber = riskCoreFactors.Count;
IList<string> results = new List<string>();
double[,] randNumber = new double[simulateNumber, riskCoreFactorNumber];
randNumberService.GenerateQuasiRandomNumber(simulateNumber, riskCoreFactorNumber, ref randNumber);
double[,] factorLoadingMatrix = new double[riskCoreFactorNumber, riskCoreFactorNumber];
double[] eigenValueVector = new double[riskCoreFactorNumber];
decomposeSerive.DecomposeCorrelationMatrixByRiskCoreFactor(simulateDate, riskCoreFactorNumber, riskCoreFactors, ref factorLoadingMatrix, ref eigenValueVector);
//int riskCoreFactorID = new int();
int riskFactorID = new int();
int indexPriceFactorID = new int();
int simulateID = new int();
int[] riskCoreFactorID = new int[riskCoreFactorNumber];
double[] currentPrice = new double[riskCoreFactorNumber];
double[] priceShock = new double[riskCoreFactorNumber];
double[,] simulatedPrice = new double[simulateNumber, riskCoreFactorNumber];
double[] zeroRate = new double[riskCoreFactorNumber];
double[] riskVolatility = new double[riskCoreFactorNumber];
double startForwardPrice = 0;
double sumOfRandNumber = 0;
double dayOfOneYear = Constants.DAYS_IN_ONE_YEAR;
double tempZeroRate = 0.00;
int i = 0;
foreach (RskCoreFactor riskCoreFactor in riskCoreFactors)
{
//need to get index price factor from risk factor
riskCoreFactorID[i] = int.Parse(riskCoreFactor.Id);
riskFactorID = riskCoreFactor.RiskFactorId;
indexPriceFactorID = riskFactorService.GetFactorIDByRiskFactorID(riskFactorID);
currentPrice[i] = (double)indexPriceService.GetIndexPriceValueByDateIDWithSpringDao(simulateDate, indexPriceFactorID);
zeroRate[i] = tempZeroRate; // need to get from database
riskVolatility[i] = (double)riskVolatilityService.GetValueByDateFactorIDSize(simulateDate, riskFactorID, windowSize);
i++;
}
IList<RskCoreFctSimulatedPrice> simulatedPricesToDelete = new List<RskCoreFctSimulatedPrice>();
//IList<RiskCoreFactorSimulatedPrice> outputList = new List<RiskCoreFactorSimulatedPrice>();
i = 0;
int horizonID = 0;
IList<RskCoreFctSimulatedPrice> simulatedPrices = new List<RskCoreFctSimulatedPrice>();
for (i = 0; i < simulateNumber; i++)
{
simulateID = i;
for (int j = 0; j < riskCoreFactorNumber; j++)
{
for (int l = 0; l < horizonNumber; l++)
{
horizonID = l;
if (horizonID == 0)
{
startForwardPrice = currentPrice[j];
//logForwardPrice = Math.Log(startForwardPrice);
}
else
{
startForwardPrice = simulatedPrice[i, j];
//logForwardPrice = Math.Log(startForwardPrice);
}
sumOfRandNumber = 0;
for (int k = 0; k < riskCoreFactorNumber; k++) // can be truncated by number of principal components
{
sumOfRandNumber += randNumberService.GenerateInverseRandomNumber(randNumber[i, k]) * factorLoadingMatrix[j, k];
}
priceShock[j] = (zeroRate[j] / dayOfOneYear - 0.5 * Math.Pow(riskVolatility[j], 2)) * timeStepLength + riskVolatility[j] * sumOfRandNumber;
simulatedPrice[i, j] = startForwardPrice * Math.Exp(priceShock[j]);
RskCoreFctSimulatedPrice riskFactorsimulatedPrice = new RskCoreFctSimulatedPrice();
riskFactorsimulatedPrice.RiskCoreFactorId = riskCoreFactorID[j];
riskFactorsimulatedPrice.SimulateDate = simulateDate;
riskFactorsimulatedPrice.HorizonDate = simulateDate.AddDays(horizonID);
riskFactorsimulatedPrice.HorizonId = horizonID;
riskFactorsimulatedPrice.PeriodType = periodTypeLookupID.ToString();
riskFactorsimulatedPrice.SimulationMethod = simulationMethodLookupID.ToString();
riskFactorsimulatedPrice.SimulationNumber = simulateNumber;
riskFactorsimulatedPrice.SimulationId = simulateID;
riskFactorsimulatedPrice.CurrentPrice = (decimal)startForwardPrice;
riskFactorsimulatedPrice.SimulatedPriceShock = (decimal)priceShock[j];
riskFactorsimulatedPrice.SimulatedForwardPrice = (decimal)simulatedPrice[i, j];
riskFactorsimulatedPrice.CreateUname = CurrentUser.UserName;
riskFactorsimulatedPrice.CreateUid = CurrentUser.UserId;
riskFactorsimulatedPrice.CreateDate = DateTime.Now;
riskFactorsimulatedPrice.State.MarkNew();
simulatedPrices.Add(riskFactorsimulatedPrice);
}
}
}
Framework.QueryInfo info = new Framework.QueryInfo();
info.CustomSQL = "delete from RskCoreFctSimulatedPrice";
info.AddParam("SimulateDate", simulateDate);
info.AddParam("SimulationNumber", simulateNumber);
Dao.ExecuteUpdate(info);
StringBuilder sb = new StringBuilder();
Framework.QueryInfo rInfo = new QueryInfo();
int rowCount = simulatedPrices.Count;
int pageSize = 1000;
int pages = 0;
pages = rowCount / pageSize;
if (rowCount <= pageSize)
{
sb = new StringBuilder();
for (int j = 1; j <= rowCount; j++)
{
var r = simulatedPrices[j - 1];
string s = InsertInfoRskCoreFctSimulatedPrice(r);
sb.AppendFormat(s);
}
rInfo.CustomSQL = "begin " + sb.ToString() + " end;";
Dao.ExecuteNonQuery(rInfo);
}
else
{
for (int pageIndex = 1; pageIndex <= pages; pageIndex++)
{
sb = new StringBuilder();
for (int j = (pageIndex - 1) * pageSize + 1; j <= pageIndex * pageSize; j++)
{
var r = simulatedPrices[j - 1];
string s = InsertInfoRskCoreFctSimulatedPrice(r);
sb.AppendFormat(s);
}
rInfo.CustomSQL = "begin " + sb.ToString() + " end;";
Dao.ExecuteNonQuery(rInfo);
}
if (rowCount % pageSize != 0)
{
int rows = rowCount / pageSize;
sb = new StringBuilder();
for (int j = pages * pageSize + 1; j <= pages * pageSize + rows; j++)
{
var r = simulatedPrices[j - 1];
string s = InsertInfoRskCoreFctSimulatedPrice(r);
sb.AppendFormat(s);
}
rInfo.CustomSQL = "begin " + sb.ToString() + " end;";
Dao.ExecuteNonQuery(rInfo);
}
}
// foreach (var r in simulatedPrices)
// {
// sb.AppendFormat(string.Format(@"insert into rsk_core_fct_simulated_price(CORE_SIMULATED_PRICE_ID,RISK_CORE_FACTOR_ID,SIMULATE_DATE
// ,HORIZON_DATE,HORIZON_ID ,PERIOD_TYPE,PERIOD_TYPE_NAME,SIMULATION_METHOD
// ,SIMULATION_METHOD_NAME,SIMULATION_NUMBER,SIMULATION_ID,CURRENT_PRICE,
// SIMULATED_PRICE_SHOCK ,SIMULATED_FORWARD_PRICE,
// CREATE_UID,CREATE_UNAME,CREATE_OID,CREATE_PID,CREATE_DATE,LAST_MOD_UID,
// LAST_MOD_UNAME,LAST_MOD_OID,LAST_MOD_PID,LAST_MOD_DATETIME)"));
// sb.Append("\r\n");
// string simulationDate = DateTime.Parse(r.SimulateDate.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// simulationDate = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", simulateDate);
// string horizonDate = DateTime.Parse(r.HorizonDate.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// horizonDate = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", horizonDate);
// string createDate = DateTime.Parse(r.CreateDate.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// createDate = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", createDate);
// string lastModDateTime = DateTime.Parse(r.LastModDatetime == null ? DateTime.Now.ToString() : r.LastModDatetime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// lastModDateTime = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", lastModDateTime);
// sb.AppendFormat(
// string.Format(
// @" VALUES({0},{1},{2},{3},{4},'{5}','{6}','{7}','{8}',{9},{10},{11},{12},{13},{14},'{15}','{16}','{17}',{18},'{19}','{20}','{21}','{22}',{23})",
// "HIBERNATE_SEQUENCE.NEXTVAL", r.RiskCoreFactorId, simulationDate, horizonDate,
// r.HorizonId, r.PeriodType, r.PeriodTypeName, r.SimulationMethod, r.SimulationMethodName,
// r.SimulationNumber, r.SimulationId, r.CurrentPrice, r.SimulatedPriceShock, r.SimulatedForwardPrice,
// r.CreateUid == null ? "" : r.CreateUid, r.CreateUname == null ? "" : r.CreateUname, r.CreateOid == null ? "" : r.CreateOid,
// r.CreatePid == null ? "" : r.CreatePid, createDate, r.LastModUid == null ? "" : r.LastModUid, r.LastModUname == null ? "" : r.LastModUname,
// r.LastModOid == null ? "" : r.LastModOid, r.LastModPid == null ? "" : r.LastModPid, lastModDateTime));
// sb.Append("\r\n");
// tagCount++;
// }
//Framework.QueryInfo rInfo = new QueryInfo();
//rInfo.CustomSQL = "begin\n" + sb.ToString() + "end;\n";
//Dao.ExecuteNonQuery(rInfo);
// Dao.SaveOrUpdateAll<RskCoreFctSimulatedPrice>(simulatedPrices);
}
private string InsertInfoRskCoreFctSimulatedPrice(RskCoreFctSimulatedPrice r)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(string.Format(@"insert into rsk_core_fct_simulated_price(CORE_SIMULATED_PRICE_ID,RISK_CORE_FACTOR_ID,SIMULATE_DATE ,HORIZON_DATE,HORIZON_ID ,PERIOD_TYPE,PERIOD_TYPE_NAME,SIMULATION_METHOD,SIMULATION_METHOD_NAME,SIMULATION_NUMBER,SIMULATION_ID,CURRENT_PRICE,SIMULATED_PRICE_SHOCK ,SIMULATED_FORWARD_PRICE,CREATE_UID,CREATE_UNAME,CREATE_OID,CREATE_PID,CREATE_DATE,LAST_MOD_UID,LAST_MOD_UNAME,LAST_MOD_OID,LAST_MOD_PID,LAST_MOD_DATETIME)"));
//sb.Append("\r\n");
string simulationDate = DateTime.Parse(r.SimulateDate.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
simulationDate = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", simulationDate);
string horizonDate = DateTime.Parse(r.HorizonDate.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
horizonDate = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", horizonDate);
string createDate = DateTime.Parse(r.CreateDate.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
createDate = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", createDate);
string lastModDateTime = DateTime.Parse(r.LastModDatetime == null ? DateTime.Now.ToString() : r.LastModDatetime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
lastModDateTime = string.Format("to_date('{0}','yyyy-mm-dd hh24:mi:ss')", lastModDateTime);
sb.AppendFormat(
string.Format(
@" VALUES({0},{1},{2},{3},{4},'{5}','{6}','{7}','{8}',{9},{10},{11},{12},{13},{14},'{15}','{16}','{17}',{18},'{19}','{20}','{21}','{22}',{23});",
"HIBERNATE_SEQUENCE.NEXTVAL", r.RiskCoreFactorId, simulationDate, horizonDate,
r.HorizonId, r.PeriodType, r.PeriodTypeName, r.SimulationMethod, r.SimulationMethodName,
r.SimulationNumber, r.SimulationId, r.CurrentPrice, r.SimulatedPriceShock, r.SimulatedForwardPrice,
r.CreateUid == null ? "" : r.CreateUid, r.CreateUname == null ? "" : r.CreateUname, r.CreateOid == null ? "" : r.CreateOid,
r.CreatePid == null ? "" : r.CreatePid, createDate, r.LastModUid == null ? "" : r.LastModUid, r.LastModUname == null ? "" : r.LastModUname,
r.LastModOid == null ? "" : r.LastModOid, r.LastModPid == null ? "" : r.LastModPid, lastModDateTime));
//sb.Append("\r\n");
return sb.ToString();
}
DateTime _simulateDate
{
get;
set;
}
int _simulateNumber
{
get;
set;
}
int _horizonNumber
{
get;
set;
}
double _timeStepLength
{
get;
set;
}
int _windowSize
{
get;
set;
}
int _periodTypeLookupID
{
get;
set;
}
int simulationMethodLookupID
{
get;
set;
}
int _simulationMethodLookupID
{
get;
set;
}
///// <summary>
///// 采用多线程处理
///// </summary>
//void SimulateForwardPriceForMultiPeriod_NoParameter()
//{
// try
// {
// // MessageBox.Show("12345");
// Framework.QueryInfo info = new Framework.QueryInfo();
// string userId = SessionId;
// //info.CustomSQL = "delete from T_AnsycData where userId=:UserId and DataType='SimulateForwardPrice'";
// //info.Parameters.Add("UserId", userId);
// //Dao.ExecuteNonQuery(info);
// LOG.Info("In ForwardPriceSimulationService.SimulateForwardPriceForMultiPeriod()");
// IRiskCoreFactorService riskCoreFactorService =
// (IRiskCoreFactorService)ServiceLocator.Get("riskCoreFactorService");
// IList<RiskCoreFactor> riskCoreFactors =
// riskCoreFactorService.GetValidListByIDWithSpringDao(Constants.VALID);
// int riskCoreFactorNumber = riskCoreFactors.Count;
// IRandomNumberService randNumberService =
// (IRandomNumberService)ServiceLocator.Get("randomNumberService");
// IIndexPriceMarketDataService indexPriceService =
// (IIndexPriceMarketDataService)ServiceLocator.Get("indexPriceMarketDataService");
// IRiskFactorVolatilityDataService riskVolatilityService =
// (IRiskFactorVolatilityDataService)ServiceLocator.Get("riskFactorVolatilityDataService");
// IRiskCorrelationDecompositionService decomposeSerive =
// (IRiskCorrelationDecompositionService)ServiceLocator.Get("riskCorrelationDecompositionService");
// IList<string> results = new List<string>();
// IGaussianDistributionService gaussianDistService =
// (IGaussianDistributionService)ServiceLocator.Get("gaussianDistributionService");
// //int periodTypeLookupID = (int)LookupItems.PERIOD_TYPE_DAILY;
// //int simulationMethodLookupID = (int)LookupItems.SIMULATION_METHOD_DIRECT_JUMP;
// double[,] randNumber = new double[_simulateNumber, riskCoreFactorNumber];
// randNumberService.GenerateQuasiRandomNumber(_simulateNumber, riskCoreFactorNumber, ref randNumber);
// double[,] factorLoadingMatrix = new double[riskCoreFactorNumber, riskCoreFactorNumber];
// double[] eigenValueVector = new double[riskCoreFactorNumber];
// //edit daidz
// decomposeSerive.DecomposeCorrelationMatrixByRiskCoreFactor_New(WcfUserName1, _simulateDate, riskCoreFactorNumber,
// riskCoreFactors, ref factorLoadingMatrix, ref eigenValueVector);
// int indexPriceFactorID = new int();
// //int riskFactorID = new int();
// int simulateID = new int();
// int[] riskCoreFactorID = new int[riskCoreFactorNumber];
// double[] currentPrice = new double[riskCoreFactorNumber];
// double[] priceShock = new double[riskCoreFactorNumber];
// double[,] simulatedPrice = new double[_simulateNumber, riskCoreFactorNumber];
// //double[] forwardPrice = new double[riskCoreFactorNumber];
// //double[] logForwardPrice = new double[riskCoreFactorNumber];
// double[] zeroRate = new double[riskCoreFactorNumber];
// double[] riskVolatility = new double[riskCoreFactorNumber];
// //double forwardPrice = 0;
// double startForwardPrice = 0;
// //double logForwardPrice = 0;
// double sumOfRandNumber = 0;
// double dayOfOneYear = Constants.DAYS_IN_ONE_YEAR;
// double tempZeroRate = 0.00;
// int i = 0;
// var allList = indexPriceService.GetIndexPriceMarketDataByDate(_simulateDate);
// var allFatorList = riskVolatilityService.GetListByDateSize(_simulateDate, _windowSize);
// System.Collections.ArrayList sidList = new System.Collections.ArrayList();
// for (var k = 0; k < riskCoreFactors.Count; k++)
// {
// var riskCoreFactor = riskCoreFactors[k];
// indexPriceFactorID = riskCoreFactor.RiskCoreFactorID;
// riskCoreFactorID[i] = riskCoreFactor.RiskCoreFactorID;
// currentPrice[i] =
// (double)indexPriceService.GetIndexPriceValueByDateWithSpringDao(allList, indexPriceFactorID);
// zeroRate[i] = tempZeroRate; // need to get from database
// // riskVolatility[i] = (double)riskVolatilityService.GetValueByDateFactorIDSize(simulateDate, riskCoreFactorID[i], windowSize);
// riskVolatility[i] =
// (double)riskVolatilityService.GetValueByDateFactorSizeByList(riskCoreFactorID[i], allFatorList);
// i++;
// }
// IRiskCoreFactorSimulatedPriceService simulatedPriceService =
// (IRiskCoreFactorSimulatedPriceService)ServiceLocator.Get("riskCoreFactorSimulatedPriceService");
// IList<RiskCoreFactorSimulatedPrice> simulatedPricesToDelete = new List<RiskCoreFactorSimulatedPrice>();
// i = 0;
// int horizonID = 0;
// IList<RiskCoreFactorSimulatedPrice> simulatedPrices = new List<RiskCoreFactorSimulatedPrice>();
// for (i = 0; i < _simulateNumber; i++)
// {
// simulateID = i;
// // IList<RiskCoreFactorSimulatedPrice> simulatedPrices = new List<RiskCoreFactorSimulatedPrice>();
// for (int j = 0; j < riskCoreFactorNumber; j++)
// {
// for (int l = 0; l < _horizonNumber; l++)
// {
// horizonID = l;
// if (horizonID == 0)
// {
// startForwardPrice = currentPrice[j];
// //logForwardPrice = Math.Log(startForwardPrice);
// }
// else
// {
// startForwardPrice = simulatedPrice[i, j];
// //logForwardPrice = Math.Log(startForwardPrice);
// }
// sumOfRandNumber = 0;
// for (int k = 0; k < riskCoreFactorNumber; k++) // can be truncated by number of principal components
// {
// sumOfRandNumber += randNumberService.GenerateInverseRandomNumber(randNumber[i, k]) * factorLoadingMatrix[j, k];
// }
// priceShock[j] = (zeroRate[j] / dayOfOneYear - 0.5 * Math.Pow(riskVolatility[j], 2)) * _timeStepLength + riskVolatility[j] * sumOfRandNumber;
// simulatedPrice[i, j] = startForwardPrice * Math.Exp(priceShock[j]);
// RiskCoreFactorSimulatedPrice riskFactorsimulatedPrice = new RiskCoreFactorSimulatedPrice();
// riskFactorsimulatedPrice.RiskCoreFactorID = riskCoreFactorID[j];
// riskFactorsimulatedPrice.SimulateDate = _simulateDate;
// riskFactorsimulatedPrice.HorizonDate = _simulateDate.AddDays(horizonID);
// riskFactorsimulatedPrice.HorizonID = horizonID;
// riskFactorsimulatedPrice.PeriodTypeLookupID = _periodTypeLookupID;
// riskFactorsimulatedPrice.SimulationMethodLookupID = simulationMethodLookupID;
// riskFactorsimulatedPrice.SimulationNumber = _simulateNumber;
// riskFactorsimulatedPrice.SimulationID = simulateID;
// riskFactorsimulatedPrice.CurrentPrice = (decimal)startForwardPrice;
// riskFactorsimulatedPrice.SimulatedPriceShock = (decimal)priceShock[j];
// riskFactorsimulatedPrice.SimulatedForwardPrice = (decimal)simulatedPrice[i, j];
// //riskFactorsimulatedPrice.CreatedBy = WcfService.Wcf.loginUser.WcfUser.UserName;
// riskFactorsimulatedPrice.CreatedBy = WcfUserName1;
// riskFactorsimulatedPrice.CreateDate = DateTime.Now;
// simulatedPrices.Add(riskFactorsimulatedPrice);
// }
// }
// //sb.Append(string.Format("delete from RiskCoreFactorSimulatedPrices where SimulateDate='{0}'", simulateDate.ToString("yyyy-MM-dd")));
// //sb.Append(string.Format(" and SimulationID={0}", simulateID));
// //sb.Append(string.Format(" and SimulationNumber={0}\r\n", simulateNumber));
// // simulatedPricesToDelete = simulatedPriceService.GetListByDateSimID(simulateDate, simulateID, simulateNumber);
// // simulatedPriceService.Save(simulatedPricesToDelete, new List<RiskCoreFactorSimulatedPrice>(), new List<RiskCoreFactorSimulatedPrice>());
// // simulatedPriceService.Save(new List<RiskCoreFactorSimulatedPrice>(), new List<RiskCoreFactorSimulatedPrice>(), simulatedPrices);
// }
// info = new Framework.QueryInfo();
// info.CustomSQL = string.Format("delete from RiskCoreFactorSimulatedPrices where SimulateDate='{0}' and SimulationID between 0 and {1}"
// , _simulateDate.ToString("yyyy-MM-dd"), _simulateNumber);
// info.CustomSQL += "\r\n insert into T_AnsycData(UserId,DataType,Result)values(:UserId,'SimulateForwardPrice','1')";
// info.Parameters.Add("UserId", userId);
// Dao.ExecuteNonQuery(info);
// simulatedPriceService.Save(new List<RiskCoreFactorSimulatedPrice>(), new List<RiskCoreFactorSimulatedPrice>(), simulatedPrices);
// LOG.Info("Finishing simulatoin for all index curves for multiple horizon dates");
// }
// catch (Exception ex)
// {
// Framework.QueryInfo info = new Framework.QueryInfo();
// info.CustomSQL += "\r\n insert into T_AnsycData(UserId,DataType,Result)values(:UserId,'SimulateForwardPrice',:Result)";
// info.Parameters.Add("UserId", SessionId);
// info.Parameters.Add("Result", ex.Message);
// Dao.ExecuteNonQuery(info);
// }
//}
/// <summary>
/// edit daidz
/// </summary>
/// <param name="simulateDate"></param>
/// <param name="simulateNumber"></param>
/// <param name="horizonNumber"></param>
/// <param name="timeStepLength"></param>
/// <param name="windowSize"></param>
/// <param name="periodTypeLookupID"></param>
/// <param name="simulationMethodLookupID"></param>
//public void SimulateForwardPriceForMultiPeriod_New(int CurrentUserID, DateTime simulateDate, int simulateNumber, int horizonNumber, double timeStepLength, int windowSize, int periodTypeLookupID, int simulationMethodLookupID)
//{
// lock (l)
// {
// _simulateDate = simulateDate;
// SessionId = WcfService.Wcf.loginUser.WcfUser.UserId;
// _simulateNumber = simulateNumber;
// _horizonNumber = horizonNumber;
// _timeStepLength = timeStepLength;
// _windowSize = windowSize;
// _periodTypeLookupID = periodTypeLookupID;
// _simulationMethodLookupID = simulationMethodLookupID;
// Framework.QueryInfo info = new Framework.QueryInfo();
// string userId = SessionId;
// info.CustomSQL = "delete from T_AnsycData where userId=:UserId and DataType='SimulateForwardPrice'";
// info.Parameters.Add("UserId", userId);
// Dao.ExecuteNonQuery(info);
// WcfUserName1 = WcfService.Wcf.loginUser.WcfUser.UserName;
// threadStart = new ThreadStart(this.SimulateForwardPriceForMultiPeriod_NoParameter);
// thread = new Thread(threadStart);
// thread.IsBackground = true;
// thread.Start();
// }
//}
//public static string WcfUserName1 = string.Empty;
//private void threadHand1_Run(string userName)
//{
// this.SimulateForwardPriceForMultiPeriod_NoParameter();
//}
//void worker_DoWork(object sender, DoWorkEventArgs e)
//{
//}
public void GetSimulatedForwardPriceForSingleHorizon(int horizonID, DateTime computeDate, int simulationNumber, int periodTypeLookupID, int simulationMethodLookupID, ref int[] simulatedRiskCoreFactorID, ref double[,] simulatedForwardPrice)
{
// IRiskCoreFactorService riskCoreFactorService = (IRiskCoreFactorService)ServiceLocator.Get("riskCoreFactorService");
//IList<RiskCoreFactor> riskCoreFactors = riskCoreFactorService.GetAll();
IList<RskCoreFactor> riskCoreFactors = riskCoreFactorService.GetValidListByIDWithSpringDao(Constants.VALID);
// IRiskCoreFactorSimulatedPriceService simulatedPriceService = (IRiskCoreFactorSimulatedPriceService)ServiceLocator.Get("riskCoreFactorSimulatedPriceService");
//IList<RiskCoreFactorSimulatedPrice> simulatedPrices = new List<RiskCoreFactorSimulatedPrice>();
//IList<RiskCoreFactorIDVO> riskCoreFactors = simulatedPriceService.GetRiskCoreFactorListByDateNumberIDWithSpringDao(computeDate, horizonID, periodTypeLookupID, simulationMethodLookupID, simulationNumber);
Framework.QueryInfo info = new Framework.QueryInfo();
info.QueryObject = "RskCoreFctSimulatedPrice";
info.AddParam("SimulateDate", computeDate);
info.AddParam("HorizonId", horizonID);
info.AddParam("PeriodType", periodTypeLookupID.ToString());
info.AddParam("SimulationMethod", simulationMethodLookupID);
info.AddParam("SimulationNumber", simulationNumber);
IList<RskCoreFctSimulatedPrice> simulatedPrices = Holworth.Utility.Utility.ListToT<RskCoreFctSimulatedPrice>(Dao.FindList(info));
// IList<RskCoreFctSimulatedPrice> simulatedPrices = simulatedPriceService.GetListByDateNumberIDWithSpringDao(computeDate, horizonID, periodTypeLookupID, simulationMethodLookupID, simulationNumber);
//int riskCoreFactorNumber = riskCoreFactors.Count;
int k = 0;
//foreach (RiskCoreFactorIDVO riskCoreFactor in riskCoreFactors)
foreach (RskCoreFactor riskCoreFactor in riskCoreFactors)
{
simulatedRiskCoreFactorID[k] = int.Parse(riskCoreFactor.Id);
k++;
}
double[] proxySimulatedPrice = new double[simulatedPrices.Count];
k = 0;
foreach (RskCoreFctSimulatedPrice simulatedPrice in simulatedPrices)
{
proxySimulatedPrice[k] = (double)simulatedPrice.SimulatedForwardPrice;
k++;
}
k = 0;
for (int i = 0; i < simulationNumber; i++)
{
for (int j = 0; j < riskCoreFactors.Count; j++)
{
simulatedForwardPrice[i, j] = proxySimulatedPrice[k];
k++;
}
}
}
public int GetRiskCoreFactorRowNumber(int riskFactorID, int simulatedRiskCoreFactorNumber, int[] simulatedRiskCoreFactorID)
{
int riskCoreFactorRowNumber = 0;
for (int i = 0; i < simulatedRiskCoreFactorNumber; i++)
{
if (simulatedRiskCoreFactorID[i] == riskFactorID)
{
riskCoreFactorRowNumber = i;
break;
}
}
return riskCoreFactorRowNumber;
}
IForwardPriceSimulationService _priceSimulationService = null;
IForwardPriceSimulationService priceSimulationService
{
get
{
if (_priceSimulationService == null)
{
_priceSimulationService = ctx["ForwardPriceSimulationService"] as IForwardPriceSimulationService;
}
return _priceSimulationService;
}
}
public void SimulateForwardPrice(DateTime computeDate, int horizonNumber, int simulationNumber)
{
double timeStepLength = (double)Constants.BASE_TIME_STEP_LENGTH;
int windowSize = (int)Constants.BASE_WINDOW_SIZE;
int periodTypeLookupID = (int)LookupItems.PERIOD_TYPE_DAILY;
int simulationMethodLookupID = (int)LookupItems.SIMULATION_METHOD_DIRECT_JUMP;
priceSimulationService.SimulateForwardPriceForMultiPeriod(computeDate, simulationNumber, horizonNumber, timeStepLength, windowSize, periodTypeLookupID, simulationMethodLookupID);
}
}
}
ForwardPriceSimulationService的更多相关文章
- OracleBulkCopy 修正帮
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Refle ...
随机推荐
- Convex 一道阿姆斯特朗回旋好题
2001年5月8日,阿姆斯特朗(Armstrong, 1929-2013) 教授发明了一种名为“阿姆斯特朗回旋加速喷气式阿姆斯特朗加密”的加密算法,算法从未公开,直至2013阿姆斯特朗教授逝世后,其生 ...
- Springboot - 建立简单的用户登录系统
在开始编码前,先建立几个Package(可以按个人习惯命名),如图 1.Controllers 用于存放控制器类 2.Models 用于存放数据实体类 3.Repositories 用于存放数据库操作 ...
- 【thrift】thrift入门初探--thrift安装及java入门实例
转载:https://www.cnblogs.com/fingerboy/p/6424248.html 公司的一些平台服务框架底层封装了thrift提供服务,最近项目不是很紧,于是研究了一下,刚刚入门 ...
- C#对象的三种序列化
要让一个对象支持.Net序列化服务,用户必须为每一个关联的类加上[Serializable]特性.如果类中有些成员不适合参与序列化(比如:密码字段),可以在这些域前加上[NonSerialized]特 ...
- 你正在从一个声称代表如下的证书颁发机构安装证书 alipay truest network,希望能知道程序是怎么实现的或相关资料
你正在从一个声称代表如下的证书颁发机构安装证书 alipay truest network,希望能知道程序是怎么实现的或相关资料
- 用PHP收发邮件
注:在WinForm下怎么试都不好使,最后没办法换成了PHP下,一试就好使了. 这里用到了phpmailer组件,网上有下. 转:phpnow支持ssl的方法 原文出处:http://blog.163 ...
- Oracle DSI系列 01 DSI初识BBED
DSI是Data Server Internals的缩写,是Oracle公司内部用来培训Oracle售后工程师使用的教材. 1 bbed工具使用BBED工具介绍BBED stands for Bloc ...
- 通过日志查看Web Api详细运行过程
1. 通过Nuget安装System.Web.Http.Tracing. 2. 通过HttpConfiguration,注册SystemDiagnosticsTraceWriter public st ...
- SecureCRT 8.1使用经验总结
1.反空闲设置: 2.文件上传下载 上传 sudo rz -y 文本文件勾选Upload files as ASCII,图片或其他飞文本文件,去掉勾选.采用默认binary 3.文件下载 sudo s ...
- django-创建表的字段属性,表关系
表的各种属性文档:null char ..., django与之对应的文档 https://docs.djangoproject.com/en/1.11/ref/models/fields/ 英文 ...