【原創(chuàng)附代碼】基于R軟件的數(shù)據(jù)挖掘預(yù)測模型的股票交易系統(tǒng)_第1頁
【原創(chuàng)附代碼】基于R軟件的數(shù)據(jù)挖掘預(yù)測模型的股票交易系統(tǒng)_第2頁
【原創(chuàng)附代碼】基于R軟件的數(shù)據(jù)挖掘預(yù)測模型的股票交易系統(tǒng)_第3頁
【原創(chuàng)附代碼】基于R軟件的數(shù)據(jù)挖掘預(yù)測模型的股票交易系統(tǒng)_第4頁
【原創(chuàng)附代碼】基于R軟件的數(shù)據(jù)挖掘預(yù)測模型的股票交易系統(tǒng)_第5頁
已閱讀5頁,還剩19頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

(3)(3)4基于數(shù)據(jù)挖掘預(yù)測模型的股票交易系統(tǒng)根據(jù)上市保險(xiǎn)公司的業(yè)務(wù)分析和財(cái)務(wù)分析來看,對投資者來投資中國平安的價(jià)值最高,由于實(shí)驗(yàn)運(yùn)行時間較長,數(shù)據(jù)挖掘分析的方法相同,與選擇哪家上市保險(xiǎn)公司歷史交易數(shù)據(jù)無關(guān)。本文選擇了中國人壽歷史交易數(shù)據(jù)進(jìn)行了數(shù)據(jù)挖掘與分析。4.1數(shù)據(jù)來源本文所用數(shù)據(jù)為中國人壽(601628)歷史交易數(shù)據(jù),數(shù)據(jù)來源于雅虎財(cái)經(jīng)網(wǎng)站(網(wǎng)址:)。獲取方法為如下R代碼:library(tseries)CLI_Web_1<-as.xts(get.hist.quote("601628.ss",start="2007-01-09",quote=c("Open","High","Low","Close","Volume","AdjClose")))head(CLI_Web_1)并將所下載數(shù)據(jù)轉(zhuǎn)換為R中的時間序列對象(xts對象),本實(shí)驗(yàn)的數(shù)據(jù)開始時間為2007年1月9日,結(jié)束時間為2016年6月4日。4.2建模過程4.2.1數(shù)據(jù)處理用R函數(shù)colnames將下載數(shù)據(jù)整理成如下統(tǒng)一格式:OpenHighLowCloseVolumeAdjusted34.162007-01-0937.0040.2037.0038.9331901890034.162007-01-1039.8040.3038.7239.466861020034.632007-01-1138.8039.6037.0138.294390250033.602007-01-1237.7939.7437.5039.504217740034.662007-01-1539.8243.4538.9543.455613190038.132007-01-1645.2846.8844.0645.054456770039.534.2.2定義數(shù)據(jù)挖掘任務(wù)本模型所要解決的數(shù)據(jù)挖掘任務(wù)為預(yù)測任務(wù)。該預(yù)測的目標(biāo)變量為Ti(R代碼中名為T.ind)2007-01-1039.8040.3038.7239.466861020034.632007-01-1138.8039.6037.0138.294390250033.602007-01-1237.7939.7437.5039.504217740034.662007-01-1539.8243.4538.9543.455613190038.132007-01-1645.2846.8844.0645.054456770039.534.2.2定義數(shù)據(jù)挖掘任務(wù)本模型所要解決的數(shù)據(jù)挖掘任務(wù)為預(yù)測任務(wù)。該預(yù)測的目標(biāo)變量為Ti(R代碼中名為T.ind),其定義如下:T=工{vgV:v>p%vvp%}i(1)其中P—Ciijij=1戸=C+H+LPiiii3(2)C、H、

