本文整理汇总了C#中ConstructGen.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructGen.SetValue方法的具体用法?C# ConstructGen.SetValue怎么用?C# ConstructGen.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstructGen
的用法示例。
在下文中一共展示了ConstructGen.SetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoWeights
public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
{
for (int i = 0; i < products_.Count; ++i)
{
double avg = 0;
for (int j = 0; j < signalResults_.Dates.Count; ++j)
{
if(j<WindowLength)
{
wts_.SetValue(signalResults_.Dates[j],i,0);
continue;
}
// if the product is not valid on this date then the weight is zero.
if (double.IsNaN(filters_.GetValue(signalResults_.Dates[j],i)))
{
wts_.SetValue(signalResults_.Dates[j], i, 0.0);
}
else
{
for (int y = 0; y < WindowLength; ++y)
avg += signalResults_.GetValue(signalResults_.Dates[j - y], i);
avg /= WindowLength;
double val = signalResults_.GetValue(signalResults_.Dates[j], i) / avg;
wts_.MultValue(signalResults_.Dates[j], i, val, false);
}
}
}
}
示例2: getConstructOfInvoiceSpreads
private ConstructGen<double> getConstructOfInvoiceSpreads()
{
var con = new ConstructGen<double>(Configs.Length);
for (int i = 0; i < con.ArrayLength; ++i)
{
for (int j = 0; j < Collections[i].Lines.Count; ++j)
{
var date = Collections[i].Lines[j].Date;
var val = Collections[i].Lines[j].InvoiceSpread;
con.SetValue(date, i, val ?? double.PositiveInfinity);
}
}
con.SortKeys();
// feed forward missing values
double[] before = null;
foreach (var date in con.Dates)
{
var today = con.GetValues(date);
if (before != null)
{
for(int i=0;i<today.Length;++i)
if (double.IsInfinity(today[i]))
today[i] = before[i];
}
before = today;
}
return con;
}
示例3: GetSmoothCurvesColumnsAreCurvePoints
public static ConstructGen<double> GetSmoothCurvesColumnsAreCurvePoints(DateTime valueDate_, uint curveCount_, BondMarket market_, BondField field_, SI.Data.BondCurves curve_, string close_ = "MLP", string source_ = "MLP")
{
DateTime date = valueDate_;
var points = new List<decimal>();
for (decimal d = 1M; d < 30M; d = d + 0.25M)
points.Add(d);
var con = new ConstructGen<double>(points.Select(x => x.ToString()).ToArray());
for (int i = 0; i < curveCount_; ++i)
{
var curve = GetSmoothCurve(date, market_, field_, curve_, close_, source_);
if (curve == null) continue;
foreach (var node in curve.GetNodes())
{
int index = points.IndexOf(node);
if (index == -1) continue;
var point = curve.GetValue(node);
if(point.HasValue)
con.SetValue(date, index, point.Value);
}
date = MyCalendar.PrevWeekDay(date);
}
con.SortKeys();
return con;
}
示例4: 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;
}
示例5: DoWeights
public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
{
foreach (DateTime date in signalResults_.Dates)
{
for (int i = 0; i < signalResults_.ArrayLength; ++i)
{
double val = signalResults_.GetValue(date, i);
if (val < 0 && GoShort == false)
wts_.SetValue(date, i, 0.0);
else if (val > 0 && GoLong == false)
wts_.SetValue(date, i, 0.0);
else
wts_.MultValue(date, i, val, false);
}
}
}
示例6: Create
public void Create(IList<DataSeriesEvaluator> evals_)
{
m_evals = evals_;
m_pnls = new ConstructGen<double>(evals_.Count);
for (int evalIndex = 0; evalIndex < evals_.Count; ++evalIndex)
for (int i = 0; i < m_evals[evalIndex].Daily.Data.Length; ++i)
m_pnls.SetValue(m_evals[evalIndex].Daily.Dates[i], evalIndex, m_evals[evalIndex].Daily.Data[i]);
m_pnls.SortKeys();
m_customStartDate = DateTime.Today.Month == 1
? new DateTime(DateTime.Today.Year - 1, 1, 1)
: new DateTime(DateTime.Today.Year, 1, 1);
//AsOfDate = MyCalendar.PrevWeekDay(DateTime.Today);
AsOfDate = m_pnls.LastDate;
}
示例7: GoMulti
public static void GoMulti()
{
var data = DataRetriever.GetData(indexStart_: "ES", suffix_: "Index", contractIndex_: 1);
var listOfEvals = new List<ReturnsEval.DataSeriesEvaluator>();
foreach (var firstWindow in new[] {5, 10, 15, 20, 25, 50, })
{
var indic = new SI.Research.Technicals.MACross(firstWindow, firstWindow * 2);
var signals = indic.GenerateWeightSeries(data, null);
for (int i = 0; i < signals.Length; ++i)
signals.Data[i] = signals.Data[i] < 0d ? -1d : 1d;
signals = CollapseToChanges(signals);
if (false)
{
var con = new ConstructGen<double>(new[] { "Signal", "CleanPrice" });
con.SetColumnValues(0, signals);
foreach (var date in con.Dates)
con.SetValue(date, 1, data.ValueOnExactDate(date));
con.DisplayInGrid("changes with price levels");
}
//signals.DisplayInGrid("changes");
var pnl = GeneratePnl(data, signals);
var eval = new ReturnsEval.DataSeriesEvaluator(pnl.Dates, pnl.Data, string.Format("ES_{0}", firstWindow), ReturnsEval.DataSeriesType.Returns);
listOfEvals.Add(eval);
}
listOfEvals.Display("blah");
}
示例8: DoWeights
public override void DoWeights(ConstructGen<double> signalResults_, ConstructGen<double> fullSignalResults_, ConstructGen<double> wts_, List<ProductBase> products_, ConstructGen<double> filters_)
{
foreach (DateTime date in signalResults_.Dates)
for (int i = 0; i < products_.Count; ++i)
{
double v = signalResults_.GetValue(date, i);
v = (v == 0) ? 0.0 : (v < 0) ? -1.0 : 1.0;
v = (m_reverse) ? -v : v;
if (m_scaleSignDifferently && v != 0)
{
v = (v < 0) ? (v * m_negScale) : (v * m_posScale);
wts_.MultValue(date, i, v, v < 0);
}
else
{
wts_.SetValue(date, i, v);
//wts_.SetToSign(date, i, v);
}
}
}
示例9: getData
protected override ConstructGen<double> getData(DateTime startDate_, DateTime endDate_, bool forceRefresh_)
{
ConstructGen<double> con = null;
var ds = Singleton<ConnMngr>.Instance.Execute(queryDBName, getQueryString(startDate_, endDate_));
if (ConnMngr.HasResult(ds))
{
con = new ConstructGen<double>(Singleton<FXIDs>.Instance.ColumnHeadings);
foreach (DataRow row in ds.Tables[0].Rows)
{
var ccyID = Convert.ToInt32(row[idColumn]);
var value = Convert.ToDouble(row[valueColumn]);
var date = Convert.ToDateTime(row[dateColumn]);
{
var hour = (int)row["hour"];
var minute = (int)row["minute"];
date = date.AddHours(hour).AddMinutes(minute);
}
Currency ccy = Singleton<FXIDs>.Instance.GetFromId(ccyID);
con.SetValue(date, ccy.ArrayIndex, value);
}
}
return con;
}
示例10: Go
//.........这里部分代码省略.........
// then we displayed in a line chart:
euroSeries.DisplayLineChart("EUR");
// what else could we do with this euro series?
// convert to returns:
var euroReturns = euroSeries.ToReturns();
var cumulative = euroReturns.ToCumulative();
var stdFromMean = euroSeries.ToStdevFromMean(meanWindowLength_: 21, sdWindowLength_: 126);
// I've also done a load of stuff to transform this series, take a look at HelperMethods.
// often, we don't deal with individual price series, though we need inline data
// for this I have made something called ConstructGen<T>, where again, T is normally a double
var firstConstruct = new ConstructGen<double>(9);
// this has made a construct that is set up to store dated values for 9 different variables
// it's good to set the columnHeadings on the construct so you know what they refer to
var headings = new string[] {"AUD", "CAD", "CHF", "EUR", "GBP", "JPY", "NOK", "NZD", "SEK"};
firstConstruct.ColumnHeadings = headings;
// (I'll show you how to do this more easily in a bit...
// let's look at what we can do with construct and how we use it
DateTime conDate = new DateTime(2014, 1, 1);
firstConstruct.SetValue(conDate, 0, 100.2);
// this has set the value for the first column (AUD) on the given Date
// we get it out by:
var v1 = firstConstruct.GetValue(conDate, 0);
// set the second value:
firstConstruct.SetValue(conDate, 1, 45.6);
// this has set the value for the given date for 'CAD'
// we could set all values at once using SetValues rather than SetValue
firstConstruct.SetValues(conDate, new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9});
// and we could get them out using:
double[] allValuesOnDate = firstConstruct.GetValues(conDate);
// there are lots of methods on Construct<T> to make our life easier when dealing with data
// we can fill it up randomly using the SetValues, and then just call SortKeys() to ensure teh dates are in order
firstConstruct.SortKeys();
// this means that we will be iterate over the dates in order when we go through it
// e.g.
foreach (DateTime date in firstConstruct.Dates)
示例11: handleclick
protected override void handleclick(EventArgs e_)
{
try
{
DatedDataCollectionGen<double> hist = null;
hist = m_signal.GetSignalGridProvider().GetHistoryForCcyPair(m_ccy1, m_ccy2);
if (hist == null) hist = m_signal.GetSignalGridProvider().GetHistoryForCcyPair(m_ccy2, m_ccy1, -1d);
ConstructGen<double> con = new ConstructGen<double>(Singleton<FXIDs>.Instance.ColumnHeadings);
for (int i = 0; i < hist.Dates.Length; ++i)
{
con.SetValue(hist.Dates[i], m_ccy1.ArrayIndex, hist.Data[i]);
con.SetValue(hist.Dates[i], m_ccy2.ArrayIndex, -hist.Data[i]);
}
var rets = ReturnsFromFXWeights.DoIt_DailyWeights(dailyWts_: con);
var eval = new ReturnsEval.DataSeriesEvaluator(m_signal.Name, ReturnsEval.DataSeriesType.Returns);
eval.AddInnerSeries(rets.CombinedPnl.Dates.ToArray(), rets.CombinedPnl.ToArray(), rets.CombinedPnl.ColumnHeadings);
eval.Evaluate();
eval.Display(string.Format("{0}: {1}/{2} signal performance",m_signal.Name,m_ccy1,m_ccy2)).Icon = Util.BmpToIcon(Properties.Resources.money);
}
catch (Exception ex_)
{
Logger.Error(string.Format("Error generating and showing pnl for signal grid ccy pair ({0}/{1})", m_ccy1.Code, m_ccy2.Code), typeof(SignalPnlOverTime), ex_);
}
}
示例12: OnClick
protected override void OnClick(EventArgs e)
{
ConstructGen<double> shortBasket = new ConstructGen<double>(m_analyzer.SourceWts.ColumnHeadings);
ConstructGen<double> longBasket = new ConstructGen<double>(m_analyzer.SourceWts.ColumnHeadings);
foreach (DateTime date in m_analyzer.SourceWts.Dates)
{
double[] fullWts = m_analyzer.SourceWts.GetValues(date);
shortBasket.EnsureDate(date);
longBasket.EnsureDate(date);
for (int i = 0; i < fullWts.Length; ++i)
if (fullWts[i] > 0d)
longBasket.SetValue(date, i, fullWts[i]);
else if (fullWts[i] < 0d)
shortBasket.SetValue(date, i, fullWts[i]);
}
var allResult = ReturnsFromFXWeights.DoIt_DailyWeights(m_analyzer.SourceWts);
var longREsult = ReturnsFromFXWeights.DoIt_DailyWeights(longBasket);
var shortResult = ReturnsFromFXWeights.DoIt_DailyWeights(shortBasket);
List<ReturnsEval.DataSeriesEvaluator> evals = new List<ReturnsEval.DataSeriesEvaluator>();
//evals.Add(allResult.GetEvaluatorCombinedSpotAndCarry());
//evals.Last().Name = m_analyzer.Name;
//evals.Add(longREsult.GetEvaluatorCombinedSpotAndCarry());
//evals.Last().Name = "LongBasket";
//evals.Add(shortResult.GetEvaluatorCombinedSpotAndCarry());
//evals.Last().Name = "ShortBasket";
evals.Display(string.Format("{0} split into long/short baskets", m_analyzer.Name));
}
示例13: reloadTopRight
private void reloadTopRight(IDictionary<string, DataEncapsValue> list)
{
if (list.Count == 0 || m_trArgs.Locked)
return;
ConstructGen<double> conTopRight = new ConstructGen<double>(list.Count);
conTopRight.ColumnHeadings = new string[conTopRight.ArrayLength];
int i = 0;
foreach (string s in list.Keys)
{
conTopRight.ColumnHeadings[i] = s;
DatedDataCollectionGen<double> coll = list[s].Data;
double[] series = (cbTopRightCumulative.Checked) ? coll.Data.Cumulative() : coll.Data;
for (int j = 0; j < series.Length; ++j)
conTopRight.SetValue(coll.Dates[j], i, series[j]);
++i;
}
conTopRight.SortKeys();
StringBuilder titleBuilder=new StringBuilder();
foreach (string s in list.Values.Select<DataEncapsValue, string>(x => x.Name).Distinct<string>())
titleBuilder.Append(s).Append(" / ");
titleBuilder.Length -= 3;
lbl_TR_title.Text = titleBuilder.ToString();
dataCollectionDisplay1.Create(new SortedDictionary<DateTime, double[]>(conTopRight.GetInnerData()), conTopRight.ColumnHeadings);
}
示例14: TransformToCon
public static ConstructGen<double> TransformToCon(DataAroundEvent[] data_, int numberAroundEvents_, DataAroundEventField field_)
{
ConstructGen<double> ret = new ConstructGen<double>((numberAroundEvents_ * 2) + 1);
ret.ColumnHeadings = new string[ret.ArrayLength];
ret.ColumnHeadings[numberAroundEvents_] = "0";
for (int i = 1; i <= numberAroundEvents_; ++i)
{
ret.ColumnHeadings[numberAroundEvents_ - i] = (-i).ToString();
ret.ColumnHeadings[numberAroundEvents_ + i] = i.ToString();
}
var headings = new List<string>(ret.ColumnHeadings);
if(data_!=null)
foreach (var eve in data_.OrderBy(x => x.EventDate))
{
// initialise to NaN
ret.SetValues(eve.EventDate, Utils.GetArrayOfValue<double>(double.NaN, ret.ArrayLength));
var subData = eve[field_];
if(subData!=null)
foreach (var point in subData.Data)
{
if (point == null) continue;
var index = headings.IndexOf((point.Index - data_.First().Offset).ToString());
ret.SetValue(eve.EventDate, index, point.Value);
}
}
return ret;
}
示例15: 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));
//.........这里部分代码省略.........