QSTK's eventprofiler function doesn't plot properly

情到浓时终转凉″ 提交于 2019-12-10 16:48:50

问题


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 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 index.py:2204 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 index.py in the middle of a healthy call stack.)

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.


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



回答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]


来源:https://stackoverflow.com/questions/33851603/qstks-eventprofiler-function-doesnt-plot-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!