iiL分別為交易日i的收盤價(jià)、最高價(jià)、最低價(jià)。V(i=1,...,k)為從交易ii日i開始接下來的1?k天平均價(jià)格相對交易日i收盤價(jià)的變動率(稱收益率)。Ti第1頁共35頁第第#頁共35頁間順序。重復(fù)該過程R次也將保證訓(xùn)練集與測試集的充分變化,這增加了估計(jì)的可靠性。此外,如果使用同一個隨機(jī)選取的時間點(diǎn)集R以評價(jià)不同的模型,則可以進(jìn)行成對比較,并獲得平均表現(xiàn)差值的統(tǒng)計(jì)置信水平。4.3.2實(shí)驗(yàn)結(jié)果的比較與模型選擇結(jié)果本實(shí)驗(yàn)從2016年6月4日22:27產(chǎn)生第一個結(jié)果文件svmR.RData至2016年6月5日02:04產(chǎn)生最后一個(第5個)結(jié)果文件,耗時約2.5小時。本實(shí)驗(yàn)共產(chǎn)生360個學(xué)習(xí)模型,概述如下:>join(subset(svmR,stats=tgtStats),+subset(svmC,stats=tgtStats),+subset(nnetR,stats=tgtStats),+subset(nnetC,stats=tgtStats),+subset(earth,stats=tgtStats),+by='variants')==MonteCarloExperiment==20repetitionsMonteCarloSimulationusing:seed=1234trainsize=0.5xNROW(DataSet)testsize=0.4xNROW(DataSet)360learningsystemstestedon1datasets分別按準(zhǔn)確率(prec)、收益率(Ret)、可獲益交易的百分比(PercProf)、累計(jì)最大虧損(MaxDD)、Sharpe比率(SharpeRatio)(后二者與風(fēng)險(xiǎn)有關(guān))各指標(biāo)分別為學(xué)習(xí)模型排序,表現(xiàn)最佳的前五個模型分別為(R代碼見附錄):>rankSystems(allSysRes,5,maxs=c(T,T,T,F,T))$SP500$SP500$prec.sbsystemscoregrow.svmC.v50.3387977grow.svmC.v130.3387977grow.svmC.v210.3387977grow.svmC.v60.3284392grow.svmC.v140.3284392$SP500$Retsystemscoregrow.svmR.v1975.5605grow.svmR.v2064.8880grow.earth.v4432.2415single.nnetR.v1230.0270single.earth.v2229.2260$SP500$PercProfsystemscoregrow.svmR.v466.1595grow.svmR.v366.0185grow.svmR.v165.9255grow.svmR.v265.4300slide.svmR.v565.1710$SP500$MaxDDsystemscoregrow.svmR.v750387.93grow.svmR.v453116.55grow.svmR.v154153.04slide.svmR.v554761.33grow.svmR.v354830.22$SP500$SharpeRatiosystemscoregrow.svmR.v190.0560grow.svmR.v200.0475grow.earth.v440.0315grow.svmR.v40.0310slide.svmR.v170.0305從中可見,支持向量機(jī)類模型svrR表現(xiàn)最優(yōu),時間窗口類型為增加型的模型表現(xiàn)表現(xiàn)突出。如果按同時滿足(1)合理的交易次數(shù)至少為50次(2)平均收益率至少為0.7%(3)獲益的交易百分比至少為60%三個條件選擇模型,則結(jié)果如下:>intersect(intersect(s1,s2),s3)[1]"single.svmR.v2""slide.svmR.v2""slide.svmR.v5""slide.svmR.v6"[5]"grow.svmR.v1""grow.svmR.v2""grow.svmR.v3""grow.svmR.v4"可見,這些模型都是支持向量機(jī)模型,但滑動時間窗口與增長時間窗口幾乎各占一半。根據(jù)模型建議交易決策20個例子:>head(t1@trading,20)CloseOrderMoneyN.StocksEquity2009-03-2522.1301000000.001000000.02009-03-2622.7201000000.001000000.02009-03-2722.4701000000.001000000.02009-03-3022.0601000000.001000000.0

2009-03-3122.9901000000.001000000.02009-04-0123.1101000000.001000000.02009-04-0223.7601000000.001000000.02009-04-0323.5101000000.001000000.02009-04-0723.7401000000.001000000.02009-04-0822.6401000000.001000000.02009-04-0923.59-11200173.4-8834991779.42009-04-1024.401990166.60990166.62009-04-1325.34-11193305.1-8116987645.62009-04-1425.391985368.20985368.22009-04-1524.90-11180965.6-7762987691.82009-04-1624.6301180965.6-7762989787.52009-04-1724.4401180965.6-7762991262.32009-04-2024.761993737.20993737.22009-04-2124.09-11186380.2-8027993009.82009-04-2223.451997564.10997564.1其中1表示買入指令,-1賣出指令,0為持有指令。附錄本文用到的R代碼:#####################################################ReadingthedatafromtheCSVfile###################################################library(DMwR)library(xts)CLI<-as.xts(read.zoo('ChinaLifeInsurance.csv',header=T,sep=","))######################################################GettingthedatafromtheWeb#########################################################################################################Thefirstway:Usingget.hist.quoteintseries###################################################library(tseries)CLI_Web_1<-as.xts(get.hist.quote("601628.ss",start="2007-01-09",quote=c("Open","High","Low","Close","Volume","AdjClose")))head(CLI_Web_1)######################################################Thesecondway:UsinggetSymbolsinquantmod###################################################library(quantmod)getSymbols('601628.ss')CLI_Web_2<-get("601628.SS")head(CLI_Web_2)colnames(CLI_Web_2)<-c("Open","High","Low","Close","Volume","Adjusted")head(CLI_Web_2)######################################################Thesecondway:getseveraldatasets###################################################setSymbolLookup(CLI_Web_3=list(name='601628.ss',src='yahoo'),NCI=list(name='601336.ss',src='yahoo'),CPA=list(name='601318.ss',src='yahoo'),CPac=list(name='601601.ss',src='yahoo'))getSymbols(c('CLI_Web_3','NCI','CPA','CPac'))head(CLI_WEB_3)head(NCI)head(CPA)head(CPAC)colnames(CLI_WEB_3)<-c("Open","High","Low","Close","Volume","Adjusted")

