Skip to content

Dynamic Shift #725

Answered by tibdex
EricDallAgnol asked this question in Q&A
Dec 5, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi Eric,

Indeed, passing measures to date_shift() or shift()'s offset parameter is not supported. As a workaround, if you have a small set of known in advance different offsets (let's say around 10), you could do something like that:

tt.switch(
  m["date_diff"],
  {
    -1: tt.date_shift(m["VaR"], h["RiskDate"], offset="P-1D"),
    0: m["VaR"],
    ...,
    5: tt.date_shift(m["VaR"], h["RiskDate"], offset="P5D")
  }
)

You could even create the switch() cases with a dict comprehension to have less things to type.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@EricDallAgnol
Comment options

Answer selected by EricDallAgnol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants