
EXERCÍCIOS DE RISCO - PARTE 1

O Problema Básico da Decisão sob Incerteza
O Problema Básico da Decisão sob Incerteza


Métrica de Risco (ou Métrica de Decisão)


R. Walpole, R. Myers, S. Myers and K. Ye, “Probability and Statistics for Engineers and Scientists”, Publisher: Pearson; 9th edition, 2012.

Daniel Bernoulli and the St. Petersburg Problem (1738)
Consider a simple experiment. I will flip a coin once and will pay you a dollar if the coin came up tails on the first flip; the experiment will stop if it came up heads. If you win the dollar on the first flip, though, you will be offered a second flip where you could double your winnings if the coin came up tails again. The game will thus continue, with the prize doubling at each stage, until you come up heads. How much would you be willing to pay to partake in this gamble?
A. Damodaran, “Strategic Risk Taking: A Framework for Risk Management", Pearson Prentice Hall, August 12, 2007.

Thomas Mazzoni, “A First Course in Quantitative Finance”, Publisher: Cambridge University Press; March 29, 2018.
.

Valor Esperado da Utilidade
Sometime in your life, you will deal with the economy’s financial system. You will deposit your savings in a bank account, or you will take out a loan to cover tuition or to buy a house. After you have a job, your employer will start a retirement account for you, and you will decide whether to invest the funds in stocks, bonds, or other financial instruments. If you try to put together your own portfolio, you will have to decide between investing in established companies such as General Electric or newer ones such as Twitter. And in the media, you will hear reports about whether the stock market is up or down, together with the often feeble attempts to explain why the market behaves as it does. If you reflect for a moment on the many financial decisions you will make during your life, you will see two related elements in almost all of them: time and risk.
QUESTÃO:
Jamal has a utility function U = W^(1/2), where W is his wealth in millions of dollars and U is the utility he obtains from that wealth. In the final stage of a game show, the host offers Jamal a choice between (A) $4 million for sure, or (B) a gamble that pays $1 million with probability 0.6 and $9 million with probability 0.4.
a. Graph Jamal’s utility function. Is he risk averse? Explain.
b. Does A or B offer Jamal a higher expected prize? Explain your reasoning with appropriate calculations. (Hint: The expected value of a random variable is the weighted average of the possible outcomes, where the probabilities are the weights.)
c. Does A or B offer Jamal a higher expected utility? Again, show your calculations.
d. Should Jamal pick A or B? Why?
(Chapter 27: The Basic Tools of Finance) - do livro do N. Gregory Mankiw, “Principles of Economics”, 8th Ed., Jan 1, 2017.

Yves Hilpisch, “Python for Finance: Mastering Data-Driven Finance”, O'Reilly Media, 2nd Edition, January 8, 2019.

The farmer´s problems - 1, 2 e 3
The farmer´s problem -1 and Optimal Solution based on Expected Yields
The farmer´s problem - 2 and Optimal Solution based on Expected Yields
The farmer´s problem - 3 and Optimal Solution based on Expected Yields
John R. Birge and François Louveaux, “Introduction to Stochastic Programming”, 2nd Edition,
Springer Series in Operations Research and Financial Engineering, 2011.

Is a large loss an indication of a risk management failure??? (FRM EXAM 2009 - QUESTION 1-11)

Philippe Jorion, Financial Risk Manager Handbook - FRM PART I / PART II, 6th Edition, Wiley Finance, 2011.

The Optimum Size of Trade (or Kelly Criterion)
You may have noticed that financial markets have something in common with casinos or betting in general. That common element is the random nature of the outcome of trades and bets. In this section I show you how to find a way to optimise bets or investments, despite this randomness, so as to maximise your long-term average growth rate.
In gambling activities such as casino games, the house makes the rules and those rules are in favour of the house – of course. On average, bettors lose as the casino intends to make a profit. In the stock market, over time and on average, prices rise because of economic growth, and investors probably get a good return. But the stock market is volatile, and in the short run, you can easily lose money.
If you make a sequence of bets (or trades if you prefer financial markets), each bet has an uncertain outcome. You start with an amount of capital, P. The idea is to grow this money at the highest rate you can without going bust – in other words, without your account going to zero.
You have a probability, p, of winning each bet and a probability, (1 – p), of losing it. If you place a stake of $1, you get f dollars if you win and nothing if you lose. Win or lose, you also lose your stake, so f must be greater than 1 for the gamble to make any sense.
You need to place bets of the right size so as to conserve capital and be able to withstand the downturns that inevitably happen just by random chance. So, you need to work out the optimum size of bet to capture the positive returns available without exposing yourself to too much risk.
Steve Bell, "Quantitative Finance for Dummies", Wiley, 2016.

