2016-04-13 17 views
1

Bir ticaret stratejisi için MACD parametrelerini optimize etmeye çalışıyorum ama maalesef paramset.label değeri ile sıkışmış durumdayım. Onu çalıştırdığınızdaQUANTSTRAT - apply.paramset issue

################################# MACD PARAMETERS OPTIMIZATION 

.fastMA <- (20:40) 
.slowMA <- (30:70) 
.nsamples = 10 

strat.st <- 'volStrat' 

# Paramset 

add.distribution(strat.st, 
       paramset.label = 'EMA', 
       component.type = 'indicator', 
       component.label = 'macd.out', 
       variable = list(n = .fastMA), 
       label = 'nFast' 
) 

add.distribution(strat.st, 
       paramset.label = 'EMA', 
       component.type = 'indicator', 
       component.label = 'macd.out', 
       variable = list(n = .slowMA), 
       label = 'nSlow' 
) 

add.distribution.constraint(strat.st, 
          paramset.label = 'EMA', 
          distribution.label.1 = 'nFast', 
          distribution.label.2 = 'nSlow', 
          operator = '<', 
          label = 'nFast<nSlow' 
) 

results <- apply.paramset(strat.st, 
          paramset.label = 'EMA', 
          portfolio = portfolio2.st, 
          account = account.st, 
          nsamples = .nsamples, 
          verbose = TRUE) 

stats <- results$tradeStats 

print(stats) 

, bu hata her bir örnek için oluşur:

evaluation # 1: 
$param.combo 
    nFast nSlow 
379 23 51 

[1] "Processing param.combo 379" 
    nFast nSlow 
379 23 51 
result of evaluating expression: 
<simpleError in strategy[[components.type]][[index]]: subscript out of bounds> 
got results for task 1 
numValues: 1, numResults: 1, stopped: FALSE 
returning status FALSE 

Ve sonra, sonuncu için, bu hatadır:

evaluation # 10: 
$param.combo 
    nFast nSlow 
585 40 60 

[1] "Processing param.combo 585" 
    nFast nSlow 
585 40 60 
result of evaluating expression: 
<simpleError in strategy[[components.type]][[index]]: subscript out of bounds> 
got results for task 10 
numValues: 10, numResults: 10, stopped: FALSE 
first call to combine function 
evaluating call object to combine results: 
    fun(result.1, result.2, result.3, result.4, result.5, result.6, 
    result.7, result.8, result.9, result.10) 
error calling combine function: 
<simpleError in fun(result.1, result.2, result.3, result.4, result.5, result.6,  result.7, result.8, result.9, result.10): attempt to select less than one element> 
numValues: 10, numResults: 10, stopped: TRUE 
Bu kodudur

Gerçekten bunu nasıl düzeltebileceğimi anlamıyorum. Bunu nasıl çözebilirim?

işte sadece benim tahminim yönü ise, size

cevap

0

Sen OPTIMIZATION bölümünden önce kod vermedi çok teşekkür ederiz.

20:40 ve 30:70 sınamak istediğinizi anlıyorum, ancak OPTİMİZASYON kodunuzda, hem "component.label = 'macd.out'" hem de 2 dağıtımını eklersiniz.

Her ikisi de MA tipi göstergeleri kullanmasına rağmen, benzer bir test yaptım, genellikle aynı MA verisini işaret etmemelidirler ("component.label = 'macd.out'"), bu kod bir dağıtım noktasını "bileşen" olarak çalıştı .label = "hızlı" "ve başka bir nokta" component.label = 'slow' "için farklı veriler gösteriyorlar, böylece karşılaştırılabilirler.

Bu yönde hata ayıklamayı deneyebilirsiniz.