System.Collections.Generic;
3usingSystem.ComponentModel;
8usingSystem.Windows.Forms;
11usingSystem.Reflection;
12usingSystem.Windows.Forms.DataVisualization.Charting;
23 public partial class Form1: Form
28 if(Environment.GetCommandLineArgs().Length > 1)
29ws =
new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
35opt.AllModelTypes =
"conopt";
36opt.
Defines.Add(
"data",
"\""+ Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
@"..\..\..\..\Data\Markowitz.gdx") +
"\"");
46List<Tuple<double, double>> dataPoints =
newList<Tuple<double, double>>();
63Stack<Tuple<Tuple<double, double>, Tuple<double, double>>> intervals =
newStack<Tuple<Tuple<double, double>, Tuple<double, double>>>();
64intervals.Push(Tuple.Create(Tuple.Create(0.0, minRet), Tuple.Create(1.0, maxRet)));
69 while(intervals.Count > 0){
71var i = intervals.Pop();
72 doubleminL = i.Item1.Item1;
73minRet = i.Item1.Item2;
74 doublemaxL = i.Item2.Item1;
75maxRet = i.Item2.Item2;
77 doublelVal = (minL+maxL)/2;
85 if(curRet - minRet > gap)
86intervals.Push(Tuple.Create(Tuple.Create(minL, minRet), Tuple.Create(lVal, curRet)));
87 if(Math.Abs(curRet - maxRet) > gap)
88intervals.Push(Tuple.Create(Tuple.Create(lVal, curRet), Tuple.Create(maxL, maxRet)));
92dataPoints.Sort((a, b) => a.Item1.CompareTo(b.Item1));
94InitializeComponent();
95this.chart1.Series.Clear();
96Series s = this.chart1.Series.Add(
"s");
97s.ChartType = SeriesChartType.Line;
98s.MarkerStyle = MarkerStyle.Circle;
100this.chart1.ChartAreas[0].AxisX.Title =
"return";
101this.chart1.ChartAreas[0].AxisY.Title =
"variance";
102this.chart1.ChartAreas[0].AxisX.Interval = 0.1;
103this.chart1.ChartAreas[0].AxisX.Minimum = 0;
105 foreach(Tuple<double,double> p
indataPoints)
106s.Points.AddXY(p.Item1, p.Item2);
109 staticString GetModelText()
112$title Standard Markowitz Portfolio Selection Model 115 upper(s,s), lower(s,s) parts of covar matrix; 118parameter mean(s) mean of daily return 119 covar(s,s) covariance matrix of returns (upper); 121$if not set data $abort 'no include file name for data file provided' 123$load s covar upper lower mean 125variables z objective variable 132equations obj objective 134 varcon variance constraint 135 retcon return constraint; 139obj.. z =e= lambda*ret - (1-lambda)*var; 140budget.. sum(s, x(s)) =e= 1.0; 141varcon.. var =e= sum(upper(s,t), x(s)*covar(s,t)*x(t)) + 142 sum(lower(s,t), x(s)*covar(t,s)*x(t)); 143retcon.. ret =e= sum(s, mean(s)*x(s));GAMSModelInstance AddModelInstance(string modelInstanceName=null)
GAMSVariable GetVariable(string variableIdentifier)
GAMSParameter AddParameter(string identifier, int dimension, string explanatoryText="")
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
void Solve(SymbolUpdateType updateType=SymbolUpdateType.BaseCase, TextWriter output=null, GAMSModelInstanceOpt miOpt=null)
void Instantiate(string modelDefinition, params GAMSModifier[] modifiers)
Dictionary< string, string > Defines
new GAMSParameterRecord FindRecord(params string[] keys)
new GAMSParameterRecord FirstRecord()
new GAMSParameterRecord AddRecord(params string[] keys)
new GAMSVariableRecord FirstRecord()
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSCheckpoint AddCheckpoint(string checkpointName=null)
GAMSOptions AddOptions(GAMSOptions optFrom=null)
This is a small graphical program that plots the efficient frontier of Markowitz' portfolio selection...
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4