Agora imagine que você é um Trader, e que o CFO da empresa lhe deu $ 1,000.00 para você colocar nesse negócio aí.
Se você colocar os $ 1,000.00 todos de uma vez numa única "jogada", pode acontecer de você ganhar e levar $ 2,000.00 (3 mil que você ganhou menos as 1 mil apostas que valem $1.0 cada). Ou pode acontecer de você perder os $ 1,000.00.
Será que existe uma estratégia melhor???
Será que existe uma quantidade "alpha" de dinheiro que você coloque em cada aposta que você vai fazer e que nestas "milhares" de apostas você consiga o melhor "rendimento" possível???
Qual será o melhor"alpha" e quantas dezenas, centenas ou milhares de apostas você deve fazer???
Esse"alpha" deve ser variável para cada aposta, ou deve ser um valor constante para cada aposta???
Caso você tenha decidido fazer 3 mil apostas, você deve parar no meio do caminho se atingir algum valor interessante de lucro, ou deve executar até o final as 3 mil apostas que você decidiu que ia fazer???
#
# Betting without Losing Your Shirt
# Steve Bell, "Quantitative Finance for Dummies", 2016.
#
#
# Assume that you bet a fixed fraction, alpha, of your capital each time.
#
import numpy as np
import matplotlib.pyplot as plt
tamanho = 2000 #1.0e6
var1 = np.random.uniform(low=0.0, high=1.0, size=tamanho)
capital_inicial = np.zeros(tamanho)
capital_inicial[0] = 1000.0
probab_ganho = 0.4
ganho = 3.0
# São $3.0 para cada $1.0 que foi apostado, ou seja,
# Se você apostou $10.0 e ganhou, você leva para casa $30.0 - $10.0.
# Lembrar dos pagamentos das 10 apostas simultaneas.
alpha = 0.3 # cada jogada é 30% do Capital que eu tenho
#
# Lembrar que não podem ser feitas apostas menores que $1.0
#
flag = 0.0
for i in range(1,tamanho):
if flag == 0.0:
if var1[i] < probab_ganho:
dinheiro_ganho = alpha * capital_inicial[i-1] * (ganho - 1.0)
else:
dinheiro_ganho = alpha * capital_inicial[i-1] * (-1.0)
#endif
capital_inicial[i] = capital_inicial[i-1] + dinheiro_ganho
if capital_inicial[i] <= 1.0:
flag = 1.0
#endif
#if capital_inicial[i] >= 30.0e300*capital_inicial[0]:
#flag = 1.0
#endif
#endif
#endfor
print(" ")
print(np.amin(capital_inicial))
print(" ")
print(np.amax(capital_inicial))
plt.plot(capital_inicial, linewidth=2, color='r')
plt.grid(True)
plt.show()


Otimização de Portfólio de Markowitz

Aswath Damodaran, "Applied Corporate Finance", 4th Edition, Wiley, 2014

Otimização de Portfólio de Markowitz - 2
Three securities were selected: Microsoft, Dell, and General Electric (G.E.). The monthly returns from investing in each security are shown.
Plot the “expected return” versus “standard deviation” (aka risk/return graph) from each of three securities (Microsoft, Dell, and General Electric (G.E.) and a portfolio composed of 50% Dell and 50% G.E.
Finally plot risk/return graph for 4000 Portfolios.
import numpy as np
import matplotlib.pyplot as plt
# The monthly returns of 3 securities were selected:
# Microsoft, Dell, and General Electric (G.E.)
list1 = [[-0.66, -2.88, 10.11],
[-3.55, 20.29, 4.57],
[-4.48, -8.34, -4.16],
[2.09, 6.62, 2.00],
[-2.89, 3.94, -3.96],
[3.96, 3.67, -3.21],
[5.38, -2.58, -5.04],
[-2.34, -8.47, -8.93],
[-6.43, -4.88, -5.76],
[6.99, 11.81, 9.79],
[-3.19, -0.32, -4.79],
[1.49, -7.17, 13.64]]
data_np = np.array(list1)
data_1 = data_np / 100
print()
Return_Micro = np.mean(data_1[:,0])
print('Return_Micro = {:.2f}'.format(Return_Micro))
Return_Dell = np.mean(data_1[:,1])
print('Return_Dell = {:.2f}'.format(Return_Dell))
Return_GE = np.mean(data_1[:,2])
print('Return_GE = {:.2f}'.format(Return_GE))
print()
print('Standard_Deviation_Micro = {:.2f}'.format(np.std(data_1[:,0])))
print('Standard_Deviation_Dell = {:.2f}'.format(np.std(data_1[:,1])))
print('Standard_Deviation_GE = {:.2f}'.format(np.std(data_1[:,2])))

Edwin J. Elton, Martin J. Gruber, Stephen J. Brown and William N. Goetzmann,
“Modern Portfolio Theory and Investment Analysis”, Publisher Wiley, 2014.

Algoritmos Genéticos para Otimização de Portfólio de Markowitz
J. Shoaf, J. A. Foster, “The efficient set GA for stock portfolios”, IEEE International Conference on Evolutionary Computation Proceedings. IEEE World Congress on Computational Intelligence. 1998.

Outra Otimização de Portfólio de Markowitz
The simplest example is a portfolio containing two assets: a risk-free Treasury bill and a stock. Assume that the expected return of the Treasury bill is 3% and its risk is 0%. Further, assume that the expected return of the stock is 10% and its standard deviation is 20%. The question that needs to be answered for any individual investor is how much to invest in each of these assets.

Ray Dalio breaks down his "Holy Grail"
While Indiana Jones might have found it safely tucked away in the Temple of the Sun, to legendary investor Ray Dalio, the "Holy Grail" is a sweet spot between diversification and correlation.