arturomp arturomp - 28 days ago 4x
Python Question

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/ doesn't output the graph shown in the videos. (See image below.)

The other PDFs produced for the exercises for Week 4 are identically empty except for the event numbers, which are correct. Creating PDFs seems like a waste since those numbers could've just been output to terminal.

I looked into the error output for shown on the image but the fix is not obvious. (Some other backtraces on similar (but not identical) issues on pandas-related github bugs put in the middle of a healthy call stack.)

no graph on plot!

I might dig deeper into the eventprofiler code if I have time, but I thought I'd ask first. Stack Overflow has almost nothing on QSTK and nothing on pandas that seemed obviously relevant in a quick 5 minute search.

Note: I installed a VirtualBox, Ubuntu and QSTK as instructed in the quantsoftware wiki for the Georgia Tech Coursera Computational Investing course. I've successfully completed all assignments so far, so I think my set up should be OK.


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/

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 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)