鱼C论坛

 找回密码
 立即注册
查看: 2055|回复: 1

做数据分析策略 求助

[复制链接]
发表于 2019-9-21 20:40:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
已作出情绪分析
tweets[["text","positive","negative","positive_count", "negative_count","score","sentiment","time"]].head()
           text        positive        negative        positive_count        negative_count        score        sentiment        time
0        https://t.co/3PAVDdfJJr                        0        0        0        neutral        2018-08-23 13:44:47+00:00
1        NO COLLUSION - RIGGED WITCH HUNT!                        0        0        0        neutral        2018-08-23 05:10:08+00:00
2        I have asked Secretary of State @SecPompeo to ...                killing        0        1        -1        negative        2018-08-23 02:28:45+00:00
3        The only thing that I have done wrong is to wi...        win        wrong problem        1        2        -1        negative        2018-08-23 00:56:35+00:00
4        I will be interviewed on @foxandfriends by @ai...                        0        0        0        neutral        2018-08-23 00:51:38+00:00

正面:复合得分0.7
负面:复合得分-0.7

基于标普500指数的回测

开发一个简单的自定义交易情绪策略,用于对标普500指数进行回测。在深入研究交易逻辑的细节之前,我们首先做出一些假设:

回测仅限于在市场开盘或收盘时进行。理想的情况是,一旦CP的推特账号进行分析后触发买卖信号,则立马进行交易。
如果一天内产生多个信号,信号的平均值决定交易的方向。
手续费没有考虑。
比较基准是一个简单的买入并持有SPY策略。
在实际中,我们一定是要考虑交易成本的(手续费等)。

每日交易策略逻辑的基本情况如下:

基本情况:

没有交易信号

正面情绪信号:

信号出现在开盘前:开盘时买进,收盘时卖出

信号出现在交易时段:收盘时买进,明天收盘时卖出

信号出现在收盘后:明天开盘时买进,明天收盘时卖出

负面情绪信号:

信号出现在开盘前:开盘时卖出

信号出现在交易时段:收盘时卖出

信号出现在收盘后:明天开盘时卖出




CumulativeProftAndLoss=0;
for i:=1 to length_of(time_series)
     if sentiment(i) > 0.7 then
           if   timestamp(i) <  SP500(i).opentime   #早晨开盘前
                CumulativeProftAndLoss = CumulativeProftAndLoss + SP500(i).closeprice - SP500(i).openprice;
           elseif
                ...
           else
                ...
            end;
     if sentiment(i) <  -0.7 then
           if   timestamp(i) <  SP500(i).opentime   #早晨开盘前
                CumulativeProftAndLoss = CumulativeProftAndLoss + -1*(SP500(i).closeprice - SP500(i).openprice);
           elseif
                ...
           else
                ...
            end;
     endif;
end_for

现在有了这个伪代码 - 逻辑流程框架, 具体的代码还是写不出来,求大神帮忙,拜托拜托
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-10-9 11:41:24 | 显示全部楼层
求 大神解救
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-19 12:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表