It’s quite easy to experiment with simple trading & risk assessment models using Python. One could start with the simple Capital asset pricing model (CAPM), which despite its limitations remains popular in various diversified portfolio construction use cases. Using the stats module of SciPy one can easily regress a company’s stock returns (Ri) against the market’s returns (Rm) in order to derive an estimate for the beta (β) of the security (Ri = α + β*Rm).
Sample code follows:
from scipy import stats
stkret = [0.085, 0.0465, -0.0693, -0.003, 0.0546]
mktret = [0.075, -0.09, -0.061, 0.065, 0.042]
beta, alpha, r_value, p_value, std_err = stats.linregress(stkret, mktret)
Accordingly, one can calculate the expected return of a security: E (Ri ) = Rf +βi * (E(Rm) −Rf) where Rf is the return on the risk-free rate. In case the return of the security is observed to have a lower return than the expected return it’s not a good choice for the portfolio, while if it is observed to have a higher return than the expected it’s a good idea to be included.
For more information about CAPM see: https://lnkd.in/gbnMHzG