1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
//Code automatically generated with fuzzylite 6.0.
FUNCTION_BLOCK investment_portfolio
VAR_INPUT
Age: REAL;
RiskTolerance: REAL;
END_VAR
VAR_OUTPUT
PercentageInStocks: REAL;
END_VAR
FUZZIFY Age
RANGE := (20.000 .. 100.000);
TERM Young := ZShape 30.000 90.000;
TERM Old := SShape 30.000 90.000;
END_FUZZIFY
FUZZIFY RiskTolerance
RANGE := (0.000 .. 10.000);
TERM Low := ZShape 2.000 8.000;
TERM High := SShape 2.000 8.000;
END_FUZZIFY
DEFUZZIFY PercentageInStocks
RANGE := (0.000 .. 100.000);
TERM AboutFifteen := Gaussian 15.000 10.000;
TERM AboutFifty := Gaussian 50.000 10.000;
TERM AboutEightyFive := Gaussian 85.000 10.000;
METHOD : COG;
ACCU : ESUM;
DEFAULT := nan;
END_DEFUZZIFY
RULEBLOCK
AND : EPROD;
OR : ESUM;
ACT : EPROD;
RULE 1 : if Age is Young or RiskTolerance is High then PercentageInStocks is AboutEightyFive
RULE 2 : if Age is Old or RiskTolerance is Low then PercentageInStocks is AboutFifteen
RULE 3 : if Age is not extremely Old and RiskTolerance is not extremely Low then PercentageInStocks is AboutFifty with 0.500
RULE 4 : if Age is not extremely Young and RiskTolerance is not extremely High then PercentageInStocks is AboutFifty with 0.500
END_RULEBLOCK
END_FUNCTION_BLOCK
|