The objective of the portfolio optimization problem is to trade off expected return ($\mu^T x$) with the risk taken ($x^T \Sigma $x).
This could be achieved by introducing a constraint on the risk, e.g. $x^T \Sigma x \leq R$, for an acceptable risk level $R$ and then maximize the return under this constraint. However, this is not a QUBO, i.e., it cannot be solved directly with VQE or QAOA. A common approach is to penalize the expected return by the weighted risk, which leads to the used objective $\mu^T x - q x^T \Sigma x$, and is a QUBO.
The actual choice $q=0.5$ in the notebook is arbitrary and just for illustration.
If you solve the problem for different $q$, you'll find different combinations of expected return and risk. E.g. for $q=0$ you consider a risk-neutral investor and the optimal solution would only maximize the expected return independent of the risk. If you increase $q$, the solution gets more and more risk-averse, ie., the return . Solving the problem for a reasonable set of $q$ leads to the so-called efficient frontier of risk and return, i.e., for every risk level, you'll get the maximum expected return that can be achieved.
In other words, $q$ is an implicit way to control the risk taken in the optimal solution of the resulting optimization problem. In practice, you are usually not interested in $q$ but in the risk and return, thus, you would have to do, e.g., a binary search over $q$ until you find a solution that does not exceed the acceptable level of risk $R$. You'd like to get as close to $R$ as possible while not exceeding it, since this should increase the expected return of the resulting portfolio.
A more general discussion of the portfolio optimization problem can be found here:
https://en.wikipedia.org/wiki/Modern_portfolio_theory