0

この質問はすでに尋ねられていることは知っていますが、ここに投稿されたすべての回答がうまくいきませんでした。単純な 1 つのインジケーター戦略を 1 つバックテストしますが、最終的に次のエラーが発生します。

Error in .xts(e, .index(e1), .indexCLASS = indexClass(e1), .indexFORMAT = indexFormat(e1),  : 
index length must match number of observations
In addition: Warning messages:
1: In match.names(column, colnames(data)) :
all columns not located in X1.runsum for bid.vol ask.vol vol bid.freq ask.freq freq bid.price ask.price price              
2: In min(j, na.rm = TRUE) :
no non-missing arguments to min; returning Inf
3: In max(j, na.rm = TRUE) :
no non-missing arguments to max; returning -Inf

私が扱っているデータは、ビッド/アスク量、総ボリューム、ビッド/アスク クォート、クオート、1 秒間のビッド/アスク取引数を示しています。

> head(data)
                      bid.vol   ask.vol       vol bid.freq ask.freq freq bid.price ask.price   price 
2014-09-25 00:00:01 0.0000000 0.0722401 0.0722401        0        1    1        NA   408.110 408.110
2014-09-25 00:00:02 0.0423759 0.0430572 0.0854331        1        2    3   408.110   408.111 408.111
2014-09-25 00:00:03 0.0299792 0.1648549 0.1948341        1        4    5   408.106   408.112 408.112
2014-09-25 00:00:04 0.0000000 2.9369966 2.9369966        0        9    9   408.106   407.500 407.500
2014-09-25 00:00:05 0.0000000 0.0000000 0.0000000        0        0    0   408.106   407.500 407.500
2014-09-25 00:00:06 0.0000000 0.0000000 0.0000000        0        0    0   408.106   407.500 407.500

次の構造で:

> str(data)
An ‘xts’ object on 2014-09-25 00:00:01/2014-10-01 23:59:50 containing:
  Data: num [1:603994, 1:9] 0 0.0424 0.03 0 0 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:9] "bid.vol" "ask.vol" "vol" "bid.freq" ...
  Indexed by objects of class: [POSIXct,POSIXt] TZ: CET
  xts Attributes:  
 NULL
>

戦略は非常に単純です。指定された間隔の移動ウィンドウの実行中の合計がしきい値以上になると、シグナルが発生するはずです。

実行中の合計を持つインジケーターはうまく機能します:

  add.indicator(strategy.st, name = "runSum", arguments = list(x = quote(data$ask.vol), n = lookBackVol), label = "runsum")

与える

                       bid.vol   ask.vol       vol bid.freq ask.freq freq bid.price ask.price   price X1.runsum
 2014-09-25 00:00:01 0.0000000 0.0722401 0.0722401        0        1    1        NA   408.110 408.110        NA
 2014-09-25 00:00:02 0.0423759 0.0430572 0.0854331        1        2    3   408.110   408.111 408.111        NA
 2014-09-25 00:00:03 0.0299792 0.1648549 0.1948341        1        4    5   408.106   408.112 408.112        NA
 2014-09-25 00:00:04 0.0000000 2.9369966 2.9369966        0        9    9   408.106   407.500 407.500        NA
 2014-09-25 00:00:05 0.0000000 0.0000000 0.0000000        0        0    0   408.106   407.500 407.500  3.217149
 2014-09-25 00:00:06 0.0000000 0.0000000 0.0000000        0        0    0   408.106   407.500 407.500  3.144909

しかし、私が得られないのは、パラメータラベル=「runsum」で述べられているように、newc olumns が「 X1.runsum」だけでなく「runsum 」と呼ばれる理由です。これにより、シグナルを呼び出すときに命名の問題が発生する可能性があります。

> add.signal(strategy.st, name = "sigThreshold", arguments = list(column = "X1.runsum", threshold    = thresholdVol, relationship = "gte", cross = TRUE), label = "longEntry")

冒頭で説明したように、エラーが発生します。

私はこれを試しました:

  • add.signal の名前をcolumn = X1.runsumからcolumn = runsum- に変更しても役に立たなかった
  • RRT パッケージの新しいバージョンをダウンロード - 役に立たなかった
  • インジケーター機能のトリックもarguments = list(x = quote(data$ask.vol[,1])- 役に立たなかった

データには OHLC 以外の情報が含まれているため、標準の OHLC 関数を使用できません。

助けていただけますか?

4

1 に答える 1

1

間違いは2行目にありました:

test <- applyIndicators(strategy.st, data)
test <- applySignals(strategy.st, data)

インジケーターを含まない元の変更されていないデータを呼び出すためです。ただし、代わりにこれを使用します。

test <- applyIndicators(strategy.st, data)
test <- applySignals(strategy.st, test)
于 2014-11-23T23:39:18.767 に答える