<jupyter_start><jupyter_text>[0,011, 23, 15, 176][0,080, 29, 3, 121][0,025, 19, 22, 291][0,026, 25, 20, 281][0,080, 12, 1, 236][0,031, 15, 19, 402][0,021, 20, 9, 331][0,080, 5, 3, 235][0,040, 25, 5, 411][0.015, 14, 5, 407][0.088, 7, 8, 465][0.085, 3, 4, 153][0.027, 5, 12, 259][0.087, 27, 4, 185][0.044, 10, 10, 425][0.088, 23, 8, 143][0.084, 23, 24, 104][0.037, 17, 10, 235][0.029, 16, 10, 339][0.034, 16, 5, 328][0.054, 2, 11, 41][0.036, 26, 15, 313][0.020, 1, 15, 400][0.017, 13, 7, 67][0.051, 8, 28, 45][0.011, 14, 1, 482][0.025, 21, 5, 326][0.090, 24, 3, 304][0.092, 23, 5, 276][0.092, 18, 25, 435][0.097, 11, 18, 34][0.094, 13, 5, 333][0.027, 16, 7, 315][0.065, 20, 9, 323][0.050, 27, 2, 187][0.069, 10, 8, 436]<jupyter_code>chromossomes = [
    [0.011, 23, 15, 176], [0.080, 29, 3, 121], [0.025, 19, 22, 291], [0.026, 25, 20, 281], [0.080, 12, 1, 236], 
    [0.031, 15, 19, 402], [0.021, 20, 9, 331], [0.080, 5, 3, 235], [0.040, 25, 5, 411], [0.015, 14, 5, 407],
    [0.088, 7, 8, 465], [0.085, 3, 4, 153], [0.027, 5, 12, 259], [0.087, 27, 4, 185], [0.044, 10, 10, 425],
    [0.088, 23, 8, 143],[0.084, 23, 24, 104],[0.037, 17, 10, 235], [0.029, 16, 10, 339], [0.034, 16, 5, 328], 
    [0.054, 2, 11, 41], [0.036, 26, 15, 313], [0.020, 1, 15, 400], [0.017, 13, 7, 67], [0.051, 8, 28, 45],
    [0.011, 14, 1, 482], [0.025, 21, 5, 326], [0.090, 24, 3, 304], [0.092, 23, 5, 276], [0.092, 18, 25, 435], 
    [0.097, 11, 18, 34], [0.094, 13, 5, 333], [0.027, 16, 7, 315], [0.065, 20, 9, 323], [0.050, 27, 2, 187],
    [0.069, 10, 8, 436]
]

for chromossome in chromossomes:
    money = greedy_filter_rule(np_array, chromossome, 10000)
    print (chromossome, money)<jupyter_output>[0.011, 23, 15, 176] 11676.85
[0.08, 29, 3, 121] 9450.560000000001
[0.025, 19, 22, 291] 11792.88
[0.026, 25, 20, 281] 11305.49
[0.08, 12, 1, 236] 9450.560000000001
[0.031, 15, 19, 402] 12706.57
[0.021, 20, 9, 331] 11710.680000000002
[0.08, 5, 3, 235] 9450.560000000001
[0.04, 25, 5, 411] 11874.950000000006
[0.015, 14, 5, 407] 10312.980000000003
[0.088, 7, 8, 465] 10264.24
[0.085, 3, 4, 153] 10264.24
[0.027, 5, 12, 259] 10819.199999999997
[0.087, 27, 4, 185] 10264.24
[0.044, 10, 10, 425] 10236.78
[0.088, 23, 8, 143] 10264.24
[0.084, 23, 24, 104] 10264.24
[0.037, 17, 10, 235] 10483.050000000003
[0.029, 16, 10, 339] 12895.97
[0.034, 16, 5, 328] 11488.480000000003
[0.054, 2, 11, 41] 12056.9
[0.036, 26, 15, 313] 11488.480000000003
[0.02, 1, 15, 400] 12489.520000000002
[0.017, 13, 7, 67] 11971.45
[0.051, 8, 28, 45] 12071.0
[0.011, 14, 1, 482] 13402.700000000006
[0.025, 21, 5, 326] 12404.42
[0.09, 24, 3, 304] 10000.0
[0.092, 23, 5, 276] 10000.0
[0.092, 18, 25, 435] 10000.0
[0.097, 11, 18, 34] [...]<jupyter_text>^^^ ATÉ AQUI É ATÔMICO, JÁ ESTÁ TUDO EM FUNÇÃO HEHEHE ^^^  Definições importantes que vão pro relatório1. **Risk:** Risk takes on many forms but is broadly categorized as the chance an outcome or investment's actual return will differ from the expected outcome or return. Risk includes the possibility of losing some or all of the original investment.2. **Beta:** By definition, the market has a beta of 1.0, and individual stocks are ranked according to how much they deviate from the market. A stock that swings more than the market over time has a beta above 1.0. If a stock moves less than the market, the stock's beta is less than 1.0. High-beta stocks are supposed to be riskier but provide a potential for higher returns; low-beta stocks pose less risk but also lower returns.3. **Volatilidade:** Standard deviation measures the dispersion of data from its expected value. The standard deviation is used in making an investment decision to measure the amount of historical volatility associated with an investment relative to its annual rate of return. It indicates how much the current return is deviating from its expected historical normal returns. For example, a stock that has a high standard deviation experiences higher volatility, and therefore, a higher level of risk is associated with the stock.  Fuzzy 1 - Compra/Venda de uma *stock*1. **INPUTS**    1. Porcentagem de crescimento        * Universo: Quanto variou o preço da *stock* desde o último pico?        * Conjunto Fuzzy: baixo, médio, alto    2. Risco        * Universo: Qual o risco de se investir nessa *stock* ?        * Conjunto Fuzzy: baixo, médio, alto2. **OUTPUTS**    1. Porcentagem de compra/venda        * Universo: Qual a porcentagem do *budget* que deve ser gasta com essa ação?        * Conjunto Fuzzy: muito baixo, baixo, médio, alto e muito alto3. **RULES**    * Se a *stock* tem *alto crescimento* e *baixo risco* **ENTÃO** o investimento deve ser *muito alto*    * Se a *stock* tem *alto crescimento* e *médio risco* **ENTÃO** o investimento deve ser *alto*    * Se a *stock* tem *alto crescimento* e *alto risco* **ENTÃO** o investimento deve ser *baixo*    * Se a *stock* tem *médio crescimento* e *baixo risco* **ENTÃO** o investimento deve ser *alto*    * Se a *stock* tem *médio crescimento* e *médio risco* **ENTÃO** o investimento deve ser *médio*    * Se a *stock* tem *médio crescimento* e *alto risco* **ENTÃO** o investimento deve ser *baixo*        * Se a *stock* tem *baixo crescimento* e *baixo risco* **ENTÃO** o investimento deve ser *baixo*    * Se a *stock* tem *baixo crescimento* e *médio risco* **ENTÃO** o investimento deve ser *muito baixo*    * Se a *stock* tem *baixo crescimento* e *alto risco* **ENTÃO** o investimento deve ser *muito baixo* define os inputs<jupyter_code>x_filter = ctrl.Antecedent(np.arange(0, 0.20, 0.01), 'x_filter')
x_filter.automf(3)
x_filter.view()
risk_filter = ctrl.Antecedent(np.arange(0,101,1), 'risk_filter')
risk_filter.automf(3)
risk_filter.view()<jupyter_output><empty_output><jupyter_text>define os outputs<jupyter_code>percentage_filter = ctrl.Consequent(np.arange(0,101,1), 'percentage_filter')
percentage_filter.automf(5)
percentage_filter.view()<jupyter_output><empty_output><jupyter_text>define as regras<jupyter_code>rule1 = ctrl.Rule(x_filter['poor'] | risk_filter['poor'], percentage_filter['good'])
rule2 = ctrl.Rule(x_filter['average'] and risk_filter['average'], percentage_filter['decent'])
rule3 = ctrl.Rule(x_filter['good'] and risk_filter['good'], percentage_filter['mediocre'])
rule4 = ctrl.Rule(x_filter['poor'] and risk_filter['poor'], percentage_filter['decent'])
rule5 = ctrl.Rule(x_filter['average'] and risk_filter['average'], percentage_filter['average'])
rule6 = ctrl.Rule(x_filter['good'] and risk_filter['good'], percentage_filter['mediocre'])
rule7 = ctrl.Rule(x_filter['poor'] and risk_filter['poor'], percentage_filter['mediocre'])
rule8 = ctrl.Rule(x_filter['average'] and risk_filter['average'], percentage_filter['poor'])
rule9 = ctrl.Rule(x_filter['good'] and risk_filter['good'], percentage_filter['poor'])
rule1.view()
plt.show()<jupyter_output><empty_output><jupyter_text>cria o controlador fuzzy<jupyter_code>calc_pct_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9])
calc_pct_ctrl<jupyter_output><empty_output><jupyter_text>TESTE DO FUZZY PRO IGU VER<jupyter_code>pct = ctrl.ControlSystemSimulation(calc_pct_ctrl)
pct.input['x_filter'] = 200
pct.input['risk_filter'] = 200

pct.compute()

print(pct.output['percentage_filter'])
percentage_filter.view(sim=pct)<jupyter_output>20.83066751972702<jupyter_text>Fuzzy 2 - Classificação do Grau de Risco de uma *stock*1. **INPUTS**    1. Média de Variação (famosa volatilidade)        * Universo: Qual foi a média de variação no valor das *stocks* (em módulo)?        * Conjunto Fuzzy: baixo, média, alto    2. Beta        * Universo: Qual o valor da volatilidade da *stock* com relação a volatilidade do mercado?        * Conjunto Fuzzy: baixo, alto2. **OUTPUTS**    1. Risco        * Universo: Qual o grau de risco ao se investir nessa *stock* ?        * Conjunto Fuzzy: baixo, médio, alto3. **RULES**    * Se a *stock* apresenta *baixa variação* e um *baixo valor beta* **ENTAO** o risco é baixo    * Se a *stock* apresenta *baixa variação* e um *alto valor beta* **ENTAO** o risco é médio    * Se a *stock* apresenta *média variação* e um *baixo valor beta* **ENTAO** o risco é médio    * Se a *stock* apresenta *média variação* e um *alto valor beta* **ENTAO** o risco é alto    * Se a *stock* apresenta *alta variação* e um *baixo valor beta* **ENTAO** o risco é médio    * Se a *stock* apresenta *alta variação* e um *alto valor beta* **ENTAO** o risco é alto define os inputs<jupyter_code>vol =  ctrl.Antecedent(np.arange(0, 15, 1), 'vol')
vol.automf(3)
vol.view()
beta = ctrl.Antecedent(np.arange(0.95, 1.06, 0.001), 'beta')
beta['low'] = fuzz.trimf(beta.universe, [0.95, 0.95, 1.05])
beta['high'] = fuzz.trimf(beta.universe, [0.95, 1.05, 1.05])
beta.view()<jupyter_output><empty_output><jupyter_text>define os outputs<jupyter_code>risk = ctrl.Consequent(np.arange(0, 101, 1), 'risk')
risk.automf(3)
risk.view()<jupyter_output><empty_output><jupyter_text>define as regras<jupyter_code>rule1 = ctrl.Rule(vol['poor'] | beta['low'], risk['poor'])
rule2 = ctrl.Rule(vol['poor'] | beta['high'], risk['average'])
rule3 = ctrl.Rule(vol['average'] | beta['low'], risk['average'])
rule4 = ctrl.Rule(vol['average'] | beta['high'], risk['good'])
rule5 = ctrl.Rule(vol['good'] | beta['low'], risk['average'])
rule6 = ctrl.Rule(vol['good'] | beta['high'], risk['good'])
rule1.view()
plt.show()
rule1 = ctrl.Rule(vol['poor'] | beta['low'], risk['poor'])
rule2 = ctrl.Rule(vol['good'] | beta['high'], risk['good'])
rule1.view()
plt.show()<jupyter_output><empty_output><jupyter_text>cria o controlador fuzzy<jupyter_code>calc_risk_ctrl = ctrl.ControlSystem([rule1, rule2])
calc_risk_ctrl<jupyter_output><empty_output><jupyter_text>TESTE DO FUZZY PRO IGU VER<jupyter_code>risking = ctrl.ControlSystemSimulation(calc_risk_ctrl)
risking.input['vol'] = 16
risking.input['beta'] = 0.95

risking.compute()

print(risking.output['risk'])
vol.view(sim=risking)
beta.view(sim=risking)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup