Skip to content

galatea-associates/poc-pnl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

POC - P&L

Objectives

This Proof of Concept is intended to build an application for P&L calculations that allow us get familiarized with the relevant concepts, formulas and ultimately to iterate a design flexible enough to enable:

  • Multiple Valuation configurations and services
  • Different Asset type P&L calculations
  • Data input requirement discovery to allow service evolution

Components

Following Fuse conventions for component structure

  • Domain: entity object with no business logic.
  • Repository: classes interacting with the persistance layer.
  • Services: classes performing business logic.
  • Entry points: components interacting with the outside world.

P&L workflow

In a high level and abstract view, this application perform the P&L calculation of a set of instruments corresponding to accounts (books) in a given interval of time defined by a reference date and a target that (usually EOD).

As this diagram P&L workflow shows, the PnLService iterates through each account instrument and calculate the Unrealized and Realized P&Ls.

The Unrealized P&L need to get the valuation of the Instrument and for this we can apply different models and configuration. To enable model evolution, we have implemented and communication strategy between the PnLService and ValuationService that allows both parties to validate the input data provided and augmented accordingly. This exchange of information is detailed in the following diagram: Unrealized PnL workflow

Finally, the PnL service calculates the Realized P&L retrieving the trades involving the instrument and adding different values such as Commissions, Fees and Cash Proceeds. The following diagram details this process: Realized PnL workflow

Important Values

P&L / Risk Blotter G-Sheet

Value Formula
MTM P&L CurrentValuation.Valuation - ReferenceValuation.Valuation
MTM P&L (Book Currency) mtmPnL * CurrentValuation.FxRate
FX P&L CurrentValuation.Valuation * (ReferenceValuation.FxRate - CurrentValuation.FxRate)
LTD MTM P&L ReferencePnl.ltdMtMPnL + CurrentPnl.mtmPnL
LTD MTM P&L (Book Currency) ReferencePnl.ltdMtMPnLBook + CurrentPnl.mtmPnLBook
LTD FX P&L ReferencePnl.ltdFxPnl + CurrentPnl.fxPnl
Unrealized P&L (Instrument Currency) CurrentValuation.Valuation - ReferenceValuation.Valuation
Unrealized P&L (Book Currency) CurrentValuation.ValuationBook - ReferenceValuation.ValuationBook
Realized P&L Fees + Commissions + Proceeds

Dependencies

See pom.xml for entire list of dependencies.

Setting up in Eclipse

Code Style

Source: https://github.com/GalateaRaj/fuse-starter-java#eclipse

Set code style settings, which will allow auto-formatting of code to match the Google style guide

  • Navigate to Window -> Preferences -> Java -> Code Style -> Formatter
  • Click Import and select <project_directory>/style/eclipse-java-google-style.xml
  • Navigate to Window -> Preferences -> Java -> Code Style -> Organize Imports
  • Click Import and select <project_directory>/style/eclipse-java-google-style.importorder
  • Navigate to Window -> Preferences -> Java -> Editor -> Save Actions
  • Select the "Perform the selected actions on save", "Format source code", "Format edited lines", and "Organize imports" options

Installing lombok

Install lombok: https://projectlombok.org/setup/eclipse. Note if you're doing this step last because you raced ahead and nothing compiles you'll have to do some cleans and re-compiles to get lombok involved in generating all the class files.

Running the project

Eclipse: r-click -> run as 'Java Application' on src/main/java/org/galatea/pocpnl/App.java

After startup, UI should be available http://localhost:8080/pnl

Initial Data Import

Initial Data can be imported by the @Service DataImportService which reads text files containing a single json object per line. The DataImportService reads each file, parses each json into an object and uses the corresponfing Repository to persist the object.

src/main/resources/data/books.txt

{"bookId": "EQTY1", "currency": "USD"}
{"bookId": "EQTY2", "currency": "USD"}

public void importData() {
    importData(bookRepository, getLines("books.txt"), Book.class);
  }
  

Testing

This application is tested using a series of scenarios defined in json files. Each test will read a single json file and parse it into a TestScenario object.

A TestScenario object should have all the information required to perform the test:

  • Inputs
    • Instruments
    • Static Data
    • FxRates
    • Trades
    • Existing Valuations
  • Expected Output
    • Expected P&L results

Running the tests

Eclipse: r-click 'Run As -> JUnit Test' on src/test/java/org/galatea/pocpnl/PocPnlApplicationTests

Adding new tests

To add a new tests:

  1. Define a new json file witht the test scenario following the TestScenario.java structure.
  2. Create a new test in PocPnlApplicationTests following the existing test conventions.

Future work

See open issues

  • Swaps (cashflows)
  • Dividends/Coupons

References

Section with relevant links to information

About

Galatea POC for P&L calculation engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •