Skip to content Skip to sidebar Skip to footer

QSTK's Eventprofiler Function Doesn't Plot Properly

Using QSTK for Georgia Tech's Coursera Computational Investing course, the eventprofiler function at the end of Examples/EventProfiler/tutorial.py doesn't output the graph shown in

Solution 1:

The problem lies in EventProfiler.
Which for Ubuntu is installed by default in /usr/local/lib/python2.7/dist-packages/QSTK-0.2.8-py2.7.egg/QSTK/qstkstudy/EventProfiler.py

In this block of code :

if b_market_neutral == True:
    df_rets = df_rets - df_rets[s_market_sym]
    del df_rets[s_market_sym]
    del df_events[s_market_sym]

The problem is in the substraction. df_rets ends up filled with NaNs. Not sure why, something must have changed in the underlying system causing that.
It can be fixed by making the substraction for each symbol in a for loop like this :

if b_market_neutral == True:
    for sym in df_events.columns:
        df_rets[sym] = df_rets[sym] - df_rets[s_market_sym]
    del df_rets[s_market_sym]
    del df_events[s_market_sym]

You may download an EventProfiler.py file with the fix from here. Rename the original one in your installation and replace it for this one.
Following a suggestion from Endeavor, who is also in the course you mention, I have also changed the alpha of error bars from 0.1 to 0.6 to make them more visible :

if b_errorbars == True:
    plt.errorbar(li_time[i_lookback:], na_mean[i_lookback:],
                yerr=na_std[i_lookback:], ecolor='#AAAAFF',
                alpha=0.6) #Changed alpha from 0.1 to 0.6 (Jose A Dura)

Solution 2:

i can confirm that the issue is here within the qstkstudy/EventProfiler.py

if b_market_neutral == True:
    df_rets = df_rets - df_rets[s_market_sym] # it fails here
    del df_rets[s_market_sym]
    del df_events[s_market_sym]

i solved it like this:

if b_market_neutral == True:
        df_rets = df_rets.sub(df_rets[s_market_sym].values, axis=0)
        del df_rets[s_market_sym]
        del df_events[s_market_sym]

Post a Comment for "QSTK's Eventprofiler Function Doesn't Plot Properly"