Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PricingContext._handle_results incorrectly removes unfetched Futures #82

Open
AlexanderJHall opened this issue Dec 31, 2019 · 1 comment

Comments

@AlexanderJHall
Copy link

AlexanderJHall commented Dec 31, 2019

PricingContext._handle_results incorrectly removes unfetched Futures

PricingContext in markets.core

The following code (with dummy details) should return the ir delta of the swap and the PV of the bond. - however it throws a KeyError

with dev_session:        
        with PricingContext(is_batch=False):
            irs = IRSwap(PayReceive.Receive,'5y', Currency.GBP, 10000000, fixed_rate=0.05)
            irs_delta = irs.calc(IRDelta)
            bond = Security(isin='XS0123456789')
            bond_price = bond.price()

        print('irs delta')
        print(irs_delta.result())
        print('bond price')
        print(bond_price.result())

However the code fails with the following error:

    self._calc()
  File gs_quant\markets\core.py, line 237, in _calc
    run_request(risk_request, GsSession.current)
  File gs_quant\markets\core.py, line 201, in run_request
    self._handle_results(calc_result)
  File gs_quant\markets\core.py, line 256, in _handle_results
    positions_for_measure = self.__futures[risk_measure]
KeyError: Price

Explanation:
Two Futures are created in PricingContext.__futures as {IRDelta: Future1, Price: Future2}.
The results are fetched sequentially from the Session.
While processing the first returned results, the IRDelta, PricingContext._handle_results correctly removes the first future {IRDelta:Future1} from __Futures and sets the IRDelta onto the Future (via .set_results) - all this happens in lines 249 to 260
However _handle_results assumes that all remaining Futures are bad (see comment on line 262) and removes them from __futures (lines 264 to 268).
As a result when the second set of results, bond price, come back from the Session and flow through _handle_results __futures is an empty dictionary and so the bond price can't be bound to a future (as the future was destroyed while processing the previous result)

@andrewphillipsn
Copy link
Contributor

thanks @AlexanderJHall, we'll take a look. @nick-young-gs @david-vanden-bon can one of you guys check this out pls

@AlexanderJHall also happy to take an MR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants