/* * 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 { /// /// Regression test to demonstrate importing and trading on custom data. /// /// /// /// /// public class CustomDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition { /// /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// 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("BTC", resolution); } /// /// Event Handler for Bitcoin Data Events: These Bitcoin objects are created from our /// "Bitcoin" type below and fired into this event handler. /// /// One(1) Bitcoin Object, streamed into our algorithm synchronised in time with our other data streams 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)); } } } /// /// This is used by the regression test system to indicate which languages this algorithm is written in. /// public Language[] Languages { get; } = { Language.CSharp, Language.Python }; /// /// This is used by the regression test system to indicate what the expected statistics are from running the algorithm /// public Dictionary ExpectedStatistics => new Dictionary { {"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"} }; } }