/* The example python portfolio.py portfolio reads in data and solves the portfolio models. */ public static void Main(string[] argv) { string name = argv[0]; MarkowitzData d = new MarkowitzData(name); { Console.WriteLine("\n-------------------------------------------------------------------"); Console.WriteLine("Basic Markowitz portfolio optimization"); Console.WriteLine("---------------------------------------------------------------------\n"); for(int i = 0; i < d.gammas.Length; ++i) { double res = BasicMarkowitz(d.n, d.mu, d.GT, d.x0, d.w, d.gammas[i]); Console.WriteLine("Expected return: {0,-12:f4} Std. deviation: {1,-12:f4} ", res,d.gammas[i]); } } { // Some predefined alphas are chosen double[] alphas = { 0.0, 0.01, 0.1, 0.25, 0.30, 0.35, 0.4, 0.45, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 10.0 }; int niter = alphas.Length; double[] frontier_mux = new double[niter]; double[] frontier_s = new double[niter]; EfficientFrontier(d.n,d.mu,d.GT,d.x0,d.w,alphas, frontier_mux, frontier_s); Console.WriteLine("\n-------------------------------------------------------------------------"); Console.WriteLine("Efficient frontier\n") ; Console.WriteLine("------------------------------------------------------------------------\n"); Console.WriteLine("{0,-12} {1,-12} {2,-12}", "alpha","return","risk") ; for (int i = 0; i < frontier_mux.Length; ++i) Console.WriteLine("{0,-12:f4} {0,-12:e4} {0,-12:e4}\n", alphas[i],frontier_mux[i],frontier_s[i]); } { // Somewhat arbirtrary choice of m double[] m = new double[d.n]; for (int i = 0; i < d.n; ++i) m[i] = 1.0e-2; double[] x = new double[d.n]; double[] t = new double[d.n]; MarkowitzWithMarketImpact(d.n,d.mu,d.GT,d.x0,d.w,d.gammas[0],m, x,t); Console.WriteLine("\n-----------------------------------------------------------------------"); Console.WriteLine("Markowitz portfolio optimization with market impact cost\n"); Console.WriteLine("------------------------------------------------------------------------\n"); Console.WriteLine("Expected return: {0:e4} Std. deviation: {1:e4} Market impact cost: {2:e4}\n", dot(d.mu,x), d.gammas[0], dot(m,t)); } { double[] f = new double[d.n]; for (var i = 0; i < d.n; ++i) f[i] = 0.01; double[] g = new double[d.n]; for (var i = 0; i < d.n; ++i) g[i] = 0.001; MarkowitzWithTransactionsCost(d.n,d.mu,d.GT,d.x0,d.w,d.gammas[0],f,g); } }
/* * The example * * python portfolio.py portfolio * * reads in data and solves the portfolio models. */ public static void Main(string[] argv) { string name = argv[0]; MarkowitzData d = new MarkowitzData(name); { Console.WriteLine("\n-------------------------------------------------------------------"); Console.WriteLine("Basic Markowitz portfolio optimization"); Console.WriteLine("---------------------------------------------------------------------\n"); for (int i = 0; i < d.gammas.Length; ++i) { double res = BasicMarkowitz(d.n, d.mu, d.GT, d.x0, d.w, d.gammas[i]); Console.WriteLine("Expected return: {0,-12:f4} Std. deviation: {1,-12:f4} ", res, d.gammas[i]); } } { // Some predefined alphas are chosen double[] alphas = { 0.0, 0.01, 0.1, 0.25, 0.30, 0.35, 0.4, 0.45, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 10.0 }; int niter = alphas.Length; double[] frontier_mux = new double[niter]; double[] frontier_s = new double[niter]; EfficientFrontier(d.n, d.mu, d.GT, d.x0, d.w, alphas, frontier_mux, frontier_s); Console.WriteLine("\n-------------------------------------------------------------------------"); Console.WriteLine("Efficient frontier\n"); Console.WriteLine("------------------------------------------------------------------------\n"); Console.WriteLine("{0,-12} {1,-12} {2,-12}", "alpha", "return", "risk"); for (int i = 0; i < frontier_mux.Length; ++i) { Console.WriteLine("{0,-12:f4} {0,-12:e4} {0,-12:e4}\n", alphas[i], frontier_mux[i], frontier_s[i]); } } { // Somewhat arbirtrary choice of m double[] m = new double[d.n]; for (int i = 0; i < d.n; ++i) { m[i] = 1.0e-2; } double[] x = new double[d.n]; double[] t = new double[d.n]; MarkowitzWithMarketImpact(d.n, d.mu, d.GT, d.x0, d.w, d.gammas[0], m, x, t); Console.WriteLine("\n-----------------------------------------------------------------------"); Console.WriteLine("Markowitz portfolio optimization with market impact cost\n"); Console.WriteLine("------------------------------------------------------------------------\n"); Console.WriteLine("Expected return: {0:e4} Std. deviation: {1:e4} Market impact cost: {2:e4}\n", dot(d.mu, x), d.gammas[0], dot(m, t)); } { double[] f = new double[d.n]; for (var i = 0; i < d.n; ++i) { f[i] = 0.01; } double[] g = new double[d.n]; for (var i = 0; i < d.n; ++i) { g[i] = 0.001; } MarkowitzWithTransactionsCost(d.n, d.mu, d.GT, d.x0, d.w, d.gammas[0], f, g); } }