本文整理汇总了C#中ConstructGen.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructGen.ToArray方法的具体用法?C# ConstructGen.ToArray怎么用?C# ConstructGen.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstructGen
的用法示例。
在下文中一共展示了ConstructGen.ToArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnCombinePnl_Click
private void btnCombinePnl_Click(object sender, EventArgs e)
{
var all = spreadWeightGeneratorCollectionGrid1.ListOfGenerators;
if (all.Count() == 0) return;
ConstructGen<double> con = new ConstructGen<double>(all.Count());
con.ColumnHeadings = new string[con.ArrayLength];
for (int i = 0; i < con.ArrayLength; ++i)
{
var item = all.ElementAt(i);
con.ColumnHeadings[i] = item.ToString();
con.SetColumnValues(i, item.GetSimplePnl());
}
if (con.NeedsToSortKeys())
con.SortKeys();
var eval = new ReturnsEval.DataSeriesEvaluator("Combined", ReturnsEval.DataSeriesType.Returns);
eval.AddInnerSeries(con.Dates.ToArray(), con.ToArray(), con.ColumnHeadings);
eval.Display("Combined");
}
示例2: doPnl
protected override ReturnsEval.DataSeriesEvaluator doPnl(TraderArgs args_, ConstructGen<double> wts_)
{
var priceReturns =
args_.AllProductPrices(fillInGapsWithPrevious_: true)
.ToReturns(args_.Products.Select(x => x.Convention).ToArray());
var stratReturns = new ConstructGen<double>(priceReturns.ColumnHeadings);
double[] appliedWeights = null;
for (int i = 0; i < priceReturns.Dates.Count; ++i)
{
var date = priceReturns.Dates[i];
var priceReturnsArr = priceReturns.GetValues(date);
if (appliedWeights != null)
{
for (int j = 0; j < priceReturnsArr.Length; ++j)
stratReturns.SetValue(date, j, appliedWeights[j]*priceReturnsArr[j]);
}
if (wts_.Dates.Contains(date))
{
appliedWeights = wts_.GetValues(date);
}
}
var eval = new ReturnsEval.DataSeriesEvaluator("Gen pnl from weights", ReturnsEval.DataSeriesType.Returns);
eval.AddInnerSeries(stratReturns.Dates.ToArray(), stratReturns.ToArray(), stratReturns.ColumnHeadings);
return eval;
}
示例3: ShowPortfolioPnlProgression
public void ShowPortfolioPnlProgression()
{
var pnl = new ConstructGen<double>(Positions.Select(x=>x.Security).ToArray());
var flp = new System.Windows.Forms.FlowLayoutPanel();
var listOfInfraBoxes = new List<Infragistics.Win.Misc.UltraGroupBox>();
for (int i = 0; i < pnl.ArrayLength; ++i)
{
var posPnl = Positions[i].GeneratePnlSinceFix();
for (int d = 0; d < posPnl.Length; ++d)
{
pnl.SetValue(posPnl.Dates[d], i, posPnl.Data[d].Close);
}
{
Infragistics.Win.Misc.UltraGroupBox box = new Infragistics.Win.Misc.UltraGroupBox();
box.Text = string.Format("{0} {1}", Positions[i].Security, Positions[i].Pnl.ToString("###0.0#;(###0.0#);-"));
box.Tag = Positions[i].Pnl;
box.Size = new System.Drawing.Size(250, 250);
var chart = new SI.Controls.BarDataPointChart();
chart.SetYAxisFormat("##0.0#");
chart.Dock = System.Windows.Forms.DockStyle.Fill;
chart.Create(posPnl);
box.Controls.Add(chart);
listOfInfraBoxes.Add(box);
}
}
Infragistics.Win.Misc.UltraGroupBox[] boxArr = listOfInfraBoxes.OrderByDescending(x => (double)x.Tag).ToArray();
{
double max = 0d;
foreach (Infragistics.Win.Misc.UltraGroupBox box in boxArr)
{
max = Math.Max(max, ((SI.Controls.BarDataPointChart)box.Controls[0]).YAxisAbsoluteMax);
}
foreach (Infragistics.Win.Misc.UltraGroupBox box in boxArr)
{
((SI.Controls.BarDataPointChart)box.Controls[0]).SetMaxMinYAxisRange(max);
}
}
foreach (Infragistics.Win.Misc.UltraGroupBox box in boxArr)
{
flp.Controls.Add(box);
}
pnl.SortKeys();
for (int i = 0; i < pnl.ArrayLength; ++i)
{
DatedDataCollectionGen<double> col = pnl.GetColumnValuesAsDDC(i);
double last = col.Data[0];
for (int j = 1; j < col.Length; ++j)
{
double val = col.Data[j];
if (val == 0d)
{
if (last != 0d)
{
pnl.SetValue(col.Dates[j], i, last);
}
}
else
last = val;
}
}
DatedDataCollectionGen<double> total = pnl.SumRows();
KeyValuePair<string, System.Windows.Forms.Control>[] cons = new KeyValuePair<string, System.Windows.Forms.Control>[3];
var stack = new Controls.SimpleStackedColumnChart();
stack.Create<string, string>(
pnl.Dates.Select(x => x.ToString("HH:mm")).ToArray(),
Positions.Select(x => x.Security).ToArray(),
pnl.ToArray());
cons[0] = new KeyValuePair<string, System.Windows.Forms.Control>("position attributed", stack);
//stack.DisplayInShowForm(string.Format("{0} pnl progression, position attributed", this.Name));
var lcdd = new SI.Controls.LineChartDataDisplay();
lcdd.AddSeries(total.Dates, total.Data, Name, 40, "#0.0#");
lcdd.SetXAxisFormat("HH:mm");
//lcdd.DisplayInShowForm(string.Format("{0} total pnl progression", m_p.DisplayName));
cons[1] = new KeyValuePair<string, Control>("total", lcdd);
cons[2] = new KeyValuePair<string, Control>("comp", flp);
cons.DisplayInShowForm(string.Format("{0} pnl progression", Name));
//.........这里部分代码省略.........
示例4: Test
//.........这里部分代码省略.........
// false)),
new SpreadWeightGenerator(
new WeightGeneratorArgs()
{
Lookback = lookback,
WeightGenerationType = genType,
MinWindowLength = 60,
ZScoreThreshold = 1.3d
},
new SpreadDefinition(
new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U),
new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z),
false)),
//new SpreadWeightGenerator(
// new WeightGeneratorArgs()
// {
// Lookback = lookback,
// WeightGenerationType = genType,
// MinWindowLength = 90,
// ZScoreThreshold = 0.8d
// },
// new SpreadDefinition(
// new MonthYearOffset(ComIDs.Corn, 0, MonthCode.U),
// new MonthYearOffset(ComIDs.Corn, 0, MonthCode.Z),
// false)),
new SpreadWeightGenerator(
new WeightGeneratorArgs()
{
Lookback = lookback,
WeightGenerationType = genType,
MinWindowLength = 40,
ZScoreThreshold = 1.5d
},
new SpreadDefinition(
new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U),
new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z),
false)),
//new SpreadWeightGenerator(
// new WeightGeneratorArgs()
// {
// Lookback = lookback,
// WeightGenerationType = genType,
// MinWindowLength = 50,
// ZScoreThreshold = 1.3d
// },
// new SpreadDefinition(
// new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U),
// new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z),
// false)),
//new SpreadWeightGenerator(
// new WeightGeneratorArgs()
// {
// Lookback = lookback,
// WeightGenerationType = genType,
// MinWindowLength = 70,
// ZScoreThreshold = 1.1d
// },
// new SpreadDefinition(
// new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.U),
// new MonthYearOffset(ComIDs.Wheat, 0, MonthCode.Z),
// false)),
new SpreadWeightGenerator(
new WeightGeneratorArgs()
{
Lookback = lookback,
WeightGenerationType = genType,
MinWindowLength = 50,
ZScoreThreshold = 1.6d
},
new SpreadDefinition(
new MonthYearOffset(ComIDs.RBOB, 0, MonthCode.J),
new MonthYearOffset(ComIDs.RBOB, 0, MonthCode.U),
false)),
};
var comb = new SpreadWeightGeneratorCombiner(arr) {NumDaysForCovariance = 42, TargetVol = 0.06};
comb.Go();
{
var combinedPnl = new ConstructGen<double>(arr.Length);
combinedPnl.ColumnHeadings =
arr.Select(x => string.Format("{0} / {1} / {2}", x.Spread, x.Args.MinWindowLength, x.Args.ZScoreThreshold))
.ToArray();
for (int i = 0; i < arr.Length; ++i)
combinedPnl.SetColumnValues(i, arr[i].GetCombinedPnl());
if (combinedPnl.NeedsToSortKeys())
combinedPnl.SortKeys();
var eval = new ReturnsEval.DataSeriesEvaluator("Combined", ReturnsEval.DataSeriesType.Returns);
eval.AddInnerSeries(combinedPnl.Dates.ToArray(), combinedPnl.ToArray(), combinedPnl.ColumnHeadings);
eval.Display("Combined");
combinedPnl.SumRows().ToCumulative().DisplayLineChart("combined pnl of scaled weights");
}
}
示例5: EquityCTAEnviron
public static void EquityCTAEnviron()
{
//var copperIndex = Singleton<ComIDs>.Instance.First(x => x.Name.Equals("Copper")).ArrayIndex;
//var index =
// Singleton<ComIndexPrices>.Instance.GetData(DataConstants.DATA_START, DateTime.Today)
// .GetColumnValuesAsDDC(copperIndex);
//var index = EquityIndexOfSorts();
//var countries = new[] { "Germany", "US" };
//var instruments =
// Singleton<DBFut_Chains>.Instance.Where(
// x => x.AssetClass.Equals("Fixed Income") && countries.Any(y => y.Equals(x.Country))).ToArray();
var instruments=
Singleton<DBFut_Chains>.Instance.Where(
x => x.AssetClass.Equals("Equities")).ToArray();
foreach (var v in instruments)
{
var px = Singleton<DBFut_ChainGenericCache>.Instance.GetGenericSeries(v);
showCombinedStdevFromMean(px, v.BbgTicker, new[] {21, 42, 63, 89, 100, 126, 150, 189, 252, 512});
}
return;
//var instruments = Singleton<DBFut_Chains>.Instance.Where(x => x.AssetClass.Equals("Equities")).ToArray();
var con = new ConstructGen<double>(instruments.Select(x => x.BbgTicker).ToArray());
for(int i=0;i<instruments.Length;++i)
{
var index = Singleton<DBFut_ChainGenericCache>.Instance.GetGenericSeries(instruments[i]);
if (index == null || index.Length == 0) continue;
var prop = getMADiffPercentiles(index, new PercDiffArgs[]
{
//new PercDiffArgs() {MA1 = 21, MA2 = 42, PercWindow = 126},
//new PercDiffArgs() {MA1 = 21, MA2 = 63, PercWindow = 126},
//new PercDiffArgs() {MA1 = 21, MA2 = 89, PercWindow = 126},
new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 126},
new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 126},
new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 126},
new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 126},
new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 126},
new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 126},
//new PercDiffArgs() {MA1 = 21, MA2 = 42, PercWindow = 252},
//new PercDiffArgs() {MA1 = 21, MA2 = 63, PercWindow = 252},
//new PercDiffArgs() {MA1 = 21, MA2 = 89, PercWindow = 252},
new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 252},
new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 252},
new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 252},
new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 252},
new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 252},
new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 252},
new PercDiffArgs() {MA1 = 42, MA2 = 89, PercWindow = 504},
new PercDiffArgs() {MA1 = 42, MA2 = 126, PercWindow = 504},
new PercDiffArgs() {MA1 = 63, MA2 = 126, PercWindow = 504},
new PercDiffArgs() {MA1 = 89, MA2 = 180, PercWindow = 504},
new PercDiffArgs() {MA1 = 89, MA2 = 252, PercWindow = 504},
new PercDiffArgs() {MA1 = 126, MA2 = 252, PercWindow = 504},
});
//var c = new SI.Controls.LineChartDataDisplay();
//c.AddSeries(index, "index", 40, "##0.0#");
//c.AddSeries(dates_: prop.Dates,
// values_: prop.Data,
// desc_: "prop",
// yAxisExtent_: 40,
// yLabelFormat_: "##0.0#",
// color_: System.Drawing.Color.Orange,
// yAxisLeft_: false);
//c.DisplayInShowForm("blah");
con.SetColumnValues(i, index.ToReturns().MultiplyBy(prop));
}
con.SortKeys();
var eval = new ReturnsEval.DataSeriesEvaluator("combined", DataSeriesType.Returns);
eval.AddInnerSeries(con.Dates.ToArray(), con.ToArray(), con.ColumnHeadings);
eval.Display();
}