0
$\begingroup$

I have to label a time series of returns into 5 categories based on the Black Litterman view approach.

The categories should look as follows:

  • very bullish: + 2 std. dev.
  • bullish: + 1 std. dev.
  • neutral: near 0 std. dev.
  • bearish: -1 std. dev.
  • very bearish: -2 std. dev.

I also have generated the past vola time series, but now I can not find any scheme to apply to get to these categorical labeling accoring to BL.

Does anyone have an idea how to approach this in python? The code blow does not work properly and output is 0. Am I missing something?

zscore = (data["Returns"] - data["Returns"].mean()) / data["vola_ind"]

#defining limits
oneposSD = data["Returns"].mean() + 1 * data["Returns"].std()
twoposSD = data["Returns"].mean() + 2 * data["Returns"].std()
neuposSD = data["Returns"].mean() + 0.1 * data["Returns"].std()
onenegSD = data["Returns"].mean() - 1 * data["Returns"].std()
twonegSD = data["Returns"].mean() - 1 * data["Returns"].std()
neunegSD = data["Returns"].mean() - 0.1 * data["Returns"].std()

#looping over data
for i in zscore:
    if i > twoposSD:
        data["Pred"] = 3.0
    elif i > oneposSD:
        data["Pred"] = 2.0
    elif i > neuposSD:
        data["Pred"] = 1.0
    elif i > neunegSD:
        data["Pred"] = 0.0
    elif i > onenegSD:
        data["Pred"] = -1.0
    elif i > twonegSD:
        data["Pred"] = -2.0
    elif i < twonegSD:
        data["Pred"] = -3.0
$\endgroup$
  • $\begingroup$ What is your expected answer? A code template? And what difference do you have in mind between the BL view and the 5 categories you propose? $\endgroup$ – Vitomir Jul 12 at 9:56
  • $\begingroup$ I want to implement this in python and that I get from a return time series to a list of ordinal numbers {-2, -1, 0, +1, +2} based on the standard deviation limits. Is there an efficient way or function? I hope it is a little bit clearer. I only can provide a list of returns which I want to transform. $\endgroup$ – smartquant Jul 12 at 12:43
  • $\begingroup$ Calculate standard deviations of returns. Then implement an elif statement with 5 mutually exclusively outcomes as you have described. $\endgroup$ – Vitomir Jul 12 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.