text: You can use the matplotlib to plot this equation for several values of correlation and visualise it. The plot is shown in Figure 1.
  The best proportion to use will be the one which minimises the standard deviation. It is easy to get that value. Just add the following code:
  The function fmin in the optimize module accepts a function, std_dev in your case, as a parameter and a starting guess. Additional parameters for the std_dev function are passed using the args parameter. It then finds the optimal value. This should give you the result that you should have about 80% in first investment and 20% in the second as the safest option in case the investments are independent:
  You know that the investments are usually correlated. So, you may want to examine visually how the result varies depending upon the correlation. Add the following code to compute the optimum proportion of Investment 1 for a list of correlations and plot it:
  The result is shown in Figure 2. If both investments are perfectly correlated, then you are better with everything in Investment 1. However, if they are have a perfect negative correlation, the best option is to invest only 70% in Investment 1 and remaining in Investment 2. An example of negative correlation is the frequently heard advice: “When stock markets are booming, interest rates fall.”
  Suppose the government can spend a 100 rupees on increasing consumption and production of food. It estimates that each rupee spent on Rural Employment will increase consumption by a rupee. This increase must be matched by an increase in production. It estimates that each rupee spent on infrastructure will increase production by 2 rupees. So, you can formulate the problem as:
  You can use the scipy's linalg module to solve this problem as follows, where the four columns are c, p, r, i.