QSTK的eventprofiler功能不能正确绘图 [英] QSTK's eventprofiler function doesn't plot properly

查看:111
本文介绍了QSTK的eventprofiler功能不能正确绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用乔治亚理工学院的Coursera Computational Investing课程中的QSTK,Examples / EventProfiler / tutorial.py结尾处的eventprofiler函数不会输出视频中显示的图表。 (见下图)

为第4周的练习生成的其他PDF除了事件编号以外是完全空的,这是正确的。创建PDF似乎是一种浪费,因为这些数字可能刚刚输出到终端。



我查看了图像上显示的index.py:2204的错误输出,但修复不明显。 (对于与熊猫相关的github bug类似(但不完全相同)的问题,其他一些回溯将index.py放在健康的调用堆栈中。)



的修复程序。重命名你的安装中原来的一个,并替换它。

根据Endeavor的建议,他也在你提到的课程中,我也将错误条的alpha从0.1改为0.6到使它们更可见:

  if b_errorbars == True:
plt.errorbar(li_time [i_lookback:],na_mean [i_lookback:],
yerr = na_std [i_lookback:],ecolor ='#AAAAFF',
alpha = 0.6)#将Alpha从0.1改为0.6(Jose A Dura)


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.

解决方案

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)

这篇关于QSTK的eventprofiler功能不能正确绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