__includes [ "Reports.nls" ] breed [data datum] breed [data-rules datum-rules] breed [rules-forecasts rule-forecasts] breed [aggregate-data-rules agg-datum-rules] data-own [ time price-simulation return-simulation price-ibovespa cdi-rate earnings-by-stock patrimonial-value-by-stock dividends-by-stock exchange-rate petroleum states ] data-rules-own [ predictor-no time ; pop-rules ; active-rules ; inactive-rules price-expected-1 ;; from the rule with minimum mean squared error price-expected-2 ;; from the arithmetic mean of activated rules price-expected-3 ;; from the weighted (by the 1/MSE) mean of activated rules return-expected-1 ;; from the rule with minimum mean squared error return-expected-2 ;; from the arithmetic mean of activated rules return-expected-3 ;; from the weighted (by the 1/MSE) mean of activated rules price-squared-error-1 ;; from the rule with minimum mean squared error price-squared-error-2 ;; from the arithmetic mean of activated rules price-squared-error-3 ;; from the weighted (by the 1/MSE) mean of activated rules prices-var ret-error-1 ret-error-2 ret-error-3 ret-squared-error-1 ;; from the rule with minimum mean squared error ret-squared-error-2 ;; from the arithmetic mean of activated rules ret-squared-error-3 ;; from the weighted (by the 1/MSE) mean of activated rules returns-var n-repetitions n-actives a-prev-1 ;; 05/05/2010 a-prev-2 ;; 05/05/2010 a-prev-3 ;; 05/05/2010 b-prev-1 ;; 05/05/2010 b-prev-2 ;; 05/05/2010 b-prev-3 ;; 05/05/2010 perc-bits-defined ;; 05/05/2010 perc-bit-1-defined ;; 05/05/2010 perc-bit-2-defined ;; 05/05/2010 perc-bit-3-defined ;; 05/05/2010 perc-bit-4-defined ;; 05/05/2010 perc-bit-5-defined ;; 05/05/2010 perc-bit-6-defined ;; 05/05/2010 perc-bit-7-defined ;; 05/05/2010 perc-bit-8-defined ;; 05/05/2010 perc-bit-9-defined ;; 05/05/2010 perc-bit-10-defined ;; 05/05/2010 perc-bit-11-defined ;; 05/05/2010 perc-bit-12-defined ;; 05/05/2010 perc-bit-13-defined ;; 05/05/2010 perc-bit-14-defined ;; 05/05/2010 perc-bit-15-defined ;; 05/05/2010 perc-bit-16-defined ;; 05/05/2010 perc-bit-17-defined ;; 05/05/2010 perc-bit-18-defined ;; 05/05/2010 perc-bit-19-defined ;; 05/05/2010 perc-bit-20-defined ;; 05/05/2010 perc-bit-21-defined ;; 05/05/2010 perc-bit-22-defined ;; 05/05/2010 perc-bit-23-defined ;; 05/05/2010 ] rules-forecasts-own [ predictor-no pop-rules active-rules inactive-rules no-repetitions no-actives ] aggregate-data-rules-own [ time price-expected-1 price-expected-2 price-expected-3 return-expected-1 return-expected-2 return-expected-3 price-squared-error-1 price-squared-error-2 price-squared-error-3 prices-var-1 prices-var-2 prices-var-3 ret-squared-error-1 ret-squared-error-2 ret-squared-error-3 returns-var-1 returns-var-2 returns-var-3 ] globals [ current-price previous-price previous-return previous-rules state data-file file-experiments n-bits n-obs mse-1-final mse-2-final mse-3-final stdev-1-final stdev-2-final stdev-3-final file-delimiter ] to setup [reset? file] set file-delimiter ";" if-else reset? [ clear-all-plots ask data [die] ask data-rules [die] ask aggregate-data-rules [die] ask rules-forecasts [die] ] [ clear-all-plots ask data-rules [die] ask aggregate-data-rules [die] ask rules-forecasts [die] ] reset-ticks if reset? [ set data-file ifelse-value (empty? file) [user-file][file] load-data-file set n-bits ifelse-value bit-1994? [23] [22] ] do-plots ticks tick do-plots ticks set previous-price one-of [price-simulation] of data with [time = ticks] set previous-return one-of [return-simulation] of data with [time = ticks] tick do-plots ticks if fix-seed? [random-seed seed-val] set current-price one-of [price-simulation] of data with [time = ticks] let cont 1 create-data-rules n-predictors [ ht set time 1 set predictor-no cont set cont cont + 1 ] let temp-pop-rules [] repeat n-rules [ let temp-forecast-params random-forecast-params a-inf a-sup b-inf b-sup set temp-pop-rules lput (list temp-forecast-params (item 0 (random-bit-string n-bits)) (((predicted-return (item 0 temp-forecast-params) (item 1 temp-forecast-params) 0) - (ln (current-price / previous-price))) ^ 2)) temp-pop-rules ] set cont 1 create-rules-forecasts n-predictors [ ht set predictor-no cont set pop-rules temp-pop-rules set cont cont + 1 ] set previous-return one-of [return-simulation] of data with [time = ticks] end to go ;; defines state set state one-of [states] of data with [time = ticks] ;; reproduces population of rules ask rules-forecasts [ let n-convs 0 ; let var-exp conv-criteria let prev-ret-exp-1 0 let prev-ret-exp-2 0 let prev-ret-exp-3 0 let act-rep 1 while [((cont-active pop-rules state n-bits) < (floor ((k*% / 100) * n-rules)) or n-convs <= conv-criteria) and (act-rep <= ga-rep)] [ while [((cont-active pop-rules state n-bits) < 1)] [ ;set [plabel-color] of patch 0 0 yellow ;set [plabel] of patch 0 0 (word "Pred." predictor-no "-" act-rep) ask patch 0 0 [set plabel-color yellow] let tlabel (word "Pred." predictor-no "-" act-rep) ask patch 0 0 [set plabel tlabel] set pop-rules ga-learning pop-rules state (floor ((k*% / 100) * n-rules)) a-inf a-sup b-inf b-sup n-bits previous-return set act-rep act-rep + 1 ] let tmp-selected [] let pred-returns [] if n-convs = 0 [ set tmp-selected select-active pop-rules state n-bits set active-rules item 0 tmp-selected set pred-returns sort-by [item 1 ?1 > item 1 ?2] map [list (predicted-return item 0 item 0 ? item 1 item 0 ? previous-return) ((1 / item 2 ?) / (sum map [1 / item 2 ?] active-rules))] active-rules set prev-ret-exp-1 item 0 item 0 pred-returns set prev-ret-exp-2 mean map [item 0 ?] pred-returns set prev-ret-exp-3 sum map [item 0 ? * item 1 ?] pred-returns ] ;set [plabel-color] of patch 0 0 white ;set [plabel] of patch 0 0 (word "Pred." predictor-no "-" act-rep) ask patch 0 0 [set plabel-color white] let tlabel (word "Pred." predictor-no "-" act-rep) ask patch 0 0 [set plabel tlabel] set pop-rules ga-learning pop-rules state (floor ((k*% / 100) * n-rules)) a-inf a-sup b-inf b-sup n-bits previous-return set act-rep act-rep + 1 while [((cont-active pop-rules state n-bits) < 1)] [ ;set [plabel-color] of patch 0 0 yellow ;set [plabel] of patch 0 0 (word "Pred." predictor-no "-" act-rep) ask patch 0 0 [set plabel-color yellow] set tlabel (word "Pred." predictor-no "-" act-rep) ask patch 0 0 [set plabel tlabel] set pop-rules ga-learning pop-rules state (floor ((k*% / 100) * n-rules)) a-inf a-sup b-inf b-sup n-bits previous-return set act-rep act-rep + 1 ] ;; obtains active and inactive rules set tmp-selected select-active pop-rules state n-bits set active-rules item 0 tmp-selected set inactive-rules item 1 tmp-selected set pred-returns sort-by [item 1 ?1 > item 1 ?2] map [list (predicted-return item 0 item 0 ? item 1 item 0 ? previous-return) ((1 / item 2 ?) / (sum map [1 / item 2 ?] active-rules))] active-rules let curr-ret-exp-1 item 0 item 0 pred-returns let curr-ret-exp-2 mean map [item 0 ?] pred-returns let curr-ret-exp-3 sum map [item 0 ? * item 1 ?] pred-returns ; let var-exp max (list ((abs (curr-ret-exp-1 - prev-ret-exp-1)) / (abs prev-ret-exp-1)) ((abs (curr-ret-exp-2 - prev-ret-exp-2)) / (abs prev-ret-exp-2)) ((abs (curr-ret-exp-3 - prev-ret-exp-3)) / (abs prev-ret-exp-3))) ; ifelse var-exp < conv-criteria ifelse (ifelse-value (prev-ret-exp-1 = 0) [true][(curr-ret-exp-1 / prev-ret-exp-1) > 0]) and (ifelse-value (prev-ret-exp-2 = 0) [true][(curr-ret-exp-2 / prev-ret-exp-2) > 0]) and (ifelse-value (prev-ret-exp-3 = 0) [true][(curr-ret-exp-3 / prev-ret-exp-3) > 0]) [ set n-convs n-convs + 1] [ set n-convs 0 ] ] set no-repetitions act-rep set no-actives (cont-active pop-rules state n-bits) ] ask data-rules with [time = ticks - 1] [ hatch 1 [ set time ticks let t-predictor-no predictor-no set n-repetitions one-of [no-repetitions] of rules-forecasts with [predictor-no = t-predictor-no] set n-actives one-of [no-actives] of rules-forecasts with [predictor-no = t-predictor-no] ;; calculates expectations if ticks >= obs-learning [ let tmp-active-rules one-of [active-rules] of rules-forecasts with [predictor-no = t-predictor-no] let params-prev sort-by [item 2 ?1 > item 2 ?2] map [(list (item 0 item 0 ?) (item 1 item 0 ?) ((1 / item 2 ?) / (sum map [1 / item 2 ?] tmp-active-rules)))] tmp-active-rules ;; 05/05/2010 let pred-returns sort-by [item 1 ?1 > item 1 ?2] map [list (predicted-return item 0 item 0 ? item 1 item 0 ? previous-return) ((1 / item 2 ?) / (sum map [1 / item 2 ?] tmp-active-rules))] tmp-active-rules set return-expected-1 item 0 item 0 pred-returns set return-expected-2 mean map [item 0 ?] pred-returns set return-expected-3 sum map [item 0 ? * item 1 ?] pred-returns set price-expected-1 current-price * (exp return-expected-1) set price-expected-2 current-price * (exp return-expected-2) set price-expected-3 current-price * (exp return-expected-3) set prices-var ifelse-value (length pred-returns > 1) [variance map [current-price * (exp item 0 ?)] pred-returns][0] set returns-var ifelse-value (length pred-returns > 1) [variance map [item 0 ?] pred-returns][0] set a-prev-1 item 0 item 0 params-prev ;; 05/05/2010 set b-prev-1 item 1 item 0 params-prev ;; 05/05/2010 set a-prev-2 mean map [item 0 ?] params-prev ;; 05/05/2010 set b-prev-2 mean map [item 1 ?] params-prev ;; 05/05/2010 set a-prev-3 sum map [item 0 ? * item 2 ?] params-prev ;; 05/05/2010 set b-prev-3 sum map [item 1 ? * item 2 ?] params-prev ;; 05/05/2010 set perc-bits-defined mean map [(defined-bits item 1 ?) / n-bits] tmp-active-rules ;; 05/05/2010 let no-of-active length tmp-active-rules ;; 05/05/2010 set perc-bit-1-defined ((sum map [ifelse-value (item 0 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-2-defined ((sum map [ifelse-value (item 1 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-3-defined ((sum map [ifelse-value (item 2 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-4-defined ((sum map [ifelse-value (item 3 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-5-defined ((sum map [ifelse-value (item 4 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-6-defined ((sum map [ifelse-value (item 5 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-7-defined ((sum map [ifelse-value (item 6 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-8-defined ((sum map [ifelse-value (item 7 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-9-defined ((sum map [ifelse-value (item 8 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-10-defined ((sum map [ifelse-value (item 9 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-11-defined ((sum map [ifelse-value (item 10 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-12-defined ((sum map [ifelse-value (item 11 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-13-defined ((sum map [ifelse-value (item 12 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-14-defined ((sum map [ifelse-value (item 13 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-15-defined ((sum map [ifelse-value (item 14 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-16-defined ((sum map [ifelse-value (item 15 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-17-defined ((sum map [ifelse-value (item 16 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-18-defined ((sum map [ifelse-value (item 17 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-19-defined ((sum map [ifelse-value (item 18 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-20-defined ((sum map [ifelse-value (item 19 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-21-defined ((sum map [ifelse-value (item 20 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-22-defined ((sum map [ifelse-value (item 21 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 set perc-bit-23-defined ((sum map [ifelse-value (item 22 item 1 ? = "#") [0][1]] tmp-active-rules) / no-of-active) ;; 05/05/2010 ] ] ] tick set previous-price current-price set current-price one-of [price-simulation] of data with [time = ticks] ;; evaluate activated rules ask rules-forecasts [ set pop-rules inactive-rules foreach active-rules [ let prev-squared-error item 2 ? let act-squared-error (((predicted-return (item 0 item 0 ?) (item 1 item 0 ?) previous-return) - (ln (current-price / previous-price))) ^ 2) set pop-rules lput (replace-item 2 ? ((tau * prev-squared-error) + ((1 - tau) * act-squared-error))) pop-rules ] set inactive-rules [] set active-rules [] ] ask data-rules with [time = ticks - 1] [ set price-squared-error-1 (price-expected-1 - current-price) ^ 2 set price-squared-error-2 (price-expected-2 - current-price) ^ 2 set price-squared-error-3 (price-expected-3 - current-price) ^ 2 set ret-error-1 (return-expected-1 - (ln (current-price / previous-price))) set ret-squared-error-1 ret-error-1 ^ 2 set ret-error-2 (return-expected-2 - (ln (current-price / previous-price))) set ret-squared-error-2 ret-error-2 ^ 2 set ret-error-3 (return-expected-3 - (ln (current-price / previous-price))) set ret-squared-error-3 ret-error-3 ^ 2 ] if ticks > obs-learning [ create-aggregate-data-rules 1 [ ht set time ticks - 1 set return-expected-1 mean [return-expected-1] of data-rules with [time = ticks - 1] set return-expected-2 mean [return-expected-2] of data-rules with [time = ticks - 1] set return-expected-3 mean [return-expected-3] of data-rules with [time = ticks - 1] set price-expected-1 previous-price * (exp return-expected-1) ;mean [price-expected-1] of data-rules with [time = ticks - 1] set price-expected-2 previous-price * (exp return-expected-2) ;mean [price-expected-2] of data-rules with [time = ticks - 1] set price-expected-3 previous-price * (exp return-expected-3) ;mean [price-expected-3] of data-rules with [time = ticks - 1] set price-squared-error-1 (current-price - price-expected-1) ^ 2 set price-squared-error-2 (current-price - price-expected-2) ^ 2 set price-squared-error-3 (current-price - price-expected-3) ^ 2 set ret-squared-error-1 (return-expected-1 - (ln (current-price / previous-price))) ^ 2 set ret-squared-error-2 (return-expected-2 - (ln (current-price / previous-price))) ^ 2 set ret-squared-error-3 (return-expected-3 - (ln (current-price / previous-price))) ^ 2 let mean-return-error-1 mean [ret-error-1] of data-rules with [time = ticks - 1] let mean-return-error-2 mean [ret-error-2] of data-rules with [time = ticks - 1] let mean-return-error-3 mean [ret-error-3] of data-rules with [time = ticks - 1] set prices-var-1 variance [price-expected-1] of data-rules with [time = ticks - 1] set prices-var-2 variance [price-expected-2] of data-rules with [time = ticks - 1] set prices-var-3 variance [price-expected-3] of data-rules with [time = ticks - 1] set returns-var-1 variance [return-expected-1] of data-rules with [time = ticks - 1] set returns-var-2 variance [return-expected-2] of data-rules with [time = ticks - 1] set returns-var-3 variance [return-expected-3] of data-rules with [time = ticks - 1] ] ] do-plots ticks set previous-return one-of [return-simulation] of data with [time = ticks] if ticks = (n-obs - 1) [ set mse-1-final mean [ret-squared-error-1] of aggregate-data-rules set mse-2-final mean [ret-squared-error-2] of aggregate-data-rules set mse-3-final mean [ret-squared-error-3] of aggregate-data-rules set stdev-1-final standard-deviation [ret-squared-error-1] of aggregate-data-rules set stdev-2-final standard-deviation [ret-squared-error-2] of aggregate-data-rules set stdev-3-final standard-deviation [ret-squared-error-3] of aggregate-data-rules repeat 5 [beep wait 0.6] stop ] end to do-plots [t] set-current-plot "Returns Evolution" set-current-plot-pen "actual" plot one-of [return-simulation] of data with [time = t] set-current-plot-pen "exp-1" plot ifelse-value (t <= obs-learning) [one-of [return-simulation] of data with [time = t]] [one-of [return-expected-1] of aggregate-data-rules with [time = t - 1]] set-current-plot-pen "exp-2" plot ifelse-value (t <= obs-learning) [one-of [return-simulation] of data with [time = t]] [one-of [return-expected-2] of aggregate-data-rules with [time = t - 1]] set-current-plot-pen "exp-3" plot ifelse-value (t <= obs-learning) [one-of [return-simulation] of data with [time = t]] [one-of [return-expected-3] of aggregate-data-rules with [time = t - 1]] set-current-plot "Mean Repetitions" set-current-plot-pen "repetitions" plot ifelse-value (t < 3) [0][(mean [n-repetitions] of data-rules with [time = t - 1]) / ga-rep] set-current-plot-pen "actives" plot ifelse-value (t < 3) [0][(mean [n-actives] of data-rules with [time = t - 1]) / n-rules] if t > obs-learning [ set-current-plot "Squared Return Error Evolution" set-current-plot-pen "se-1" plot one-of [ret-squared-error-1] of aggregate-data-rules with [time = t - 1] set-current-plot-pen "se-2" plot one-of [ret-squared-error-2] of aggregate-data-rules with [time = t - 1] set-current-plot-pen "se-3" plot one-of [ret-squared-error-3] of aggregate-data-rules with [time = t - 1] ] end to load-data-file if ( file-exists? data-file ) [ file-open data-file let cont 0 let prev-price 0 while [ not file-at-end? ] [ ask patch 0 0 [ set plabel word "Loading " cont ] let line file-read-line create-data 1 [ ht set time cont set price-simulation read-from-string substring line 0 position file-delimiter line set line substring line ((position file-delimiter line) + 1) (length line) set cdi-rate read-from-string substring line 0 position file-delimiter line set line substring line ((position file-delimiter line) + 1) (length line) set earnings-by-stock read-from-string substring line 0 position file-delimiter line set line substring line ((position file-delimiter line) + 1) (length line) set patrimonial-value-by-stock read-from-string substring line 0 position file-delimiter line set line substring line ((position file-delimiter line) + 1) (length line) set dividends-by-stock read-from-string substring line 0 position file-delimiter line set line substring line ((position file-delimiter line) + 1) (length line) set exchange-rate read-from-string substring line 0 position file-delimiter line set line substring line ((position file-delimiter line) + 1) (length line) set petroleum read-from-string substring line 0 position file-delimiter line set line substring line ((position file-delimiter line) + 1) (length line) set price-ibovespa read-from-string line ifelse prev-price = 0 [ set return-simulation 0 ] [ set return-simulation ln (price-simulation / prev-price) ] set prev-price price-simulation set states get-state-monthly time ] set cont cont + 1 ] ask patch 0 0 [ set plabel "Loaded!" ] set n-obs cont file-close ] end to genr-forecasts-results file-open (word "Forecast-results" remove " " remove "." remove ":" date-and-time ".csv") file-print remove " " remove "[" remove "]" (word "time;" n-values n-predictors [(word "pred-" (? + 1) "-exp-1;pred-" (? + 1) "-exp-2;pred-" (? + 1) "-exp-3;")]) foreach n-values 274 [?] [ let w-line word (? + 1) "" let t-cont 1 while [t-cont <= n-predictors] [ set w-line (word w-line ([(word ";" return-expected-1 ";" return-expected-2 ";" return-expected-3)] of data-rules with [time = ? + 1 and predictor-no = t-cont])) set t-cont t-cont + 1 ] file-print remove "]" remove "[" w-line ] file-close end to genr-ag-forecasts-results file-open (word "Ag-Forecast-results" remove " " remove "." remove ":" date-and-time ".csv") file-print "time;pred-price-1;pred-price-2;pred-price-3;pred-ret-1;pred-ret-2;pred-ret-3;spe-1;spe-2;spe-3" foreach [(list time price-expected-1 price-expected-2 price-expected-3 return-expected-1 return-expected-2 return-expected-3 ret-squared-error-1 ret-squared-error-2 ret-squared-error-3)] of aggregate-data-rules [ file-print (word item 0 ? ";" item 1 ? ";" item 2 ? ";" item 3 ? ";" item 4 ? ";" item 5 ? ";" item 6 ? ";" item 7 ? ";" item 8 ? ";" item 9 ?) ] file-close end to genr-params-results ;; 05/05/2010 file-open (word "Params-results" remove " " remove "." remove ":" date-and-time ".csv") file-print remove " " remove "[" remove "]" (word "time;" n-values n-predictors [(word "pred-" (? + 1) "-a-prev-1;pred-" (? + 1) "-a-prev-2;pred-" (? + 1) "-a-prev-3;pred-" (? + 1) "-b-prev-1;pred-" (? + 1) "-b-prev-2;pred-" (? + 1) "-b-prev-3;")]) foreach n-values 274 [?] [ let w-line word (? + 1) "" let t-cont 1 while [t-cont <= n-predictors] [ set w-line (word w-line ([(word ";" a-prev-1 ";" a-prev-2 ";" a-prev-3 ";" b-prev-1 ";" b-prev-2 ";" b-prev-3)] of data-rules with [time = ? + 1 and predictor-no = t-cont])) set t-cont t-cont + 1 ] file-print remove "]" remove "[" w-line ] file-close end to genr-bits-results ;; 05/05/2010 file-open (word "Bits-results" remove " " remove "." remove ":" date-and-time ".csv") file-print remove " " remove "[" remove "]" (word "time;" n-values n-predictors [(word "pred-" (? + 1) "-perc-bits-def;pred-" (? + 1) "-perc-bit-01;pred-" (? + 1) "-perc-bit-02;pred-" (? + 1) "-perc-bit-03;pred-" (? + 1) "-perc-bit-04;pred-" (? + 1) "-perc-bit-05;pred-" (? + 1) "-perc-bit-06;pred-" (? + 1) "-perc-bit-07;pred-" (? + 1) "-perc-bit-08;pred-" (? + 1) "-perc-bit-09;pred-" (? + 1) "-perc-bit-10;pred-" (? + 1) "-perc-bit-11;pred-" (? + 1) "-perc-bit-12;pred-" (? + 1) "-perc-bit-13;pred-" (? + 1) "-perc-bit-14;pred-" (? + 1) "-perc-bit-15;pred-" (? + 1) "-perc-bit-16;pred-" (? + 1) "-perc-bit-17;pred-" (? + 1) "-perc-bit-18;pred-" (? + 1) "-perc-bit-19;pred-" (? + 1) "-perc-bit-20;pred-" (? + 1) "-perc-bit-21;pred-" (? + 1) "-perc-bit-22;pred-" (? + 1) "-perc-bit-23;")]) foreach n-values 274 [?] [ let w-line word (? + 1) "" let t-cont 1 while [t-cont <= n-predictors] [ set w-line (word w-line ([(word ";" perc-bits-defined ";" perc-bit-1-defined ";" perc-bit-2-defined ";" perc-bit-3-defined ";" perc-bit-4-defined ";" perc-bit-5-defined ";" perc-bit-6-defined ";" perc-bit-7-defined ";" perc-bit-8-defined ";" perc-bit-9-defined ";" perc-bit-10-defined ";" perc-bit-11-defined ";" perc-bit-12-defined ";" perc-bit-13-defined ";" perc-bit-14-defined ";" perc-bit-15-defined ";" perc-bit-16-defined ";" perc-bit-17-defined ";" perc-bit-18-defined ";" perc-bit-19-defined ";" perc-bit-20-defined ";" perc-bit-21-defined ";" perc-bit-22-defined ";" perc-bit-23-defined)] of data-rules with [time = ? + 1 and predictor-no = t-cont])) set t-cont t-cont + 1 ] file-print remove "]" remove "[" w-line ] file-close end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to-report ga-learning [all-rules actual-state k-thresh p-a-inf p-a-sup p-b-inf p-b-sup no-bits prev-return] ;; Report content: ;; 0: bit-to-bit cross-over probs. ;; 1: "a" mean cross-over prob. ;; 2: "b" mean cross-over prob. ;; 3: bit-to-bit cross-over ocurrence (%) ;; 4: bit-to-bit mutation occurence (%) ;; 5: "a" cross-over ocurrence (%) ;; 6: "b" cross-over ocurrence (%) ;; 7: "a" mutation ocurrence (%) ;; 8: "b" mutation ocurrence (%) ;;let mean-a-cross-prob -1 ;;report ;;let mean-b-cross-prob -1 ;;report ;;let ocur-bit-cross n-values no-bits [0] ;;report ;;let ocur-bit-mutat n-values no-bits [0] ;;report ;;let ocur-a-cross 0 ;;report ;;let ocur-b-cross 0 ;;report ;;let ocur-a-mutat 0 ;;report ;;let ocur-b-mutat 0 ;;report let selection select-active all-rules actual-state no-bits let selection-a sort-by [item 2 ?1 < item 2 ?2] (item 0 selection) ; let final-rules sublist selection-a 0 floor ((length selection-a) * (elitism-%-active / 100)) let final-rules sublist selection-a 0 ifelse-value (length selection-a >= floor (k-thresh * (elitism-% / 100))) [floor (k-thresh * (elitism-% / 100))][length selection-a] ;; let final-rules sublist sort-by [item 2 ?1 < item 2 ?2] all-rules 0 floor ((elitism-% / 100) * n-rules) let ps map [(item 2 ?) / (sum map [item 2 ?] all-rules)] all-rules let entropy (sum map [? * log ? n-rules] ps) * -1 let selec-pressure round 2 + ((1 - entropy) * (n-rules - 2)) ;; set final-rules lput item 0 sort-by [item 2 ?1 < item 2 ?2] all-rules final-rules ; let n-e-rules item 1 selection ; foreach sublist selection-a (floor ((length selection-a) * (elitism-%-active / 100))) (length selection-a) ; [ set n-e-rules lput ? n-e-rules ] let n-e-rules all-rules let prob-cross-over [] let bit-atu 0 repeat no-bits ;; Calculate bit-to-bit cross-over probabilities [ let seq-bits map [item bit-atu item 1 ?] n-e-rules ; let matched-bits map [ifelse-value (bit-match ? bit-atu actual-state) [1][0]] seq-bits let matched-bits map [ifelse-value (item bit-atu actual-state = "#") [0.5][ifelse-value (? = "#") [0.5][ifelse-value (? = item bit-atu actual-state) [1][0]]]] seq-bits set prob-cross-over lput (((sum matched-bits) / k-thresh) * ((length selection-a) / k-thresh)) prob-cross-over ; set prob-cross-over lput ((sum matched-bits) / k-thresh) prob-cross-over set bit-atu bit-atu + 1 ] ; set prob-cross-over map [ifelse-value (? > 1) [1][?]] prob-cross-over ; let final-rules [] while [((length all-rules) - (length final-rules)) > 0] [ ;; selects two parents by tournament let parents (list (tournament-selection n-of selec-pressure n-e-rules) (tournament-selection n-of floor selec-pressure n-e-rules)) ;; generates childs' bitstrings let child-1-bitstring [] let child-2-bitstring [] set bit-atu 0 repeat no-bits [ ;; cross-over or clone ifelse (random-float 1) < (item bit-atu prob-cross-over) and (item bit-atu prob-cross-over) <= 1 [ set child-1-bitstring lput (item bit-atu item 1 item 1 parents) child-1-bitstring set child-2-bitstring lput (item bit-atu item 1 item 0 parents) child-2-bitstring ;;set ocur-bit-cross replace-item bit-atu ocur-bit-cross ((item bit-atu ocur-bit-cross) + 1) ;;report ] [ set child-1-bitstring lput (item bit-atu item 1 item 0 parents) child-1-bitstring set child-2-bitstring lput (item bit-atu item 1 item 1 parents) child-2-bitstring ] ;; mutate child-1-bit? if (random-float 1) >= (item bit-atu prob-cross-over) [ set child-1-bitstring replace-item bit-atu child-1-bitstring (bit-mutated item bit-atu child-1-bitstring bit-atu actual-state) ;;set ocur-bit-mutat replace-item bit-atu ocur-bit-mutat ((item bit-atu ocur-bit-mutat) + 1) ;;report ] ;; mutate child-2-bit? if (random-float 1) >= (item bit-atu prob-cross-over) [ set child-2-bitstring replace-item bit-atu child-2-bitstring (bit-mutated item bit-atu child-2-bitstring bit-atu actual-state) ;;set ocur-bit-mutat replace-item bit-atu ocur-bit-mutat ((item bit-atu ocur-bit-mutat) + 1) ;;report ] set bit-atu bit-atu + 1 ] ;; generates childs' forecasting parameters let child-1-a 0 let child-1-b 0 let child-2-a 0 let child-2-b 0 let a-1 item 0 item 0 item 0 parents let a-2 item 0 item 0 item 1 parents let b-1 item 1 item 0 item 0 parents let b-2 item 1 item 0 item 1 parents ;; calculates cross-over probabilities let prob-cross-a ((abs (a-1 - a-2)) / (p-a-sup - p-a-inf)) ;;set mean-a-cross-prob ifelse-value (mean-a-cross-prob = -1) [prob-cross-a] [(mean-a-cross-prob + prob-cross-a) / 2] ;;report let prob-cross-b ((abs (b-1 - b-2)) / (p-b-sup - p-b-inf)) ;;set mean-b-cross-prob ifelse-value (mean-b-cross-prob = -1) [prob-cross-b] [(mean-b-cross-prob + prob-cross-b) / 2] ;;report ;; cross-over or clone a ifelse (random-float 1) < prob-cross-a [ let mean-childs-a ((a-1 + a-2) / 2) let stdev-childs-a (sqrt ((((a-1 ^ 2) + (a-2 ^ 2)) / 4) - ((a-1 * a-2) / 2))) let val-a-1 (random-normal mean-childs-a stdev-childs-a) let val-a-2 (random-normal mean-childs-a stdev-childs-a) set child-1-a ifelse-value (val-a-1 > p-a-sup) [p-a-sup][ifelse-value (val-a-1 < p-a-inf) [p-a-inf][val-a-1]] set child-2-a ifelse-value (val-a-2 > p-a-sup) [p-a-sup][ifelse-value (val-a-2 < p-a-inf) [p-a-inf][val-a-2]] ;;set ocur-a-cross ocur-a-cross + 1 ;;report ] [ set child-1-a a-1 set child-2-a a-2 ] ;; mutate child-1-a? if (random-float 1) >= prob-cross-a [ let shock-t ((((random-float (p-a-sup - p-a-inf)) + p-a-inf) - ((p-a-sup + p-a-inf) / 2)) * (1 - prob-cross-a)) set child-1-a ifelse-value (shock-t > 0) [ifelse-value ((child-1-a + shock-t) > p-a-sup) [p-a-sup][(child-1-a + shock-t)]] [ifelse-value ((child-1-a + shock-t) < p-a-inf) [p-a-inf][(child-1-a + shock-t)]] ;;set ocur-a-mutat ocur-a-mutat + 1 ;;report ] ;; mutate child-2-a? if (random-float 1) >= prob-cross-a [ let shock-t ((((random-float (p-a-sup - p-a-inf)) + p-a-inf) - ((p-a-sup + p-a-inf) / 2)) * (1 - prob-cross-a)) set child-2-a ifelse-value (shock-t > 0) [ifelse-value ((child-2-a + shock-t) > p-a-sup) [p-a-sup][(child-2-a + shock-t)]] [ifelse-value ((child-2-a + shock-t) < p-a-inf) [p-a-inf][(child-2-a + shock-t)]] ;;set ocur-a-mutat ocur-a-mutat + 1 ;;report ] ;; cross-over or clone b ifelse (random-float 1) < prob-cross-b [ let mean-childs-b ((b-1 + b-2) / 2) let stdev-childs-b (sqrt ((((b-1 ^ 2) + (b-2 ^ 2)) / 4) - ((b-1 * b-2) / 2))) let val-b-1 (random-normal mean-childs-b stdev-childs-b) let val-b-2 (random-normal mean-childs-b stdev-childs-b) set child-1-b ifelse-value (val-b-1 > p-b-sup) [p-b-sup][ifelse-value (val-b-1 < p-b-inf) [p-b-inf][val-b-1]] set child-2-b ifelse-value (val-b-2 > p-b-sup) [p-b-sup][ifelse-value (val-b-2 < p-b-inf) [p-b-inf][val-b-2]] ;;set ocur-b-cross ocur-b-cross + 1 ;;report ] [ set child-1-b b-1 set child-2-b b-2 ] ;; mutate child-1-b? if (random-float 1) >= prob-cross-b [ let shock-t ((((random-float (p-b-sup - p-b-inf)) + p-b-inf) - ((p-b-sup + p-b-inf) / 2)) * (1 - prob-cross-b)) set child-1-b ifelse-value (shock-t > 0) [ifelse-value ((child-1-b + shock-t) > p-b-sup) [p-b-sup][(child-1-b + shock-t)]] [ifelse-value ((child-1-b + shock-t) < p-b-inf) [p-b-inf][(child-1-b + shock-t)]] ;;set ocur-b-mutat ocur-b-mutat + 1 ;;report ] ;; mutate child-2-b? if (random-float 1) >= prob-cross-b [ let shock-t ((((random-float (p-b-sup - p-b-inf)) + p-b-inf) - ((p-b-sup + p-b-inf) / 2)) * (1 - prob-cross-b)) set child-2-b ifelse-value (shock-t > 0) [ifelse-value ((child-2-b + shock-t) > p-b-sup) [p-b-sup][(child-2-b + shock-t)]] [ifelse-value ((child-2-b + shock-t) < p-b-inf) [p-b-inf][(child-2-b + shock-t)]] ;;set ocur-b-mutat ocur-b-mutat + 1 ;;report ] let parent-1-return (predicted-return (item 0 item 0 item 0 parents) (item 1 item 0 item 0 parents) prev-return) let parent-2-return (predicted-return (item 0 item 0 item 1 parents) (item 1 item 0 item 1 parents) prev-return) let child-1-return (predicted-return child-1-a child-1-b prev-return) let child-2-return (predicted-return child-2-a child-2-b prev-return) set final-rules lput (list (list child-1-a child-1-b) child-1-bitstring (mix-variance child-1-return parent-1-return parent-2-return (item 2 item 0 parents) (item 2 item 1 parents))) final-rules if ((length all-rules) - (length final-rules)) > 0 [ set final-rules lput (list (list child-2-a child-2-b) child-2-bitstring (mix-variance child-2-return parent-1-return parent-2-return (item 2 item 0 parents) (item 2 item 1 parents))) final-rules ] ] let re-evaluations re-evaluate-offsprings final-rules set final-rules (map [replace-item 2 ?1 ifelse-value (?2 = -1) [item 2 ?1] [((?2 + item 2 ?1) / 2)]] final-rules re-evaluations) ;; set ocur-bit-cross map [? / ((length final-rules) / 2)] ocur-bit-cross ;;report ;; set ocur-bit-mutat map [? / (length final-rules)] ocur-bit-mutat ;;report ;; set ocur-a-cross (ocur-a-cross / ((length final-rules) / 2)) ;;report ;; set ocur-b-cross (ocur-b-cross / ((length final-rules) / 2)) ;;report ;; set ocur-a-mutat (ocur-a-mutat / (length final-rules)) ;;report ;; set ocur-b-mutat (ocur-b-mutat / (length final-rules)) ;;report ;; report (list (list prob-cross-over mean-a-cross-prob mean-b-cross-prob ocur-bit-cross ocur-bit-mutat ocur-a-cross ocur-b-cross ocur-a-mutat ocur-b-mutat) final-rules) ;;report report final-rules end to-report tournament-selection [rules] report item 0 sort-by [item 2 ?1 < item 2 ?2] rules ; ifelse (item 2 item 0 rules) > (item 2 item 1 rules) ; [ report item 1 rules ] ; [ ; ifelse (item 2 item 0 rules) < (item 2 item 1 rules) ; [ report item 0 rules ] ; [ ; ifelse (random 1.1) = 1 ; [ report item 1 rules ] ; [ report item 0 rules ] ; ] ; ] end to-report bit-mutated [bit-before bit-atu act-state] let result bit-before let p-1 0 ifelse bit-before = "0" [ set p-1 ifelse-value (bit-match "1" bit-atu act-state) [0.75][0.25] ifelse random-float 1 < p-1 [ set result "1" ] [ set result "#" ] ] [ ifelse bit-before = "1" [ set p-1 ifelse-value (bit-match "0" bit-atu act-state) [0.75][0.25] ifelse random-float 1 < p-1 [ set result "0" ] [ set result "#" ] ] [ set p-1 ifelse-value ((bit-match "0" bit-atu act-state) and (bit-match "1" bit-atu act-state)) [0.5][ifelse-value (bit-match "0" bit-atu act-state) [0.75][0.25]] ifelse random-float 1 < p-1 [ set result "0" ] [ set result "1" ] ] ] report result end to-report mix-variance [child-pred-return parent-1-pred-return parent-2-pred-return parent-1-var parent-2-var] let dif-1 abs (child-pred-return - parent-1-pred-return) let dif-2 abs (child-pred-return - parent-2-pred-return) ifelse ((dif-1 + dif-2) = 0) [ report ifelse-value (random 1.1 = 0) [parent-1-var][parent-2-var] ] [ let part (dif-1 / (dif-1 + dif-2)) report (part * parent-2-var) + ((1 - part) * parent-1-var) ] end to-report re-evaluate-offsprings [rules] let time-ini ifelse-value (ticks - round (tau * 24) < 1) [1][ticks - round (tau * 24)] let prev-ret one-of [return-simulation] of data with [time = time-ini] let mean-squared-errors-full n-values n-rules [-1] let mean-squared-errors-actv n-values n-rules [-1] ; let futu-ret one-of [return-simulation] of data with [time = 2] ; let act-state one-of [states] of data with [time = 1] ; let mean-squared-errors-full map [(((item 0 item 0 ?) + (item 1 item 0 ?) * (prev-ret)) - (futu-ret)) ^ 2] rules ; let mean-squared-errors-actv map [((((item 0 item 0 ?) + (item 1 item 0 ?) * (prev-ret)) - (futu-ret)) ^ 2) * ifelse-value ((sum (map [ifelse-value (?1 = "#" or ?2 = "#") [1] [ifelse-value (?1 = ?2) [1][0]] ] (item 1 ?) act-state)) = n-bits)[1][0]] rules ; set prev-ret futu-ret foreach sort-by [item 0 ?1 < item 0 ?2] [(list time return-simulation states)] of data with [time > time-ini and time <= ticks] [ let futu-ret item 1 ? let act-state item 2 ? let act-squared-errors-full map [(((item 0 item 0 ?) + (item 1 item 0 ?) * (prev-ret)) - (futu-ret)) ^ 2] rules let act-squared-errors-actv map [((((item 0 item 0 ?) + (item 1 item 0 ?) * (prev-ret)) - (futu-ret)) ^ 2) * ifelse-value ((sum (map [ifelse-value (?1 = "#" or ?2 = "#") [1] [ifelse-value (?1 = ?2) [1][0]] ] (item 1 ?) act-state)) = n-bits)[1][-1]] rules set mean-squared-errors-full (map [ifelse-value (?1 = -1) [?2] [(tau * ?1) + ((1 - tau) * ?2)]] mean-squared-errors-full act-squared-errors-full) set mean-squared-errors-actv (map [ifelse-value (?1 = -1) [ifelse-value (?2 < 0) [?1][?2]] [ifelse-value (?2 < 0) [?1][(tau * ?1) + ((1 - tau) * ?2)]]] mean-squared-errors-actv act-squared-errors-actv) set prev-ret futu-ret ] report (map [ifelse-value (?2 = -1) [?1] [?2]] mean-squared-errors-full mean-squared-errors-actv) end @#$#@#$#@ GRAPHICS-WINDOW 120 445 365 530 -1 0 54.0 1 10 1 1 1 0 0 0 1 -2 0 0 0 1 1 1 ticks 30.0 BUTTON 70 10 125 43 NIL go T 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 10 10 65 43 setup setup true \"\" NIL 1 T OBSERVER NIL NIL NIL NIL 1 MONITOR 135 10 185 55 Price current-price 2 1 11 BUTTON 70 45 125 78 go-once go NIL 1 T OBSERVER NIL NIL NIL NIL 1 INPUTBOX 10 255 60 315 n-rules 100 1 0 Number INPUTBOX 10 375 60 435 a-inf -0.55 1 0 Number INPUTBOX 60 375 110 435 a-sup 0.55 1 0 Number INPUTBOX 10 435 60 495 b-inf -3.15 1 0 Number INPUTBOX 60 435 110 495 b-sup 3.15 1 0 Number INPUTBOX 60 315 110 375 tau 0.9 1 0 Number MONITOR 185 10 235 55 Time ticks 17 1 11 INPUTBOX 60 255 110 315 ga-rep 100 1 0 Number MONITOR 235 10 285 55 Total n-obs - 1 17 1 11 INPUTBOX 10 315 60 375 k*% 10 1 0 Number PLOT 305 10 900 190 Returns Evolution time return 0.0 0.0 0.0 0.0 true true "" "" PENS "exp-1" 1.0 0 -2674135 true "" "" "exp-2" 1.0 0 -13345367 true "" "" "exp-3" 1.0 0 -10899396 true "" "" "actual" 1.0 0 -16777216 true "" "" BUTTON 10 45 65 78 re-ini setup false \"\" NIL 1 T OBSERVER NIL NIL NIL NIL 1 MONITOR 135 95 205 140 Mean SE mse-1-final 17 1 11 MONITOR 135 180 205 225 Mean SE mse-2-final 17 1 11 MONITOR 135 265 205 310 Mean SE mse-3-final 17 1 11 MONITOR 215 95 285 140 SE St.Dev. stdev-1-final 17 1 11 MONITOR 215 180 287 225 SE St.Dev. stdev-2-final 17 1 11 MONITOR 215 265 287 310 SE St.Dev. stdev-3-final 17 1 11 SWITCH 130 410 230 443 bit-1994? bit-1994? 0 1 -1000 PLOT 305 190 900 370 Squared Return Error Evolution time e^2 0.0 0.0 0.0 0.0 true true "" "" PENS "se-1" 1.0 0 -2674135 true "" "" "se-2" 1.0 0 -13345367 true "" "" "se-3" 1.0 0 -10899396 true "" "" INPUTBOX 10 195 110 255 n-predictors 10 1 0 Number INPUTBOX 10 135 110 195 obs-learning 107 1 0 Number BUTTON 10 90 125 123 NIL genr-forecasts-results NIL 1 T OBSERVER NIL NIL NIL NIL 1 SWITCH 130 375 230 408 fix-seed? fix-seed? 0 1 -1000 INPUTBOX 230 375 290 435 seed-val 0 1 0 Number INPUTBOX 130 315 200 375 conv-criteria 3 1 0 Number PLOT 305 370 900 550 Mean Repetitions time number 0.0 0.0 0.0 0.0 true true "" "" PENS "repetitions" 1.0 0 -16777216 true "" "" "actives" 1.0 0 -2674135 true "" "" INPUTBOX 200 315 290 375 elitism-% 50 1 0 Number TEXTBOX 140 65 295 95 Statistics on forecasts squared error (SE) for predictor type 1: 11 0.0 1 TEXTBOX 145 150 295 176 Statistics on forecasts squared error (SE) for predictor type 2: 11 0.0 1 TEXTBOX 140 235 290 261 Statistics on forecasts squared error (SE) for predictor type 3: 11 0.0 1 @#$#@#$#@ ## WHAT IS IT? To use this model in its full form, please follow the link below: https://sites.google.com/site/jkgeconoeng/GBLCSA.zip This model implements a genetic-based classifier system to forecast stock returns. It was developed in Galimberti and da Silva (2012) in order to provide an empirical assessment on the use of computationally intensive algorithms as representative of agent’s process of inductive expectations formation. As such, it is not exactly a simulation model. Instead, it is an input-driven algorithm given that it requires a file with data on prices and other fundamental indicators in order to work. ## HOW IT WORKS The algorithm runs in a common cycle for every new point of data. The general processing cycle can be described by the following sequence (see Fig.1 in Galimberti and da Silva, 2012): 1 - The genetic algorithm is applied to the previous period set of forecasting rules. 1.1 - See Algorithm 1 in Galimberti and da Silva (2012) for details on the GA operation. 2 - The current state of the market is evaluated and the rules matching this state are activated. 3 - The forecasting equation associated to each active rule is evaluated to compute the rules return forecasts. 4 - The active rules are aggregated according to each of three possible predictors: 4.1 - Predictor 1: select the forecast from the rule with greater strength. 4.2 - Predictor 2: compute a simple arithmetic mean over rules forecasts. 4.3 - Predictor 3: compute a weighted average over rules forecasts, where the weights are given by the strength of each rule. 5 - The strength of the active rules is adjusted according to their performance. 6 - Merge the strength adjusted active rules to those that were inactive. The forecasts of interest are those obtained from step 4, but these are recorded only after an initial learning phase has passed (see obs-learning in the Parameters Description below). By the end of the exercise, i.e., when all the data supplied has been processed, the model computes statistics on the 3 predictor’s forecasts. Namely, the Mean Squared Error of forecast, and the Standard Deviation of these squared errors are presented. For more details about the functioning of the algorithm, please consult the paper. ## HOW TO USE IT - Basic Operation: Press "setup" and choose the file with data, e.g., that used in the paper is available as "Petr4-Monthly-1987-2009.csv". Then press "go" and wait until it finishes processing the whole series of data, or release the "go" button by pressing it again to stop before the end of data. Alternatively, you can also run the algorithm period-by-period by pressing the "go-once" button. For next runs, you don't need to reload the file with data again. Just press "re-ini" after setting the parameters, and follow the above procedure pressing "go" to start the algorithm execution. - Advanced Operation: You can use the BehaviorSpace tool of NetLogo to program the execution of the algorithm for different parameterizations. This may be useful for analysis. As an example, we supply one pre-specified experiment on varying the "tau" parameter value. Just go to "Tools->BehaviorSpace" on NetLogo main menu, and "Run" the experiment named "Varying Tau". Before running the many experiments, however, you need to press the setup button in order to first specify the data file to be used throughout the experiments. Also note that the Final Commands in BehaviorSpace are set to run the "genr-ag-forecasts-results" procedure, which generates a ";"-delimited .csv file with the forecasts (and its squared errors) resulting from the aggregation of each type of predictor. ## PARAMETERS DESCRIPTION - obs-learning: the number of observations used for the algorithm learning before start forecasting. - n-predictors: the number of predictor to generate within each type of predictor. - n-rules: the number of rules to hold in each predictor, i.e., the classifier system population. - ga-rep: the maximum number of replications undergone by the genetic algorithm. - k*%: minimum proportion of active rules required from the GA. - tau: determines the horizon length considered while evaluating the forecasting performance of each rule, and the speed of adjustment of the forecasting rules. - a-inf, a-sup, b-inf, b-sup: lower and upper bounds of the coefficients in the linear forecasting rules; a is the intercept, and b is the slope. - conv-criteria: the number of generations of rules that are required to have provided the same signal of return forecast, until the GA is terminated. - elitism-%: the max. percentage of rules that are directly replicated into the next generation of rules, before the GA adaptation takes place. - fix-seed?, seed-val: if active, the random seed is set to the value in seed-val, so as to facilitate replicability. - bit-1994?: indicates if the dummy bit for the 1994 structural in the Brazilian economy should be included. - genr-forecasts-results: generates a .csv file containing the series of forecasts of each predictor within the three types. ## THINGS TO NOTICE Please see the analysis in Galimberti and da Silva (2012). ## RELATED MODELS Simple Genetic Algorithm (in NetLogo Models Library\Computer Science) ## REFERENCES - Galimberti, J. K. and S. da Silva, (2012) "An empirical case against the use of genetic-based learning classifier systems as forecasting devices", Economics Bulletin, Vol. 32 No. 1 pp. 354-369. http://ideas.repec.org/a/ebl/ecbull/eb-11-00608.html - Galimberti, J. K., (2010) "Previsibilidade dos retornos acionários: avaliando o desempenho de um sistema classificador com aprendizagem baseada em algoritmos genéticos", MSc. dissertation under supervision of S. da Silva, Federal University of Santa Catarina. http://repositorio.ufsc.br/xmlui/handle/123456789/9030 ## PROGRAM DETAILS Programmer: Jaqueson K. Galimberti E-mail: jakaga2002@yahoo.com.br URL: https://sites.google.com/site/jkgeconoeng/ Date of this revision: September 2012 (first version dates from May 2010) NetLogo version: 5.0.2 (first revision was in NetLogo 4.0.4) @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 5.0.2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ setup false "" go genr-ag-forecasts-results mse-1-final stdev-1-final mse-2-final stdev-2-final mse-3-final stdev-3-final @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 1 @#$#@#$#@