回测平台小例子BKT:收盘前2分钟买,第二天卖

40 篇文章 7 订阅

#回测平台BKT受后台服务限制,速度稳定性上可能有问题。

dobkttest<-function(begintime="20130829",endtime="20140829",strategyname="autotest")
{
    library(WindR)
    w.start(0,FALSE);
    
    bktnote=paste(strategyname,Sys.time(),"Go");
    #begintime="20130329";
    #endtime="20140329";
    
    
    dates<-w.tdays(begintime,endtime)$Data$DATETIME;
    if(length(dates)<10)
    {
        print(dates);
        print("w.tdays error.....");
        return(1);
    }
    
    out<-w.bktstart(strategyname,begintime,endtime,'Period=1m;InitialFund=3000000');
    if(out$ErrorCode!=0)
    {
        print(out);
        print("Error on w.bktstart!");
        return (2);
    }
    bktid <- out$Data$BktId;#回测的id
    codes <- '600000.sh';
    print(paste('bktid=',bktid,'codes=',codes,'begintime=',begintime,'endtime=',endtime));
    
    for(i in c(1:length(dates))){
       print(paste('do i=',i, dates[i]));
       #查仓位
         out<-w.bktquery('position',paste(dates[i],'09:30:00'))
         if(out$ErrorCode!=0)
         {
             print(out);
             print("Error on w.bktquery--position!");
             return (3);
         }
         positions <-out$Data;
    
         #每天收盘前2分钟买,开盘2分钟卖
         if(! is.null(positions))
         {#有持仓则卖出
                 out<-w.bktorder(paste(dates[i],' 09:30:00'),positions$SecurityCode,'sell',positions$SecurityVolume);
                 if(out$ErrorCode!=0)
                 {
                     print(out);
                     print("Error on w.bktorder sell!");
                     return (6);
                 }
         }
        
       #查资金
       out<-w.bktquery('Capital',paste(dates[i],'09:30:00'))
         if(out$ErrorCode!=0)
         {
             print(out);
             print("Error on w.bktquery--Capital!");
             return (4);
         }
         
         totalfund<-out$Data$AvailableFund;        
         if(is.null(totalfund) || is.nan(totalfund) )
         {
            print("totalfund is invalid");
            print(out);
            return(5.5);
         }            
         
         
         out<-w.wsi(codes,'close',paste(dates[i]," 14:58:00"),paste(dates[i]," 14:59:00"));
         if(out$ErrorCode!=0)
         {
              if(out$ErrorCode == -40520007)  #no data available
              {
                 print(out);
                    next;
              }
             print(out);
             print("Error on w.wsi!");
             return (5);
         }
         price <- out$Data$close;
         
         volume <- totalfund / sum(price) *0.9;

         if(is.null(volume) || is.nan(volume) )
         {
            print("volume is invalid");
            print(out);
            next;
            #return(5.5);
         }            
         if(volume<100)
         {
           print(paste("volume",volume));
              next;
         }    
        
         out<-w.bktorder(paste(dates[i],' 14:59:00'),codes,'buy',floor(volume/100)*100);
         if(out$ErrorCode!=0)
         {
             print(out);
             print("Error on w.bktorder buy!");
             return (6);
         }

    }
    
    w.bktend();
    
    print('BKT has finished!');
    return(1);
}

dobkttest(begintime='20130912')

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Bad climate change may greatly increase the fragility of the country. How to evaluate the impact of climate change and mitigate the impact of climate change has become an urgent problem. With regard to task one, a data envelopment analysis (DEA) model is established to get the country's fragility. First of all, we selected 4 climate factors as input indicators and 5 output indicators. Then, we use the entropy method to determine the weight and then the national vulnerability is divided. At the same time, we get the conclusion that temperature affects GDP and the times of armed conflict directly and affects the fragility indirectly. In view of task two, we choose Somalia as an object of study. First, all the indexes are divided into 5 levels by the method of cluster analysis. Second, we select 10 countries including Somalia, to solve the decision unit matrix. Then, using the model of the problem one, it is found that the increase in temperature and rainfall will cause the national vulnerability to rise and decrease, respectively. Finally, we assign 4 climate indicators to 0 of the decision units, and draw the conclusion that national vulnerability will be reduced without the impact of climate factors. When it comes to task three, we use the rough set theory to reduce the output index to the number of armed conflicts. Then, we use the BP neural network model to predict the conclusion: There is a significant increase in fragility in cases of much more armed conflict and abnormal temperature. When the average annual armed conflict is certain, the national vulnerability index will face an increasing turning point at the temperature of 10.01 and the rainfall of 1823mm. As to task four, three policies on energy reduction and emission reduction issued by the government have been selected, and a model of carbon cycle is established. Taking China as an example, we calculate the extent of the change of the average temperature by reducing the carbon dioxide emissions from the state, and calculate the change of the national vulnerability through the change of temperature. We conclude that when the temperature drops 1.9 degrees, the national vulnerability decreases by 0.1593 and the cost is 20.3 billion $. Last but not least, due to the relative accuracy of the DEA model, the urban fragile performance is accurately predicted while the continent is not. In this paper, the TOPSIS model of distance entropy of three parameter interval number is used to modify the decision matrix of the DEA model. By increasing the upper and lower bounds of the interval, the value of the decision unit is more accurate, and then the weight of the index is modified based on the schedule. When we use the North American continent for test, the error was about 2.9%。 主要解决国家脆弱性的问题,欢迎下载。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值