本文整理汇总了C#中ConstructGen.GetColumnValuesAsDDC方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructGen.GetColumnValuesAsDDC方法的具体用法?C# ConstructGen.GetColumnValuesAsDDC怎么用?C# ConstructGen.GetColumnValuesAsDDC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstructGen
的用法示例。
在下文中一共展示了ConstructGen.GetColumnValuesAsDDC方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeMarkSetupForChart
public static void DeMarkSetupForChart(UltraChart chart, ConstructGen<double> candleData_, bool isDateChart, int openIndex_=0, int highIndex_=1, int lowIndex_=2, int closeIndex_=3,
int setupLength_=9, int countdownLength_=13)
{
var closes = candleData_.GetColumnValuesAsDDC(closeIndex_);
var range = closes.Data.Max() - closes.Data.Min();
var cellHeight = range / 10d;
var setupStarts = Analysis.GetSetups(candleData_, openIndex_, highIndex_, lowIndex_, closeIndex_, setupLength_);
Analysis.AddCountdowns(candleData_, setupStarts, openIndex_, highIndex_, lowIndex_, closeIndex_, setupLength_, countdownLength_);
for (int i = 0; i < candleData_.Dates.Count; ++i)
{
var date = candleData_.Dates[i];
var arr = candleData_.GetValues(date);
//dt.LoadDataRow(new object[]
//{
// date,
// arr[openIndex_],
// arr[highIndex_],
// arr[lowIndex_],
// arr[closeIndex_],
// 0d
//}, true);
foreach (var mark in setupStarts)
{
addAnnotations(chart, date, mark, i, cellHeight, arr, openIndex_, highIndex_, lowIndex_, closeIndex_);
}
}
}
示例2: Create
public void Create(ConstructGen<double> candleData_, int openIndex_ = 0, int highIndex_ = 1, int lowIndex_ = 2, int closeIndex_ = 3, int setupLength_=9, int countdownLength_=13)
{
var dt = new DataTable();
dt.Rows.Clear();
dt.Columns.Clear();
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Open", typeof(double));
dt.Columns.Add("High", typeof(double));
dt.Columns.Add("Low", typeof(double));
dt.Columns.Add("Close", typeof(double));
dt.Columns.Add("Volume", typeof(double));
ultraChart1.DataSource = dt;
var closes = candleData_.GetColumnValuesAsDDC(closeIndex_);
var range = closes.Data.Max() - closes.Data.Min();
var cellHeight = range/10d;
var setupStarts = DeMarkAnalysis.GetSetups(candleData_,openIndex_,highIndex_,lowIndex_,closeIndex_,setupLength_);
DeMarkAnalysis.AddCountdowns(candleData_, setupStarts,openIndex_,highIndex_,lowIndex_,closeIndex_,setupLength_,countdownLength_);
for (int i = 0; i < candleData_.Dates.Count; ++i)
{
var date = candleData_.Dates[i];
var arr = candleData_.GetValues(date);
dt.LoadDataRow(new object[]
{
date,
arr[openIndex_],
arr[highIndex_],
arr[lowIndex_],
arr[closeIndex_],
0d
}, true);
foreach(var mark in setupStarts)
{
addAnnotations(date, mark, i, cellHeight, arr,openIndex_,highIndex_,lowIndex_,closeIndex_);
}
}
EstablishDefaultTooltip(hash =>
{
int rowNumber = (int) hash["DATA_ROW"];
return string.Format("{0} Open: {1}, High: {2}, Low: {3}, Close: {4}",
((DateTime) dt.Rows[rowNumber]["Date"]).ToString("dd-MMM-yyyy"),
((double) dt.Rows[rowNumber]["Open"]).ToString(CultureInfo.InvariantCulture),
((double)dt.Rows[rowNumber]["High"]).ToString(CultureInfo.InvariantCulture),
((double)dt.Rows[rowNumber]["Low"]).ToString(CultureInfo.InvariantCulture),
((double)dt.Rows[rowNumber]["Close"]).ToString(CultureInfo.InvariantCulture)
).Replace(",", System.Environment.NewLine);
});
}
示例3: ComputeMarketRatio
public static MarketViewItem ComputeMarketRatio(InstrumentPriceItem inputItem, ConstructGen<double> histData)
{
// get historical high low
double high=0;
double low=0;
if (histData != null)
{
high = histData.GetColumnValuesAsDDC(1).Data.Max();
low = histData.GetColumnValuesAsDDC(2).Data.Min();
}
return new MarketViewItem
{
Instrument = inputItem.Instrument,
LivePrice = inputItem.Close,
High = high,
Low = low,
Ratio = histData == null ? 0 : (inputItem.IsLong ? Math.Round((inputItem.Close - low) / (high - low), 3) :
Math.Round((inputItem.Close - high) / (low - high), 3)),
};
}
示例4: Go
//.........这里部分代码省略.........
// 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)
{
var datesVAlues = firstConstruct.GetValues(date);
// here we could process them...
}
// there are methods on ConstructGen<T> to make it easy to see what's in it. e.g.
firstConstruct.DisplayInGrid("Grid of construct values");
firstConstruct.DisplayInDataCollectionDisplay("Display each column as a line in a chart");
// there is also a useful method to get the column of values as a DatedDataCollection<T>
DatedDataCollectionGen<double> firstColumn = firstConstruct.GetColumnValuesAsDDC(0);
// this is an expensive operation FYI, so you wouldn't use this iterating over the dates within the ConstructGen<T> , but it is useful
// ok, now, as we have a set universe of ccys, in the way I extract data from the database (prices / weights / carry / etc) I tend to pull
// out in a standard way, making a ConstructGen<double> with a column for every currency in the universe
// so, for example, if I wanted the spots from the database from 2013 onwards, I would call this
SI.Data.FXSpots spotsProvider = new FXSpots();
ConstructGen<double> spots = spotsProvider.GetData(new DateTime(2013, 1, 1), DateTime.Today);
// this returns me a ConstructGen<double> with 27 columns, with each row being a date
// I can then use the spots values as I wish
// similarly
SI.Data.FXForwards1Wk fwdProvider = new FXForwards1Wk();
ConstructGen<double> fwds = fwdProvider.GetData(new DateTime(2013, 1, 1), DateTime.Today);
// within these classes, the data is cached, so that I don't call the database again if I don't need to
// so if I call for the second time:
var spots2 = spotsProvider.GetData(new DateTime(2013, 1, 1), DateTime.Today);
// ... this won't have hit the database again, but will get from the cached data
// but you'll notice that i have to have a reference to spotsProvider to benefit from the cached data.
// if I was to make the same request from another point in my code, I would have to create a new FXSpots() instance and then call the method on it to get the data
// it can be useful in this instance to make use of what's known as the 'Singleton' pattern.
// This basically provides a means of referring to the same instance every time, in this case so that we make use of cached data
// I have a Singleton<T> wrapper that wraps up a single instance of T so that I know I'm calling methods on the same instance every time
// so I would usually get spots from the database wrapping FXSpots in this. like:
spots = Singleton<FXSpots>.Instance.GetData(new DateTime(2013, 1, 1), DateTime.Today);
// now I could call the method on Singleton<FXSpots>.Instance from anywhere in my code and I would benefit from the caching
// I do tend to use most of the classes that retrive from the database Within SI.Data wrapped in a Singleton
// another example is the class that pulls information about signals
var signals = Singleton<Signals>.Instance;
// this is just a list of SI.Data.Signal classes
}
示例5: buildData
private void buildData()
{
var pxDates = new List<DateTime>();
var pxValues = new List<double>();
for (int y = 2003;y <= DateTime.Now.Year; ++y)
{
// find the contracts
var conLon = Long.Underlying.Futures.Where(x => x.Expiry.Year-Long.YearOffset == y && x.Expiry.Month == (int)Long.Month).FirstOrDefault();
var conShort = Short.Underlying.Futures.Where(x => x.Expiry.Year-Short.YearOffset == y && x.Expiry.Month == (int)Short.Month).FirstOrDefault();
if (conLon != null && conShort != null)
{
m_contractsLongShort.Add(y, new KeyValuePair<ComFutureMeta, ComFutureMeta>(conLon, conShort));
// last trade of this pair is the earliest lastTrade date of the two
var lastTrade = (conLon.LastTrade < conShort.LastTrade) ? conLon.LastLastDate : conShort.LastLastDate;
var dataStart = lastTrade.AddYears(-1);
if (MyCalendar.IsWeekend(dataStart)) dataStart = MyCalendar.NextWeekDay(dataStart);
ConstructGen<double> con = new ConstructGen<double>(new string[] { conLon.Ticker, conShort.Ticker, "Diff", "Normalized" });
con.SetColumnValues((int)dataColumns.Long, conLon.Prices.GetSubValues(dataStart, lastTrade));
con.SetColumnValues((int)dataColumns.Short, conShort.Prices.GetSubValues(dataStart, lastTrade));
if (con.NeedsToSortKeys()) con.SortKeys();
if (con.Dates.Count == 0)
continue;
// calculate differences
foreach (DateTime date in con.Keys)
{
double[] d = con.GetValues(date);
// if we have a value for both contracts on this day
if (d[(int)dataColumns.Long] != 0d && d[(int)dataColumns.Short] != 0d)
{
// save down the difference
d[(int)dataColumns.Diff] = d[(int)dataColumns.Long] - d[(int)dataColumns.Short];
if (date.Year == y)
{
pxDates.Add(date);
pxValues.Add(d[2]);
}
}
}
// normalize differences
{
DatedDataCollectionGen<double> diffs = con.GetColumnValuesAsDDC((int)dataColumns.Diff);
if (diffs==null || diffs.Length == 0)
continue;
var min = diffs.Data.Min();
var max = diffs.Data.Max();
var normArr = new double[diffs.Length];
for (int i = 0; i < normArr.Length; ++i)
normArr[i] = (diffs.Data[i] - min) / (max - min);
con.SetColumnValues((int)dataColumns.NormalizedDiff, new DatedDataCollectionGen<double>(diffs.Dates, normArr));
}
m_yearToPxs.Add(y, con);
}
}
m_hasBuiltData = true;
}
示例6: 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));
//.........这里部分代码省略.........
示例7: AddCandleSeries
public void AddCandleSeries(ConstructGen<double> values, string description)
{
SI.Controls.LookFeel.ProcessControl(lineChartDataDisplay1);
lineChartDataDisplay1.AddCandleSeries(values, description, 40, "###0.000");
//lineChartDataDisplay1.AddDeMarkSeries(values);
Rescale(values.GetColumnValuesAsDDC(1));
}
示例8: GetFlow
public static ConstructGen<double> GetFlow(ConstructGen<double> wts_)
{
var ret = new ConstructGen<double>(wts_.ColumnHeadings);
for (int i = 0; i < wts_.ArrayLength; ++i)
{
ret.SetColumnValues(i, wts_.GetColumnValuesAsDDC(i).ToDifferences().ToAbs());
}
return ret;
}
示例9: GenerateHoldingPeriods
public static List<HoldingPeriod> GenerateHoldingPeriods(ConstructGen<double> historicalWeights_, double? trimDistributionsBy_=null)
{
var ret = new List<HoldingPeriod>();
for (int colIndex = 0; colIndex < historicalWeights_.ArrayLength; ++colIndex)
{
var colVals = historicalWeights_.GetColumnValuesAsDDC(colIndex);
if (colVals.Data.SumAbs() == 0d)
continue;
Dictionary<WtState, List<double>> dict = new Dictionary<WtState, List<double>>();
WtState currentState = WtState.None;
DateTime stateStart = DateTime.MinValue;
for (int i = 0; i < colVals.Length; ++i)
{
var wt = colVals.Data[i];
WtState newState = (wt > 0d) ? WtState.Long : (wt < 0d) ? WtState.Short : WtState.Flat;
if (currentState == WtState.None)
{
stateStart = colVals.Dates[i];
currentState = newState;
}
else if (newState == currentState)
{
// do nothing
}
else // we have a new state
{
var ts = colVals.Dates[i] - stateStart;
if (!dict.ContainsKey(currentState)) dict[currentState] = new List<double>();
dict[currentState].Add(MyCalendar.NumBusinessDaysBetween(stateStart,colVals.Dates[i]));
currentState = newState;
stateStart = colVals.Dates[i];
}
}
// commit the last values
{
}
var hp = new HoldingPeriod()
{
Ccy=historicalWeights_.ColumnHeadings[colIndex],
State=currentState,
Held=MyCalendar.NumBusinessDaysBetween(stateStart,DateTime.Today),
Wt=colVals.Data.Last()
};
foreach (var key in dict.Keys)
{
if (trimDistributionsBy_.HasValue && trimDistributionsBy_.Value >0d && trimDistributionsBy_ <1d)
{
var series = dict[key].OrderBy(x => x);
int numberInTail = Convert.ToInt32(series.Count() * trimDistributionsBy_.Value);
//var subset = series.TakeWhile<double>(
}
hp.SetValues(key, dict[key]);
}
ret.Add(hp);
}
return ret;
}
示例10: AddCountdowns
public static void AddCountdowns(ConstructGen<double> prices_, List<DeMarkMarker> topLevelSetups_, int openIndex_ = 0,
int highIndex_ = 1, int lowIndex_ = 2,
int closeIndex_ = 3, int setupSeriesLength_ = 9, int countdownLength_ = 13)
{
var closes = prices_.GetColumnValuesAsDDC(closeIndex_);
var opens = prices_.GetColumnValuesAsDDC(openIndex_);
var highs = prices_.GetColumnValuesAsDDC(highIndex_);
var lows = prices_.GetColumnValuesAsDDC(lowIndex_);
var tuples = new List<Tuple<DeMarkMarker, DeMarkMarker>>();
foreach (var v in topLevelSetups_.Where(x => x.Disabled.HasValue == false))
{
tuples.Add(new Tuple<DeMarkMarker, DeMarkMarker>(v, v.Children.FirstOrDefault(
x =>
(x.EventType == DeMarkEventType.BuySetupIndex || x.EventType == DeMarkEventType.SellSetupIndex) &&
x.SeriesIndex == 9)));
}
foreach (var t in tuples)
{
var setupEnd = t.Item2;
if (setupEnd == null)
continue;
DateTime? nextSetupEnd = null;
{
var s = tuples.Where(x => x.Item2 != null).ToArray();
if(s.Any())
{
var series = s.Where(x => x.Item2.Date > setupEnd.Date && x.Item1.EventType != t.Item1.EventType).ToArray();
if (series.Any())
nextSetupEnd = series.OrderBy(x => x.Item2.Date).First().Item2.Date;
}
}
int count = 0;
for (int i = setupEnd.PriceIndex; i < closes.Length; ++i)
{
var date = closes.Dates[i];
// if a new setup has set, then don't continue with the countdown (aka 'recycling')
if (nextSetupEnd.HasValue && nextSetupEnd == date && count < 12)
{
i = closes.Length;
//t.Item1.Disabled = true;
continue;
}
switch (setupEnd.EventType)
{
case DeMarkEventType.BuySetupIndex: // series has been going down
{
if ((closes.Data[i] <= lows.Data[i - 2]) ||
(count == 12 && opens.Data[i] <= lows.Data[i - 2]))
{
++count;
t.Item1.AddChild(new DeMarkMarker
{
Date = closes.Dates[i],
EventType = DeMarkEventType.ReducingCountDown,
PriceIndex = i,
SeriesIndex = count,
CountDownLength = countdownLength_,
});
}
if (count == countdownLength_)
{
t.Item1.AddChild(new DeMarkMarker
{
Date = closes.Dates[i],
EventType = DeMarkEventType.CountDownStop,
PriceIndex = i,
SeriesIndex = count
});
i = closes.Length;
}
}
break;
case DeMarkEventType.SellSetupIndex: // series has been going up
{
if ((closes.Data[i] >= highs.Data[i - 2]) ||
(count == 12 && opens.Data[i] >= highs.Data[i - 2]))
{
++count;
t.Item1.AddChild(new DeMarkMarker
{
Date = closes.Dates[i],
EventType = DeMarkEventType.IncreasingCountDown,
PriceIndex = i,
SeriesIndex = count,
CountDownLength = countdownLength_,
//.........这里部分代码省略.........
示例11: GetSetups
public static List<DeMarkMarker> GetSetups(ConstructGen<double> prices_, int openIndex_ = 0, int highIndex_ = 1, int lowIndex_ = 2,
int closeIndex_ = 3, int targetSeriesLength = 9)
{
var closes = prices_.GetColumnValuesAsDDC(closeIndex_);
var highs = prices_.GetColumnValuesAsDDC(highIndex_);
var lows = prices_.GetColumnValuesAsDDC(lowIndex_);
var ret = new List<DeMarkMarker>();
int lowerSetupCount = 0;
int higherSetupCount = 0;
for (int i = 4; i < closes.Length; ++i)
{
{
if (closes.Data[i] < closes.Data[i - 4])
{
/////Setup Cancellation////
//if the setups do not reach the target, we cancel the setup
if (higherSetupCount > 0 && higherSetupCount < targetSeriesLength)
{
higherSetupCount = 0;
ret.RemoveAt(ret.Count - 1);
}
++lowerSetupCount;
}
else
{
/////Setup Cancellation////
//if the setups do not reach the target, we cancel the setup
if (lowerSetupCount > 0 && lowerSetupCount < targetSeriesLength)
ret.RemoveAt(ret.Count - 1);
lowerSetupCount = 0;
}
if (lowerSetupCount > 0)
{
if (lowerSetupCount == 1)
{
// setups start.
var mark = new DeMarkMarker
{
Date = closes.Dates[i],
EventType = DeMarkEventType.BuySetupStart,
PriceIndex = i,
SeriesIndex = 1,
SetupSeriesLength = targetSeriesLength,
};
ret.Add(mark);
}
var recentSetupStart = ret.Last();
recentSetupStart.AddChild(new DeMarkMarker
{
Date = closes.Dates[i],
EventType = DeMarkEventType.BuySetupIndex,
PriceIndex = i,
SeriesIndex = lowerSetupCount,
SetupSeriesLength = targetSeriesLength,
});
if (lowerSetupCount == targetSeriesLength)
{
lowerSetupCount = 0;
if ((lows.Data[i] <= lows.Data[i-2] && lows.Data[i] <= lows.Data[i-3]) ||
(lows.Data[i-1] <= lows.Data[i-2] && lows.Data[i] <= lows.Data[i-3]))
recentSetupStart.AddChild(new DeMarkMarker
{
Date = closes.Dates[i],
EventType = DeMarkEventType.PerfectedBuySetup,
PriceIndex = i,
SeriesIndex = lowerSetupCount,
SetupSeriesLength = targetSeriesLength,
});
}
}
}
{
if (closes.Data[i] > closes.Data[i - 4])
{
if (lowerSetupCount > 0 && lowerSetupCount < targetSeriesLength)
{
lowerSetupCount = 0;
ret.RemoveAt(ret.Count - 1);
}
++higherSetupCount;
}
else
{
/////Setup Cancellation////
//if the setups do not reach the target, we cancel the setup
if (higherSetupCount > 0 && higherSetupCount < targetSeriesLength)
ret.RemoveAt(ret.Count - 1);
higherSetupCount = 0;
}
if (higherSetupCount > 0)
{
//.........这里部分代码省略.........