public string LoadValuationReports(ICoreCache cache, string nameSpace) { var results = cache.LoadItems(typeof(ValuationReport), Expr.ALL); foreach (var item in results) { try { var valuationReport = (ValuationReport)item.Data; string valuationId = valuationReport.header.messageId.Value; cache.SaveObject(valuationReport, nameSpace + "." + valuationId, null); } catch (System.Exception excp) { cache.Logger.Log(excp); } } return(String.Format("ValuationReports retrieved")); }
private static Market GetCurve(ILogger logger, ICoreCache cache, string nameSpace, object[][] rateCurveFiltersRange) { NamedValueSet rateCurveFilters = rateCurveFiltersRange.ToNamedValueSet(); IExpression queryExpr = Expr.BoolAND(rateCurveFilters); List <ICoreItem> loadedCurves = cache.LoadItems <Market>(queryExpr); if (loadedCurves.Count == 0) { throw new InvalidOperationException("Requested curve is not available."); } if (loadedCurves.Count > 1) { throw new InvalidOperationException("More than 1 curve found for supplied filters."); } var loadedCurve = loadedCurves.Single(); var market = (Market)loadedCurve.Data; var yieldCurveValuation = (YieldCurveValuation)market.Items1[0]; DateTime baseDate = yieldCurveValuation.baseDate.Value; string currency = PropertyHelper.ExtractCurrency(loadedCurve.AppProps); yieldCurveValuation.discountFactorCurve = ConstructDiscountFactors(logger, cache, nameSpace, yieldCurveValuation.discountFactorCurve, baseDate, currency); return(market); }
/// <summary> /// Returns the header information for all trades matching the query properties. /// </summary> /// <param name="query">The query properties. A 2-column array of names and values.</param> /// <returns></returns> public object[,] QueryTradeIds(object[,] query) { //try //{ int rowMin = query.GetLowerBound(0); int rowMax = query.GetUpperBound(0); int colMin = query.GetLowerBound(1); int colMax = query.GetUpperBound(1); if (colMax - colMin + 1 != 3) { throw new ApplicationException("Input parameters must be 3 columns (name/op/value)!"); } IExpression whereExpr = null; for (int row = rowMin; row <= rowMax; row++) { int colName = colMin + 0; int colOp = colMin + 1; int colValue = colMin + 2; var name = query[row, colName] == null ? null : query[row, colName].ToString(); var op = query[row, colOp] == null ? null : query[row, colOp].ToString(); object value = query[row, colValue]; if (name != null && (op != null) && (value != null)) { op = op.ToLower().Trim(); if (op == "equ" || op == "==") { whereExpr = Expr.BoolAND(Expr.IsEQU(name, value), whereExpr); } else if (op == "neq" || op == "!=") { whereExpr = Expr.BoolAND(Expr.IsNEQ(name, value), whereExpr); } else if (op == "geq" || op == ">=") { whereExpr = Expr.BoolAND(Expr.IsGEQ(name, value), whereExpr); } else if (op == "leq" || op == "<=") { whereExpr = Expr.BoolAND(Expr.IsLEQ(name, value), whereExpr); } else if (op == "gtr" || op == ">") { whereExpr = Expr.BoolAND(Expr.IsGTR(name, value), whereExpr); } else if (op == "lss" || op == "<") { whereExpr = Expr.BoolAND(Expr.IsLSS(name, value), whereExpr); } else if (op == "starts") { whereExpr = Expr.BoolAND(Expr.StartsWith(name, value.ToString()), whereExpr); } else if (op == "ends") { whereExpr = Expr.BoolAND(Expr.EndsWith(name, value.ToString()), whereExpr); } else if (op == "contains") { whereExpr = Expr.BoolAND(Expr.Contains(name, value.ToString()), whereExpr); } else { throw new ApplicationException("Unknown Operator: '" + op + "'"); } } } List <ICoreItem> items = _cache.LoadItems(typeof(Trade), whereExpr); //TODO what about confirmation? var result = new object[items.Count + 1, 17]; // add heading row result[0, 0] = TradeProp.ProductType; result[0, 1] = TradeProp.TradeId; result[0, 2] = TradeProp.TradeDate; result[0, 3] = TradeProp.MaturityDate; result[0, 4] = TradeProp.EffectiveDate; result[0, 5] = TradeProp.TradeState; result[0, 6] = TradeProp.RequiredCurrencies; result[0, 7] = TradeProp.RequiredPricingStructures; result[0, 8] = TradeProp.ProductTaxonomy; result[0, 9] = TradeProp.AsAtDate; result[0, 10] = EnvironmentProp.SourceSystem; result[0, 11] = TradeProp.TradingBookId; result[0, 12] = TradeProp.TradingBookName; result[0, 13] = TradeProp.BaseParty; result[0, 14] = TradeProp.Party1; result[0, 15] = TradeProp.CounterPartyName; result[0, 16] = TradeProp.Party2; // now add data rows int tradeNum = 1; foreach (ICoreItem item in items) { try { //var fpmlTrade = (Trade)item.Data; result[tradeNum, 0] = item.AppProps.GetValue <string>(TradeProp.ProductType); result[tradeNum, 1] = item.AppProps.GetValue <string>(TradeProp.TradeId); result[tradeNum, 2] = item.AppProps.GetValue <DateTime>(TradeProp.TradeDate).ToShortDateString(); result[tradeNum, 3] = item.AppProps.GetValue <DateTime>(TradeProp.MaturityDate).ToShortDateString(); result[tradeNum, 4] = item.AppProps.GetValue <DateTime>(TradeProp.EffectiveDate).ToShortDateString(); result[tradeNum, 5] = item.AppProps.GetValue <string>(TradeProp.TradeState); result[tradeNum, 6] = String.Join(";", item.AppProps.GetArray <string>(TradeProp.RequiredCurrencies)); result[tradeNum, 7] = String.Join(";", item.AppProps.GetArray <string>(TradeProp.RequiredPricingStructures)); result[tradeNum, 8] = item.AppProps.GetValue <string>(TradeProp.ProductTaxonomy, null); result[tradeNum, 9] = item.AppProps.GetValue <DateTime>(TradeProp.AsAtDate).ToShortDateString(); result[tradeNum, 10] = item.AppProps.GetValue <string>(EnvironmentProp.SourceSystem); result[tradeNum, 11] = item.AppProps.GetValue <string>(TradeProp.TradingBookId); result[tradeNum, 12] = item.AppProps.GetValue <string>(TradeProp.TradingBookName); result[tradeNum, 13] = item.AppProps.GetValue <string>(TradeProp.BaseParty); result[tradeNum, 14] = item.AppProps.GetValue <string>(TradeProp.Party1); result[tradeNum, 15] = item.AppProps.GetValue <string>(TradeProp.CounterPartyName); result[tradeNum, 16] = item.AppProps.GetValue <string>(TradeProp.OriginatingPartyName); tradeNum++; } catch (Exception e) { Debug.Print("TradeStoreExcelApi.QueryTrades: Exception: {0}", e); } } //} //catch (Exception e) //{ // Debug.Print("TradeStoreExcelApi.QueryTrades: Exception: {0}", e); //} //finally //{ // Debug.Print("TradeStoreExcelApi.QueryTrades: Leave"); //} return(result); }
public void ReceiveNewItem(object notUsed) { // note: this runs on the foreground thread var item = notUsed as ICoreItem; if (item == null) { return; } var qas = item.Data as QuotedAssetSet; if (qas == null) { return; } // 1. Get the property values that uniquely identify the curves to refresh. // This is the process for the workflow request. Alternatively, a direct build of the curve can occur. // var nameSpace = item.AppProps.GetValue <string>(EnvironmentProp.NameSpace); var market = item.AppProps.GetValue <string>(CurveProp.Market);//For real time use Market and not MarketAndDate var curveType = item.AppProps.GetValue <string>(CurveProp.PricingStructureType); var curveName = item.AppProps.GetValue <string>(CurveProp.CurveName); var configIdentifier = FunctionProp.Configuration + ".PricingStructures." + market + "." + curveType + "." + curveName; var identifier = FunctionProp.Market + "." + market + "." + curveType + "." + curveName; List <ICoreItem> items = null; // 2.Check if the dependent curves should be refreshed // if (chkBoxDependentCurves.Checked) { //Find all the QAS's where the ReferenceCurveName is equal to the curveType.curveName! var requestProperties = new NamedValueSet(); requestProperties.Set(EnvironmentProp.NameSpace, NameSpace); requestProperties.Set(CurveProp.Market, market); requestProperties.Set(EnvironmentProp.Function, FunctionProp.Configuration); requestProperties.Set(CurveProp.ReferenceCurveName, curveType + '.' + curveName); IExpression queryExpr = Expr.BoolAND(requestProperties); _loggerRef.Target.LogDebug("Dependent curve property request set at {0}", DateTime.Now.ToLongTimeString()); items = _cache.LoadItems <Market>(queryExpr); } // 3. If the build is a local build then use the curve engine. // if (!chkBoxWorkflow.Checked) { _loggerRef.Target.LogDebug("Request to build base curve {0} locally at : {1}", identifier, DateTime.Now.ToLongTimeString()); var curve = CurveEngine.RefreshPricingStructureFromConfiguration(_loggerRef.Target, _cache, nameSpace, configIdentifier, identifier, qas, DateTime.Now, DateTime.Now); _loggerRef.Target.LogDebug("Built the base curve {0} locally at : {1}", curve, DateTime.Now.ToLongTimeString()); if (items != null) { foreach (var dataItem in items) { var spreadCurve = dataItem.Data as Market; if (spreadCurve == null) { continue; } //var bootstrap = dataItem.AppProps.GetValue<bool>(CurveProp.BootStrap, false); //if (!bootstrap) { dataItem.AppProps.Set(CurveProp.BootStrap, true); } try { var curveId = spreadCurve.id; if (String.IsNullOrEmpty(curveId)) { curveId = spreadCurve.Items[0].id; //use yieldCurve.id, CurveGen 1.X compatible } dataItem.AppProps.Set(CurveProp.BaseDate, DateTime.Now); dataItem.AppProps.Set(CurveProp.BuildDateTime, DateTime.Now); var marketData = new Pair <PricingStructure, PricingStructureValuation>(spreadCurve.Items[0], spreadCurve.Items1[0]); var ps = PricingStructureFactory.Create(_loggerRef.Target, _cache, nameSpace, null, null, marketData, dataItem.AppProps); if (ps != null) { CurveEngine.SaveCurve(_cache, nameSpace, ps); } _loggerRef.Target.LogDebug("Built the spread curve {0} locally at : {1}", curveId, DateTime.Now.ToLongTimeString()); } catch (Exception e) { _loggerRef.Target.LogDebug(e.ToString()); } } } } else { // 4. Set the parameters for the work request. // var curveGenRequest = new OrdinaryCurveGenRequest { NameSpace = nameSpace, BaseDate = DateTime.Now, RequestId = Guid.NewGuid().ToString(), RequesterId = new UserIdentity { Name = _cache.ClientInfo.Name, DisplayName = _cache.ClientInfo.UserFullName //Name = _clientRef.Target.ClientInfo.Name, //DisplayName = _clientRef.Target.ClientInfo.UserFullName }, UseSavedMarketData = true, ForceGenerateEODCurves = true }; // 5. Set the base curve in the curve selection for the work request. // var curveSelector = new List <CurveSelection> { new CurveSelection { NameSpace = nameSpace, MarketName = market, CurveType = curveType, CurveName = curveName } }; // 6.Include all other dependent curvenames i.e. spread curves. // if (items != null) { curveSelector.AddRange(from childCurve in items let spreadCurveType = childCurve.AppProps.GetValue <string>( CurveProp.PricingStructureType) let spreadCurveName = childCurve.AppProps.GetValue <string>(CurveProp.CurveName) select new CurveSelection { NameSpace = nameSpace, MarketName = market, CurveType = spreadCurveType, CurveName = spreadCurveName }); } curveGenRequest.CurveSelector = curveSelector.ToArray(); // 7. Set the actual work request. // IWorkContext context = new WorkContext(_loggerRef.Target, _cache, "DEV"); //IWorkContext context = new WorkContext(_loggerRef.Target, _clientRef.Target, "DEV"); _loggerRef.Target.LogDebug("WorkContext set at {0}", DateTime.Now.ToLongTimeString()); using (var workflow = new WFGenerateOrdinaryCurve()) { workflow.Initialise(context); WorkflowOutput <HandlerResponse> output = workflow.Execute(curveGenRequest); WorkflowHelper.ThrowErrors(output.Errors); foreach (var error in output.Errors) { _loggerRef.Target.LogInfo("WorkFlow error: {0} at {1}", error.Message, DateTime.Now.ToLongTimeString()); } } _loggerRef.Target.LogDebug("WorkFlow executed at {0}", DateTime.Now.ToLongTimeString()); //item = null; //_queuedItems.Locked(queue => // { // if (queue.Count > 0) // item = queue.Dequeue(); // }); } }