1

Does anyone know how to replace a value in a yield curve object for revaluing a bond (to get partial durations)? I suppose you could re-do all of these steps again, but it seems like there's a better way to just adjust it in place?

http://khandrikacm.blogspot.com/2014/03/usd-yield-curve-building-using-python.html

user6142489
  • 512
  • 2
  • 10
  • 28

1 Answers1

2

If the setup is as in the page you linked, then it's as simple as writing (for instance):

swaps[(5,Years)].setValue(0.016)

setting a new value will cause the curve to be marked as out of date: the next time you ask the bond for its value, the curve will automatically recalculate and the bond will return the updated price.

See also QuantLib: Building Key Rate Risks to see how to bump the curve in a different way.

Luigi Ballabio
  • 4,128
  • 21
  • 29
  • Thanks Luigi. In referencing the code above, I'm getting a weird result where `bp = .0001 shock_term = (5,Years) swaps[shock_term].setValue(bbg_value('USSW5 Curncy')) ref = swaps[shock_term].value() swaps[shock_term].setValue(bp * 5) new = swaps[shock_term].value()` keeps returning a 'new' value that isn't the one that corresponds to new setValue() change. Said another way, no matter what I put in the `swaps[shock_term].setValue()` it seems to be stuck on a value from a prior test. Do I need to reset something? I tried using `ref` like in your YouTube tutorial. – user6142489 Sep 28 '17 at 18:45
  • Apologies how ugly the format is for that question - I could repost as another question if that's easiest. – user6142489 Sep 28 '17 at 18:57