Download presentation
Presentation is loading. Please wait.
Published byConner Ackerman Modified over 10 years ago
1
Early Warning Indicators A case study with F# “Give them the third best to go on with; the second best comes too late, the best never comes” Sir Robert Watson-Watt (on the RADAR early warning system for World War 2)
2
Agenda Background, Requirements and Drivers Calculation Options and Cell Framework Application Architecture and life-cycle Deployment, Handover and Lessons Learned
3
Background Treasury Liquidity Management – Banks use a variety of sources to ensure that liquidity is always available from money markets & repo; through credit bonds and equity issuance - "Never borrow from a Central Bank, if there are any alternatives" Early Warning Indicators, one system mandated by Regulators – When Lehman went bankrupt, interbank lending seized-up as Banks lost confidence in each other ability to pay, Collateral calls escalated & tier-1 capital tumbled as share prices collapsed Never Again – ExCo's and regulators demanded plans, tools & systems to warn of risks and manage mitigation – Early Warning Indicators – Active liquidity, active limit management, Active Collateral Control, Active RWA, stress tests
4
Early Warning Indicators Requirement Very high level metrics with tolerable thresholds – Liquidity buffers, Cash Ladders, Collateral Quality, Risk appetite – Peer Bank stock valuations & CDS Spreads – Core commodities (oil, gold, etc) spot & futures – Forex rates & volatility – Country CDS Spreads real-time calculation of RAG Status and breach reporting Business policy/plans for detailed review on Breach
5
Early Warning Indicators System Drivers Additional calculations as business needs change without restart Option to define calculation using Excel formulas Scorecard reports {Excel;PDF} generated from RAG indicators (not spreadsheet template) No routine maintenance Flexible for future integration
6
Agenda Background, Requirements and Drivers Calculation Options and Cell Framework Application Architecture and life-cycle Deployment, Handover and Lessons Learned
7
EWI Calculation Options Build from Spreadsheet component (Spreadsheet Gear) with price-feed – single threaded, complex integration Build from Tick-store (KDB, Q) – No automatic trigger Build from Cell Framework & FSYacc/FSLex Excel expression parser – F# new to Treasury – Haskell Quant payoff engine – F# Equity Prime
8
Cell Framework Model object encapsulates calculations Closures with event triggers Computational Expression Builder Parser for Excel expressions Selected for speed of development
9
Cell Model Model presented to C# as a class with properties Source indicators seeded with default values type EWISample (model : IModel) as this = inherit Cephei.Kernel.Model (model) // cell definitions let _hsbc_px_last = cell.Value (Fun.load "hsbc_px_last" 609.1) let _hsbc_history = cell.Value (Fun.load "hsbc_history" (Fun.defaultTS 260 Double.NaN)) let _hsbc_CDS_3month = cell.Value (Fun.load "hsbc_px_last" 33.1) let _hsbc_CDS_9month = cell.Value (Fun.load "hsbc_px_last" 43.1) let _hsbc_px_close = cell { return Fun.first _hsbc_history.Value } let _hsbc_three_nine_diff = cell { return _hsbc_CDS_3month.Value - _hsbc_CDS_9month.Value } let _hsbc_30avg = cell { return Fun.avg30day _hsbc_history.Value } let _hsbc_30high = cell { return Fun.max30day _hsbc_history.Value } let _hsbc_30low = cell { return Fun.max30day _hsbc_history.Value } let _hsbc_px_last_rag = cell {let! red = _hsbc_px_last.Value < _hsbc_30low.Value let! amber = _hsbc_px_last.Value < _hsbc_30avg.Value return if red then "R" elif amber then "A" else "G"} let _hsbc_CDS_3month_rag = cell {let! red = (_hsbc_CDS_3month.Value - _hsbc_three_nine_diff.Value) / _hsbc_CDS_3month.Value > 0.95 let! amber = (_hsbc_CDS_3month.Value - _hsbc_three_nine_diff.Value) / _hsbc_CDS_3month.Value > 0.90 return if red then "R" elif amber then "A" else "G"} do this.Link () // access properties member this.hsbc_px_last = _hsbc_px_last
10
Cell closures Cell encapsulates calculation and records dependencies through profiling Change events trigger re-calculation type EWISample (model : IModel) as this = inherit Cephei.Kernel.Model (model) // cell definitions let _hsbc_px_last = cell.Value (Fun.load "hsbc_px_last" 609.1) let _hsbc_history = cell.Value (Fun.load "hsbc_history" (Fun.defaultTS 260 Double.NaN)) let _hsbc_CDS_3month = cell.Value (Fun.load "hsbc_px_last" 33.1) let _hsbc_CDS_9month = cell.Value (Fun.load "hsbc_px_last" 43.1) let _hsbc_px_close = cell { return Fun.first _hsbc_history.Value } let _hsbc_three_nine_diff = cell { return _hsbc_CDS_3month.Value - _hsbc_CDS_9month.Value } let _hsbc_30avg = cell { return Fun.avg30day _hsbc_history.Value } let _hsbc_30high = cell { return Fun.max30day _hsbc_history.Value } let _hsbc_30low = cell { return Fun.max30day _hsbc_history.Value } let _hsbc_px_last_rag = cell {let! red = _hsbc_px_last.Value < _hsbc_30low.Value let! amber = _hsbc_px_last.Value < _hsbc_30avg.Value return if red then "R" elif amber then "A" else "G"} let _hsbc_CDS_3month_rag = cell {let! red = (_hsbc_CDS_3month.Value - _hsbc_three_nine_diff.Value) / _hsbc_CDS_3month.Value > 0.95 let! amber = (_hsbc_CDS_3month.Value - _hsbc_three_nine_diff.Value) / _hsbc_CDS_3month.Value > 0.90 return if red then "R" elif amber then "A" else "G"} do this.Link () // access properties member this.hsbc_px_last = _hsbc_px_last
11
Conditional Cell closures Conditional expressions are profiled using monadic let! verb type EWISample (model : IModel) as this = inherit Cephei.Kernel.Model (model) // cell definitions let _hsbc_px_last = cell.Value (Fun.load "hsbc_px_last" 609.1) let _hsbc_history = cell.Value (Fun.load "hsbc_history" (Fun.defaultTS 260 Double.NaN)) let _hsbc_CDS_3month = cell.Value (Fun.load "hsbc_px_last" 33.1) let _hsbc_CDS_9month = cell.Value (Fun.load "hsbc_px_last" 43.1) let _hsbc_px_close = cell { return Fun.first _hsbc_history.Value } let _hsbc_three_nine_diff = cell { return _hsbc_CDS_3month.Value - _hsbc_CDS_9month.Value } let _hsbc_30avg = cell { return Fun.avg30day _hsbc_history.Value } let _hsbc_30high = cell { return Fun.max30day _hsbc_history.Value } let _hsbc_30low = cell { return Fun.max30day _hsbc_history.Value } let _hsbc_px_last_rag = cell {let! red = _hsbc_px_last.Value < _hsbc_30low.Value let! amber = _hsbc_px_last.Value < _hsbc_30avg.Value return if red then "R" elif amber then "A" else "G"} let _hsbc_CDS_3month_rag = cell {let! red = (_hsbc_CDS_3month.Value - _hsbc_three_nine_diff.Value) / _hsbc_CDS_3month.Value > 0.95 let! amber = (_hsbc_CDS_3month.Value - _hsbc_three_nine_diff.Value) / _hsbc_CDS_3month.Value > 0.90 return if red then "R" elif amber then "A" else "G"} do this.Link () // access properties member this.hsbc_px_last = _hsbc_px_last
12
Cephei Framework Cell computational expression builder appears as an extension to F# language – Conditional paths follow async workflow pattern Cell Framework, part of a larger framework – http://ql.codeplex.com C++/CLI quant wrapper http://ql.codeplex.com – Cephei.XL Excel addin
13
Parser for Excel expressions FSLex/FSYacc parser for Excel expression syntax (from samples) AST rendered to F# equivalent source and compiled for calculation with fast ticking data AST interpreted for intra-day changes One-day proof of Concept command line calculator
14
Selected for speed of development Cell framework and event based recalculation demonstrated in F# interactive Expression parser PoC in a day Multi-threaded recalculation as prices tick Values cached in Cell, only dependent cells recalculated
15
Agenda Background, Requirements and Drivers Calculation Options and Cell Framework Application Architecture and life-cycle Deployment, Handover and Lessons Learned
16
EWI Application Architecture Loosely coupled services (C#).NET 4 Windows Service deployment (C#) WCF Communication (C#) EDM Data Persistence (C#, Linq) Dynamic model generation at start-up (F#) WWF workflow and IIS ASP.NET report rendering RFA integration with Thompson Reuters Market Data WPF UI for maintenance
17
Development life-cycle Database & Service design in UML using Sparx EA & generated as C# & SQL/Server C# EDM Entity Model generated from DB Testing using MSTest cases Continuous integration using TeamCity Initial load from F# scripts using Query Extensions
18
Agenda Background, Requirements and Drivers Calculation Options and Cell Framework Application Architecture and life-cycle Deployment, Handover and Lessons Learned
19
Development / Deployment Issues IObservable <> & IObserver<> clash in Fsharp.Core 2 & mscorelib 4 F# powerpack not packaged for.NET 4 VS2010 (deployed with app) Codeplex F# powerpack & VS2010 version numbers not the same FSYacc / FSLex need VS extension for MSbuild Had to install VS on build server for consistent version – Standard was to avoid IDE install because of version classes in VS2003
20
Handover review Support company trained/contracted for C# & SQL only -> additional scope Why app not implemented in single language. Impact of porting F# to C# – F# perceived as a syntax flavour (like VB.net) – Introduction of Type information to database model and code generator high because of Expression parser – Porting FSYacc/FSLex to ANTLR (/other) – Cost of Conversion higher than original Development
21
Lessons learned Need to explain why F# is not “just another.NET language” Closures, type inference, Lambda functions, computational expressions, parsers F# “let” is not the same as VBA “LET” !! Need to explain productivity – F# used for minority of application, but contributed most value Need to package F# runtime & PowerPack
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.