Flexi Forward Product
Problem Description
We have a new product to develop, the Flexi forward, this product is characterized by:
- Fixed currency. Either sell currency or buy currency will be fixed. The final amount for the trade in the fixed currency will be decided at creation time, the other amount will vary depending on the Drawdowns that we execute over the forward.
- Allows the creation of Drawdowns at any time.
- The rate for the Drawdowns will be variable.
The procedure that we have used to develop new financial products was to create a new django model class using as base Deal or BaseDealTwo. This made the roll out of new products a slow but safe process, as the new products had to be included in previos functionalities explicitly, another caveat of this process is that it favours the obfuscation of code with inclusion of exceptions in the common code, to take into account special behaviour for some types of deal.
This is something typical:
deal = get_deal()
if isinstance(deal, ForwardDeal):
do_something()
elif isinstance(deal, SpotDeal):
do_another_slighly_different_thing()
else:
# You get the idea
For this product we want to avoid another different class to the existing ones, but we need to explore the options for future product developments.
Solution
This proposed solution is to use the class ForwardDeal as a base for ther new product, as it offers almost all the functionality that we need for the Flexi forwards, we will need some more work to adapt the Drawdowns to the requirements of the product but it is feasible.
For the forward we will have:
WINDOW_SETTLEMENT_DATE_TYPE = "window"
FIXED_SETTLEMENT_DATE_TYPE = "fixed"
FLEXI_SETTLEMENT_TYPE = "flexi"
FORWARD_TYPES = (
(WINDOW_SETTLEMENT_DATE_TYPE, "Window"),
(FIXED_SETTLEMENT_DATE_TYPE, "Fixed"),
(FLEXI_SETTLEMENT_TYPE, "Flexi")
)
DEAL_TYPE_STR = "Forward"
FIXED_DEAL_TYPE_FULL = "Fixed Forward"
WINDOW_DEAL_TYPE_FULL = "Window Forward"
FLEXI_DEAL_TYPE_FULL = "Flexi Forward"
For the Drawdown class we need access to a different rate than the one in the ForwardDeal. We could include a field for a rate and rate direction in the Drawdown or find another solution (extract the rate to an external model and access to this model only if the Drawdown is from a Flexi forward).
Another side of this project is to document all the integration process and its steps in order to develop in the future some functionality that allows us to implement all the financial products that we have in the backlog waiting to be developed. We should face this project with the transition to some form of common structure/methodology for new financial products in mind
Alternatives
For this particular case we could add subclasses from BaseDealTwo/Transaction and adjust the existing code to take into account the caracteristics of Flexi Forwards (Transaction class would be more suited to the kind of rate flexibility needed for the Flexi forwards drawdowns). The other alternative that we really tried to push was the creation of a new common class with the functionality for Flexi forward while at the same time keeping it flexible enough to allow the creation of any other financial product that we have in development queue.
We have discarded the first one as it will almost certainly include another trade class tho the mix that we have and the second one because it is not clear how to do it without analysing the common characteristics of the rest of products in queue.
These are the tasks needed for this project based on FLF - Flexi Forward - Estimation:
Estimation with BaseDealTwo/Settlement:
| Aplication | Task |
|---|---|
| BOS | FLF - Include a new model under the DealBase2 |
| BOS | FLF - Product Adapt BaseDeal2 methods to FLF |
| BOS | FLF - Adapt New Deal to book FLF |
| BOS | FLF - Create TR for FLF |
| BOS | FLF - Include in the client statement the FLF product |
| BOS | FLF - All reports where we are displaying the Deals information (x13) |
| BOS | FLF - All support reports where we are displaying the Deals information (x6) |
| BOS | FLF - Inlcude FLF in automatic processes like Due date |
| BOS | FLF - Inlcude FLF in automatic processes like OverdueDate |
| BOS | FLF - Inlcude FLF in automatic processes like Reminders |
| BOS | FLF - Inlcude FLF in automatic processes like Others |
| BOS | FLF - Calculate Profit and Loss, and commissions for FLF |
| FXS | FLF - Update Serializer in FXS to include new instrument |
| BOS | FLF - Include new Instruments when a FLF is CREATED |
| BOS | FLF - Include new Instruments when a FLF is UPDATED |
| BOS | FLF - Include new Instruments when a FLF is CANCELLED |
| BOS | FLF - Verify FLF from FLF Page |
| BOS | FLF - UnVerify FLF from FLF Page |
| BOS | FLF - Cancel FLF from FLF Page |
| BOS | FLF - Send FLF TR from FLF Page |
| BOS | FLF - Update query to exlude FLF from Any BaseDealTwo view |
| BOS | FLF - Display FLF information on Trade Log |
| BOS | FLF - FLF Page to see the FlexiForward as Product (Page product) |
| BOS | FLF - Display FLF information on Client pages |
| BOS | FLF - Display FLF information on Pages sales |
| BOS | FLF - Display FLF information on Pages operations |
| BOS | FLF - Display FLF information on Operations > Allocation Page |
| BOS | FLF - Display FLF information on Pages recon |
| BOS | FLF - Display FLF information on Pages (x10) |
| BOS | FLF - Create EndPoint on BOS to return a especific trade |
| BOS | FLF - Create EndPoint on BOS to return all FLF associated to a trade |
| BOS | FLF - Include a Group to allow just for especific group of users |
| BOS | FLF - Each epic must have a bug session |
| BOS | FLF - Monitoring tasks to allow to the team to check it. Kibana / Sentry |
| BOS | FLF - Statemachine |
| BOS | DD FLF - Create DD FlexiForward Model under the "Settlement" |
| BOS | DD FLF - Overwrite in the DD FLF model the methods to adjust to DD FLF "Settlement" |
| BOS | DD FLF - Include DD FLF on DD-WF tab, from a UI point of view, not in the model layer |
| BOS | DD FLF - Create a new TR for DD FLF product |
| BOS | DD FLF - Include in the client statement the DD FLF product |
| BOS | DD FLF - All reports where we are displaying the Deals information (x13) |
| BOS | DD FLF - All support reports where we are displaying the Deals information (x6) |
| BOS | DD FLF - Inlcude DD FLF in automatic processes like Due date |
| BOS | DD FLF - Inlcude DD FLF in automatic processes like OverdueDate |
| BOS | DD FLF - Inlcude DD FLF in automatic processes like Reminders |
| BOS | DD FLF - Inlcude DD FLF in automatic processes like Others |
| BOS | DD FLF - Calculate Profit and Loss, and commissions for DD FLF |
| BOS | DD FLF - Include the DD FLF and FLF product in the Exposure calculation |
| BOS | DD FLF - Create margin call based on FLF Exposure |
| FXS | DD FLF - Update Serializer in FXS to include new instrument |
| BOS | DD FLF - Include new Instruments when a DD FLF is CREATED |
| BOS | DD FLF - Include new Instruments when a DD FLF is UPDATED |
| BOS | DD FLF - Include new Instruments when a DD FLF is CANCELLED |
| BOS | DD FLF - Allow to selling back DD FLF product |
| BOS | DD FLF - Verify DD FLF from DD FLF Page |
| BOS | DD FLF - Unverify DD FLF from DD FLF Page |
| BOS | DD FLF - WriteOff DD FLF from DD FLF Page |
| BOS | DD FLF - Cancel DD FLF from DD FLF Page |
| BOS | DD FLF - Send DD FLF TR from DD FLF Page |
| BOS | DD FLF - Update query to exlude DD FLF from Any "Settlement query" |
| BOS | DD FLF - Display DD FLF information on Trade Log |
| BOS | DD FLF - Display DD FLF information on Pages |
| BOS | DD FLF - Display DD FLF information on Pages |
| BOS | DD FLF - Display DD FLF information on Pages |
| BOS | DD FLF - Non Verified Contract Display DD FLF information on Pages |
| BOS | DD FLF - Allocation Pages Display DD FLF information on Pages |
| BOS | DD FLF - Recon Pages Display DD FLF information on Pages B |
| BOS | DD FLF - Others Display DD FLF information on Pages (x10) |
| BOS | DD FLF - Retrieve DD FLF information on Get Trades |
| BOS | DD FLF - Retrieve DD FLF information on Get ALL Trades |
| BOS | DD FLF - Include a Group to allow just for especific group of users |
| BOS | DD FLF - Each epic must have a bug session |
| BOS | DD FLF - Monitoring tasks to allow to the team to check it. Kibana / Sentry |
| BOS | DD FLF - Statemachine |
Estimation with ForwardDeal/Drawdown:
| Aplication | Task |
|---|---|
| BOS | |
| BOS | |
| BOS | FLF - Adapt New Deal to book FLF |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | FLF - Calculate Profit and Loss, and commissions for FLF |
| FXS | FLF - Update Serializer in FXS to include new instrument |
| BOS | FLF - Include new Instruments when a FLF is CREATED |
| BOS | FLF - Include new Instruments when a FLF is UPDATED |
| BOS | FLF - Include new Instruments when a FLF is CANCELLED |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | FLF - Include a Group to allow just for especific group of users |
| BOS | FLF - Each epic must have a bug session |
| BOS | FLF - Monitoring tasks to allow to the team to check it. Kibana / Sentry |
| BOS | |
| BOS | |
| BOS | |
| BOS | DD FLF - Include DD FLF on DD-WF tab, from a UI point of view, not in the model layer |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | DD FLF - Calculate Profit and Loss, and commissions for DD FLF |
| BOS | DD FLF - Include the DD FLF and FLF product in the Exposure calculation |
| BOS | DD FLF - Create margin call based on FLF Exposure |
| FXS | DD FLF - Update Serializer in FXS to include new instrument |
| BOS | DD FLF - Include new Instruments when a DD FLF is CREATED |
| BOS | DD FLF - Include new Instruments when a DD FLF is UPDATED |
| BOS | DD FLF - Include new Instruments when a DD FLF is CANCELLED |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | |
| BOS | DD FLF - Include a Group to allow just for especific group of users |
| BOS | DD FLF - Each epic must have a bug session |
| BOS | DD FLF - Monitoring tasks to allow to the team to check it. Kibana / Sentry |
| BOS | DD FLF - Statemachine |
Caveats
We have to put extra effort in extracting a methodology to develop new products using as base the existing ones to avoid the inclusion of more workflows that do similar things with different classes (i.e anything related with payments, movement of funds has similar operation between different types of trades but different implementation, take into account the subtle differences is not easy task).
Another issue is that this kind of trades will behave as a normal ForwardDeal so any kind of functionality that do not restrict the access by type will be available for them (we have to take that into account in order to restrict anything that does not make sense for Flexi forwards). We have to be extra careful with the interaction between EBO/API and BOS.
Operation
The intended functionality will be available for Sales and operations people with a permission included that will restrict the access to selected personel.
Security Impact
This new trades will be included in the API as any other ForwardDeal and, if we need to restrict them, we have to take that into account.
Performance Impact
Nothing related to the ForwardDeal, but for the Drawdown class we either access the father ForwardDeal to check its type in order to modify its behaviour or we include a type reference in the Drawdown class. Probably we will do the former as this is a mechanism currently used for fixed/windows behaviour. Anyway this will affect the performance for some workflows where not previous distinction where needed.
Developer Impact
We strongly recommend to use this project to improve the quality of the code in the different workflows related to ForwarDeal, improving its modularity and simplicity wherever is possible.
Data Consumer Impact
Probably this will affect TMS in some way.
References
Those are the places where we check if a ForwardDeal is a windows deal, we should review it to see if we need to add logic for Flexi forwards:
- clients/views/clients/view_client.py:136
- api/serializers/trades.py:79
- core/templatetags/core_tags/trades/base.py:242
- sales/views/common/dashboard.py:186
- tms/controllers/deal_set_mapping.py:50
- api/controllers/trades.py:270
- sales/forms/forward_form.py:367
- tms/serializers/deal_serializers/base.py:250
- tms/serializers/deal_serializers/base.py:252
- tms/serializers/deal_serializers/swap_serializer.py:26
- tms/serializers/deal_serializers/broker_deal_serializer.py:106
- reports/controllers/custom_report/format.py:125
- reports/controllers/custom_report/format.py:128
- trades/managers/forwarddeal.py:24
- risk/controllers/risk/credit_limit.py:210
- risk/controllers/risk/credit_limit.py:285
- trades/forms/edit_deal_extended_form.py:100
- trades/forms/edit_deal_extended_form.py:238
- trades/forms/edit_deal_extended_form.py:460
- trades/views/operations/contract_handle/domain_services/drawdown_service.py:107
- trades/views/operations/trades/deal/edit_deal.py:134
- trades/views/operations/trades/swap/swap_deal.py:73
- trades/views/operations/trades/swap/anticipate_trade_swap.py:84
- sales/static/js/new_deal_models.js:1800
- sales/static/js/new_deal_models.js:1862
- trades/models/forward_deal.py:107
- trades/models/forward_deal.py:110
- trades/models/forward_deal.py:1168