colnames(NCI)<-c("Open","High","Low","Close","Volume","Adjusted")colnames(CPA)<-c("Open","High","Low","Close","Volume","Adjusted")colnames(CPAC)<-c("Open","High","Low","Close","Volume","Adjusted")head(CLI_WEB_3)head(NCI)head(CPA)head(CPAC)此前加載數(shù)據(jù)######################################################DefiningthePredictionTasks###################################################T.ind<-function(quotes,tgt.margin=0.025,n.days=10){v<-apply(HLC(quotes),1,mean)r<-matrix(NA,ncol=n.days,nrow=NROW(quotes))##Thefollowingstatmentiswronginthebook(page109)!for(xin1:n.days)r[,x]<-Next(Delt(Cl(quotes),v,k=x),x)x<-apply(r,1,function(x)sum(x[x>tgt.margin|x<-tgt.margin]))if(is.xts(quotes))xts(x,time(quotes))elsex}此前計(jì)算文中所述目標(biāo)變量CLI<-GSPC1<-CLI_WEB_3xts_date<-index(GSPC1)[coredata(GSPC1)[,5]!=0]xts_data<-coredata(GSPC1)[coredata(GSPC1)[,5]!=0,]GSPC<-xts(xts_data,order.by=xts_date)candleChart(last(CLI,'3months'),theme='white',TA=NULL)avgPrice<-function(p)apply(HLC(p),1,mean)addAvgPrice<-newTA(FUN=avgPrice,col=1,legend='AvgPrice')addT.ind<-newTA(FUN=T.ind,col='red',legend='tgtRet')addAvgPrice(on=1)addT.ind()library(DMwR)library(xts)CLI<-as.xts(read.zoo('002024.csv',header=T,sep=","))colnames(CLI)<-c("Open","High","Low","Close","Volume","Adjusted")library(quantmod)T.ind<-function(quotes,tgt.margin=0.025,n.days=10){v<-apply(HLC(quotes),1,mean)r<-matrix(NA,ncol=n.days,nrow=NROW(quotes))##Thefollowingstatmentiswronginthebook(page109)!for(xin1:n.days)r[,x]<-Next(Delt(Cl(quotes),v,k=x),x)x<-apply(r,1,function(x)sum(x[x>tgt.margin|x<-tgt.margin]))if(is.xts(quotes))xts(x,time(quotes))elsex}GSPC<-GSPC1<-CLIcandleChart(last(GSPC1,'3months'),theme='white',TA=NULL)avgPrice<-function(p)apply(HLC(p),1,mean)addAvgPrice<-newTA(FUN=avgPrice,col=1,legend='AvgPrice')addT.ind<-newTA(FUN=T.ind,col='red',legend='tgtRet')addAvgPrice(on=1)addT.ind()【已調(diào)試代碼】library(TTR)myATR<-function(x)ATR(HLC(x))[,'atr']mySMI<-function(x)SMI(HLC(x))[,'SMI']myADX<-function(x)ADX(HLC(x))[,'ADX']myAroon<-function(x)aroon(x[,c('High','Low')])$oscillatormyBB<-function(x)BBands(HLC(x))[,'pctB']myChaikinVol<-function(x)Delt(chaikinVolatility(x[,c("High","Low")]))[,1]myCLV<-function(x)EMA(CLV(HLC(x)))[,1]myEMV<-function(x)EMV(x[,c('High','Low')],x[,'Volume'])[,2]myMACD<-function(x)MACD(Cl(x))[,2]myMFI<-function(x)MFI(x[,c("High","Low","Close")],x[,"Volume"])mySAR<-function(x)SAR(x[,c('High','Close')])[,1]myVolat<-function(x)volatility(OHLC(x),calc="garman")[,1]此前,計(jì)算12個技術(shù)指標(biāo),作為模型解釋變量library(randomForest)data.model<-specifyModel(T.ind(GSPC)~Delt(Cl(GSPC),k=1:10)+myATR(GSPC)+mySMI(GSPC)+myADX(GSPC)+myAroon(GSPC)+myBB(GSPC)+myChaikinVol(GSPC)+myCLV(GSPC)+CMO(Cl(GSPC))+EMA(Delt(Cl(GSPC)))+myEMV(GSPC)+myVolat(GSPC)+myMACD(GSPC)+myMFI(GSPC)+RSI(Cl(GSPC))+mySAR(GSPC)+runMean(Cl(GSPC))+runSD(Cl(GSPC)),na.rm=TRUE)set.seed(1234)rf<-buildModel(data.model,method='randomForest',training.per=c(start(GSPC),index(GSPC["2012-01-09"])),ntree=50,importance=T)varImpPlot(,type=1)imp<-importance(,type=1)rownames(imp)[which(imp>6.5)]data.model<-specifyModel(T.ind(GSPC)~#Delt(Cl(GSPC),k=1)#+Delt(Cl(GSPC),k=2)#+Delt(Cl(GSPC),k=3)#+Delt(Cl(GSPC),k=4)#+Delt(Cl(GSPC),k=5)#+Delt(Cl(GSPC),k=6)#+Delt(Cl(GSPC),k=7)#+Delt(Cl(GSPC),k=8)#+Delt(Cl(GSPC),k=9)#+Delt(Cl(GSPC),k=10)+myATR(GSPC)+mySMI(GSPC)+myADX(GSPC)#+myAroon(GSPC)#+myBB(GSPC)#+myChaikinVol(GSPC)+myCLV(GSPC)#+CMO(Cl(GSPC))#+EMA(Delt(Cl(GSPC)))#+myEMV(GSPC)+myVolat(GSPC)+myMACD(GSPC)#+myMFI(GSPC)#+RSI(Cl(GSPC))+mySAR(GSPC)+runMean(Cl(GSPC))#+runSD(Cl(GSPC)))Tdata.train<-as.data.frame(modelData(data.model,data.window=c('2007-01-09','2012-01-09')))Tdata.eval<-na.omit(as.data.frame(modelData(data.model,data.window=c('2012-01-10','2016-06-2'))))Tform<-as.formula('T.ind.GSPC~.')######################################################ThePredictionModels###################################################set.seed(1234)library(nnet)norm.data<-scale(Tdata.train)nn1<-nn<-nnet(Tform,norm.data[1:700,],size=10,decay=0.01,maxit=1000,linout=T,trace=F)norm.preds<-predict(nn,norm.data[701:1000,])preds<-unscale(norm.preds,norm.data)sigs.nn<-trading.signals(preds,0.1,-0.1)true.sigs<-trading.signals(Tdata.train[701:1000,'T.ind.GSPC'],0.1,-0.1)sigs.PR(sigs.nn,true.sigs)summary(nn1)set.seed(1234)library(nnet)signals<-trading.signals(Tdata.train[,'T.ind.GSPC'],0.1,-0.1)norm.data<-data.frame(signals=signals,scale(Tdata.train[,-1]))nn2<-nn<-nnet(signals~.,norm.data[1:500,],size=10,decay=0.01,maxit=1000,trace=F)preds<-predict(nn,norm.data[501:1000,],type='class')sigs.PR(preds,norm.data[501:1000,1])summary(nn2)library(e1071)sv<-svm(Tform,Tdata.train[1:700,],gamma=0.001,cost=100)s.preds<-predict(sv,Tdata.train[701:1000,])sigs.svm<-trading.signals(s.preds,0.1,-0.1)true.sigs<-trading.signals(Tdata.train[701:1000,'T.ind.GSPC'],0.1,-0.1)sigs.PR(sigs.svm,true.sigs)summary(sv)library(kernlab)data<-cbind(signals=signals,Tdata.train[,-1])ksv<-ksvm(signals~.,data[1:500,],C=10)ks.preds<-predict(ksv,data[501:1000,])sigs.PR(ks.preds,data[501:1000,1])summary(ksv)library(earth)e<-earth(Tform,Tdata.train[1:500,])e.preds<-predict(e,Tdata.train[501:1000,])sigs.e<-trading.signals(e.preds,0.1,-0.1)true.sigs<-trading.signals(Tdata.train[501:1000,'T.ind.GSPC'],0.1,-0.1)sigs.PR(sigs.e,true.sigs)summary(e)######################################################FromPredictionsintoActions###################################################policy.1<-function(signals,market,opened.pos,money,bet=0.2,hold.time=10,f=0.025,max.loss=0.05){d<-NROW(market)#thisistheIDoftodayorders<-NULLnOs<-NROW(opened.pos)#nothingtodo!if(!nOs&&signals[d]=='h')return(orders)#Firstletscheckifwecanopennewpositions#i)longpositionsif(signals[d]=='b'&&!nOs){quant<-round(bet*money/market[d,'Close'],0)if(quant>0)orders<-rbind(orders,data.frame(order=c(1,-1,-1),order.type=c(1,2,3),val=c(quant,market[d,'Close']*(1+f),market[d,'Close']*(1-max.loss)),action=c('open','close','close'),posID=c(NA,NA,NA)))#ii)shortpositions}elseif(signals[d]=='s'&&!nOs){#thisisthenrofstockswealreadyneedtobuy#becauseofcurrentlyopenedshortpositionsneed2buy<-sum(opened.pos[opened.pos[,'pos.type']==-1,"N.stocks"])*market[d,'Close']quant<-round(bet*(money-need2buy)/market[d,'Close'],0)if(quant>0)orders<-rbind(orders,data.frame(order=c(-1,1,1),order.type=c(1,2,3),val=c(quant,market[d,'Close']*(1-f),market[d,'Close']*(1+max.loss)),action=c('open','close','close'),posID=c(NA,NA,NA)))}#Nowletscheckifweneedtoclosepositions#becausetheirholdingtimeisoverif(nOs)for(iin1:nOs){if(d-opened.pos[i,'Odate']>=hold.time)orders<-rbind(orders,data.frame(order=-opened.pos[i,'pos.type'],order.type=1,val=NA,action='close',posID=rownames(opened.pos)[i]))orders}policy.2<-function(signals,market,opened.pos,money,bet=0.2,f=0.025,max.loss=0.05){d<-NROW(market)#thisistheIDoftodayorders<-NULLnOs<-NROW(opened.pos)#nothingtodo!if(!nOs&&signals[d]=='h')return(orders)#Firstletscheckifwecanopennewpositions#i)longpositionsif(signals[d]=='b'){quant<-round(bet*money/market[d,'Close'],0)if(quant>0)orders<-rbind(orders,data.frame(order=c(1,-1,-1),order.type=c(1,2,3),val=c(quant,market[d,'Close']*(1+f),market[d,'Close']*(1-max.loss)),action=c('open','close','close'),posID=c(NA,NA,NA)))#ii)shortpositions}elseif(signals[d]=='s'){#thisisthemoneyalreadycommittedtobuystocks#becauseofcurrentlyopenedshortpositionsneed2buy<-sum(opened.pos[opened.pos[,'pos.type']==-1,"N.stocks"])*market[d,'Close']quant<-round(bet*(money-need2buy)/market[d,'Close'],0)if(quant>0)orders<-rbind(orders,data.frame(order=c(-1,1,1),order.type=c(1,2,3),val=c(quant,market[d,'Close']*(1-f),market[d,'Close']*(1+max.loss)),action=c('open','close','close'),posID=c(NA,NA,NA)))}orders}#Trainandtestperiodsstart<-1len.tr<-500len.ts<-500tr<-start:(start+len.tr-1)ts<-(start+len.tr):(start+len.tr+len.ts-1)#gettingthequotesforthetestingperiod###data(GSPC)date<-rownames(Tdata.train[start+len.tr,])market<-GSPC[paste(date,'/',sep='')][1:len.ts]#learningthemodelandobtainingitssignalpredictionslibrary(e1071)s<-svm(Tform,Tdata.train[tr,],cost=10,gamma=0.01)p<-predict(s,Tdata.train[ts,])sig<-trading.signals(p,0.1,-0.1)#nowusingthesimulatedtradert1<-trading.simulator(market,sig,'policy.1',list(f=0.05,bet=0.2,hold.time=30))t1summary(t1)tradingEvaluation(t1)plot(t1,market,theme='white',name='CLI')t2<-trading.simulator(market,sig,'policy.2',list(f=0.05,bet=0.3))summary(t2)tradingEvaluation(t2)start<-100len.tr<-500len.ts<-500tr<-start:(start+len.tr-1)ts<-(start+len.tr):(start+len.tr+len.ts-1)s<-svm(Tform,Tdata.train[tr,],cost=10,gamma=0.01)p<-predict(s,Tdata.train[ts,])sig<-trading.signals(p,0.1,-0.1)t2<-trading.simulator(market,sig,'policy.2',list(f=0.05,bet=0.3))summary(t2)tradingEvaluation(t2)######################################################ModelEvaluationandSelection###################################################MC.svmR<-function(form,train,test,b.t=0.1,s.t=-0.1,...){require(e1071)t<-svm(form,train,...)p<-predict(t,test)trading.signals(p,b.t,s.t)}MC.svmC<-function(form,train,test,b.t=0.1,s.t=-0.1,...){require(e1071)tgtName<-all.vars(form)[1]train[,tgtName]<-trading.signals(train[,tgtName],b.t,s.t)t<-svm(form,train,...)p<-predict(t,test)factor(p,levels=c('s','h','b'))}MC.nnetR<-function(form,train,test,b.t=0.1,s.t=-0.1,...){require(nnet)t<-nnet(form,train,...)p<-predict(t,test)trading.signals(p,b.t,s.t)}MC.nnetC<-function(form,train,test,b.t=0.1,s.t=-0.1,...){require(nnet)tgtName<-all.vars(form)[1]train[,tgtName]<-trading.signals(train[,tgtName],b.t,s.t)t<-nnet(form,train,...)p<-predict(t,test,type='class')factor(p,levels=c('s','h','b'))}MC.earth<-function(form,train,test,b.t=0.1,s.t=-0.1,...){require(earth)t<-earth(form,train,...)p<-predict(t,test)trading.signals(p,b.t,s.t)}singleModel<-function(form,train,test,learner,policy.func,...){p<-do.call(paste('MC',learner,sep='.'),list(form,train,test,...))eval.stats(form,train,test,p,policy.func=policy.func)}slide<-function(form,train,test,learner,relearn.step,policy.func,...){real.learner<-learner(paste('MC',learner,sep='.'),pars=list(...))p<-slidingWindowTest(real.learner,form,train,test,relearn.step)p<-factor(p,levels=1:3,labels=c('s','h','b'))eval.stats(form,train,test,p,policy.func=policy.func)}grow<-function(form,train,test,learner,relearn.step,policy.func,...){real.learner<-learner(paste('MC',learner,sep='.'),pars=list(...))p<-growingWindowTest(real.learner,form,train,test,relearn.step)p<-factor(p,levels=1:3,labels=c('s','h','b'))eval.stats(form,train,test,p,policy.func=policy.func)}eval.stats<-function(form,train,test,preds,b.t=0.1,s.t=-0.1,...){#SignalsevaluationtgtName<-all.vars(form)[1]test[,tgtName]<-trading.signals(test[,tgtName],b.t,s.t)st<-sigs.PR(preds,test[,tgtName])dim(st)<-NULLnames(st)<-paste(rep(c('prec','rec'),each=3),c('s','b','sb'),sep='.')#Tradingevaluationdate<-rownames(test)[1]market<-GSPC[paste(date,"/",sep='')][1:length(preds),]trade.res<-trading.simulator(market,preds,...)c(st,tradingEvaluation(trade.res))}pol1<-function(signals,market,op,money)policy.1(signals,market,op,money,bet=0.2,f=0.025,max.loss=0.05,hold.time=10)pol2<-function(signals,market,op,money)policy.1(signals,market,op,money,bet=0.2,f=0.05,max.loss=0.05,hold.time=20)pol3<-function(signals,market,op,money)policy.2(signals,market,op,money,bet=0.5,f=0.05,max.loss=0.05)#ThelistoflearnerswewilluseTODO<-c('svmR','svmC','earth','nnetR','nnetC')#ThedatasetsusedinthecomparisonDSs<-list(dataset(Tform,Tdata.train,'SP500'))#MonteCarlo(MC)settingsusedMCsetts<-mcSettings(20,#20repetitionsoftheMCexps0.5,#~10yearsfortraining0.4,#~5yearsfortesting1234)#randomnumbergeneratorseed#VariantstotryforalllearnersVARS<-list()VARS$svmR<-list(cost=c(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論