9ee61f425c
A mechanical refactoring was performed to make algorithms currently used in regression algorithms to implement IRegressionAlgorithmDefinition, which allows algorithms to define their own expected statistics and what languages should be run as part of regression. The type name of the C# type is used to determine the file/model name for python. This was for simplicity, but if needed, could later be refactored to expose more information, but for now the convention of keeping names the same makes sense and just works easily.
95 lines
3.8 KiB
C#
95 lines
3.8 KiB
C#
/*
|
|
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
|
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace QuantConnect.Algorithm.CSharp
|
|
{
|
|
/// <summary>
|
|
/// Regression test to demonstrate importing and trading on custom data.
|
|
/// </summary>
|
|
/// <meta name="tag" content="using data" />
|
|
/// <meta name="tag" content="custom data" />
|
|
/// <meta name="tag" content="crypto" />
|
|
/// <meta name="tag" content="regression test" />
|
|
public class CustomDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
|
{
|
|
/// <summary>
|
|
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
|
/// </summary>
|
|
public override void Initialize()
|
|
{
|
|
SetStartDate(2011, 9, 13);
|
|
SetEndDate(2015, 12, 01);
|
|
|
|
//Set the cash for the strategy:
|
|
SetCash(100000);
|
|
|
|
//Define the symbol and "type" of our generic data:
|
|
var resolution = LiveMode ? Resolution.Second : Resolution.Daily;
|
|
AddData<Bitcoin>("BTC", resolution);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event Handler for Bitcoin Data Events: These Bitcoin objects are created from our
|
|
/// "Bitcoin" type below and fired into this event handler.
|
|
/// </summary>
|
|
/// <param name="data">One(1) Bitcoin Object, streamed into our algorithm synchronised in time with our other data streams</param>
|
|
public void OnData(Bitcoin data)
|
|
{
|
|
//If we don't have any bitcoin "SHARES" -- invest"
|
|
if (!Portfolio.Invested)
|
|
{
|
|
//Bitcoin used as a tradable asset, like stocks, futures etc.
|
|
if (data.Close != 0)
|
|
{
|
|
Order("BTC", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
|
/// </summary>
|
|
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
|
|
|
/// <summary>
|
|
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
|
/// </summary>
|
|
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
|
{
|
|
{"Total Trades", "1"},
|
|
{"Average Win", "0%"},
|
|
{"Average Loss", "0%"},
|
|
{"Compounding Annual Return", "155.365%"},
|
|
{"Drawdown", "84.800%"},
|
|
{"Expectancy", "0"},
|
|
{"Net Profit", "5123.170%"},
|
|
{"Sharpe Ratio", "1.2"},
|
|
{"Loss Rate", "0%"},
|
|
{"Win Rate", "0%"},
|
|
{"Profit-Loss Ratio", "0"},
|
|
{"Alpha", "-0.008"},
|
|
{"Beta", "73.725"},
|
|
{"Annual Standard Deviation", "0.84"},
|
|
{"Annual Variance", "0.706"},
|
|
{"Information Ratio", "1.183"},
|
|
{"Tracking Error", "0.84"},
|
|
{"Treynor Ratio", "0.014"},
|
|
{"Total Fees", "$0.00"}
|
|
};
|
|
}
|
|
} |