Extends SetBenchmark to accept functions as paramenters in Python

This commit is contained in:
AlexCatarino
2017-10-12 23:57:20 +01:00
parent b8c7bed5f9
commit 6fc55de371
2 changed files with 24 additions and 1 deletions
+19
View File
@@ -565,6 +565,25 @@ namespace QuantConnect.Algorithm
return _converter.GetDataFrame(History(symbols, start, end, resolution));
}
/// <summary>
/// Sets the specified function as the benchmark, this function provides the value of
/// the benchmark at each date/time requested
/// </summary>
/// <param name="benchmark">The benchmark producing function</param>
public void SetBenchmark(PyObject benchmark)
{
using (Py.GIL())
{
var pyBenchmark = PythonUtil.ToFunc<DateTime, decimal>(benchmark);
if (pyBenchmark != null)
{
SetBenchmark(pyBenchmark);
return;
}
SetBenchmark((Symbol)benchmark.AsManagedObject(typeof(Symbol)));
}
}
/// <summary>
/// Sets the brokerage to emulate in backtesting or paper trading.
/// This can be used to set a custom brokerage model.