本文整理汇总了C#中Strategy.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Strategy.GetType方法的具体用法?C# Strategy.GetType怎么用?C# Strategy.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Strategy
的用法示例。
在下文中一共展示了Strategy.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StrategyNameGenerator
/// <summary>
/// Initializes a new instance of the <see cref="StrategyNameGenerator"/>.
/// </summary>
/// <param name="strategy">Strategy.</param>
public StrategyNameGenerator(Strategy strategy)
{
if (strategy == null)
throw new ArgumentNullException("strategy");
_strategy = strategy;
_strategy.SecurityChanged += () =>
{
if (_selectors.Contains("Security"))
Refresh();
};
_strategy.PortfolioChanged += () =>
{
if (_selectors.Contains("Portfolio"))
Refresh();
};
ShortName = new string(_strategy.GetType().Name.Where(char.IsUpper).ToArray());
_formatter = Smart.CreateDefaultSmartFormat();
_formatter.SourceExtensions.Add(new Source(_formatter, new Dictionary<string, string>
{
{ "FullName", _strategy.GetType().Name },
{ "ShortName", ShortName },
}));
_selectors = new SynchronizedSet<string>();
AutoGenerateStrategyName = true;
Pattern = "{ShortName}{Security:_{0.Security}|}{Portfolio:_{0.Portfolio}|}";
}
示例2: setStrategy
public static void setStrategy(Strategy s ){
BallScript.strategy = s;
if (s.GetType()== new secondStrategy().GetType()) {
Debug.Log("sec strategy");
BallScript.strategy=new secondStrategy();
}
}
示例3: Optimize
private void Optimize(Strategy strategy, InstrumentList instruments, OptimizationUniverse universe, int index, int n)
{
Framework[] array = new Framework[n];
Strategy[] array2 = new Strategy[n];
for (int i = 0; i < n; i++)
{
if (i == 0)
{
array[i] = strategy.framework;
}
else
{
array[i] = new Framework("framework " + i, array[i - 1].EventBus, strategy.framework.InstrumentServer, null);
}
array2[i] = (Strategy)Activator.CreateInstance(strategy.GetType(), new object[]
{
array[i],
"strategy " + i
});
}
for (int j = 0; j < n; j++)
{
OptimizationParameterSet optimizationParameterSet = universe[index + j];
foreach (OptimizationParameter current in optimizationParameterSet)
{
if (current.Name == "Bar")
{
using (IEnumerator<Instrument> enumerator2 = instruments.GetEnumerator())
{
while (enumerator2.MoveNext())
{
Instrument current2 = enumerator2.Current;
array[j].EventManager.BarFactory.Add(current2, BarType.Time, (long)current.Value);
}
continue;
}
}
FieldInfo field = array2[j].GetType().GetField(current.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField | BindingFlags.SetField);
if (field != null)
{
if (field.FieldType == typeof(int))
{
field.SetValue(array2[j], (int)current.Value);
}
else
{
field.SetValue(array2[j], current.Value);
}
}
else
{
Console.WriteLine("Optimizer::Optimize Can not set field with name " + current.Name);
}
}
}
for (int k = 0; k < n; k++)
{
foreach (Instrument current3 in instruments)
{
array2[k].AddInstrument(current3);
}
}
for (int l = n - 1; l >= 0; l--)
{
array[l].StrategyManager.StartStrategy(array2[l], StrategyMode.Backtest);
}
bool flag;
do
{
flag = true;
for (int m = 0; m < n; m++)
{
if (array2[m].Status != StrategyStatus.Stopped)
{
flag = false;
}
}
Thread.Sleep(10);
}
while (!flag);
for (int num = 0; num < n; num++)
{
universe[num].Objective = array2[num].Objective();
Console.WriteLine(universe[num] + " Objective = " + universe[num].Objective);
}
for (int num2 = 0; num2 < n; num2++)
{
this.event_count += array[num2].eventManager.EventCount;
}
for (int num3 = 0; num3 < n; num3++)
{
array[num3] = null;
array2[num3] = null;
}
strategy.framework.Clear();
}