Back

Cloned existing strategy and i have a error.

I am using my local visual studio to run lean
BasicTemplateAlgorithm works for me as backtest. so i cloned it as another cs file FirstBacktest.cs
I remembered to change the class name and also did a build using quantconnect.views
when i do a backtest, it errors out.
| 14:39:00:Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Algorithm type name not found, or unable to resolve multiple algorithm types to a single type. Please verify algorithm type name matches the algorithm name in the configuration file and that there is one and only one class derived from QCAlgorithm. Stack Trace:   at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler.CreateAlgorithmInstance (QuantConnect.Packets.AlgorithmNodePacket algorithmNodePacket, System.String assemblyPath) [0x00066] in <6a42206b43b148bbbc3c10c18b0bfff3>:0
  at QuantConnect.Lean.Engine.Engine.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Lean.Engine.AlgorithmManager manager, System.String assemblyPath) [0x000e9] in <6a42206b43b148bbbc3c10c18b0bfff3>:0 (Open Stacktrace)31 | 14:39:10:Your log was successfully created and can be retrieved from: https://www.quantconnect.com/backtest/23194/1628898/e0f5243286aaf86d0ba12768c69b5d63-log.txt
Update Backtest







Hi Rakesh,

Ensure that your algorithm name and algorithm language have been specified correctly in the config.json file.

You can also try cleaning the solution and rebuilding it.

Gabriel

0

i did both and the error is still teh same. I dont know what this means or how to fix it. i attached both the json and my cs code. i changed the keys so its not shared publicly. i could really use some help here as i am struggling.

{
// this configuration file works by first loading all top-level
// configuration items and then will load the specified environment
// on top, this provides a layering affect. environment names can be
// anything, and just require definition in this file. There's
// two predefined environments, 'backtesting' and 'live', feel free
// to add more!

// suresh configure this.

"environment": "backtesting-desktop", // "live-paper", "backtesting", "live-interactive", "live-interactive-iqfeed"

// algorithm class selector
//"algorithm-type-name": "BasicTemplateFrameworkAlgorithm",
"algorithm-type-name": "FirstBacktest",

// Algorithm language selector - options CSharp, FSharp, VisualBasic, Python, Java
"algorithm-language": "CSharp",


//Physical DLL location
"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
//"algorithm-location": "../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py",
//"algorithm-location": "QuantConnect.Algorithm.FSharp.dll",
//"algorithm-location": "QuantConnect.Algorithm.VisualBasic.dll",
//"algorithm-location": "QuantConnect.Algorithm.Java.dll",

//Jupyter notebook
//"composer-dll-directory": ".",

// engine
"data-folder": "../../../Data/",

// handlers
"log-handler": "QuantConnect.Logging.CompositeLogHandler",
"messaging-handler": "QuantConnect.Messaging.Messaging",
"job-queue-handler": "QuantConnect.Queues.JobQueue",
"api-handler": "QuantConnect.Api.Api",
"map-file-provider": "QuantConnect.Data.Auxiliary.LocalDiskMapFileProvider",
"factor-file-provider": "QuantConnect.Data.Auxiliary.LocalDiskFactorFileProvider",
"data-provider": "QuantConnect.Lean.Engine.DataFeeds.DefaultDataProvider",
"alpha-handler": "QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler",

// limits on number of symbols to allow
"symbol-minute-limit": 10000,
"symbol-second-limit": 10000,
"symbol-tick-limit": 10000,

// if one uses true in following token, market hours will remain open all hours and all days.
// if one uses false will make lean operate only during regular market hours.
"force-exchange-always-open": false,

// save list of transactions to the specified csv file
"transaction-log": "",

// To get your api access token go to quantconnect.com/account // suresh configure this.
"job-user-id": "931940",
"api-access-token": "3b2209efcf16g6b860de04eb63081cab9",

// live data configuration
"live-data-url": "ws://www.quantconnect.com/api/v2/live/data/",
"live-data-port": 8020,

// interactive brokers configuration
"ib-account": "",
"ib-user-name": "",
"ib-password": "",
"ib-host": "127.0.0.1",
"ib-port": "4002",
"ib-agent-description": "Individual",
"ib-use-tws": false,
"ib-tws-dir": "C:\\Jts",
"ib-trading-mode": "paper",
"ib-controller-dir": "C:\\IBController",
"ib-enable-delayed-streaming-data": false,

// tradier configuration
"tradier-account-id": "",
"tradier-access-token": "",
"tradier-refresh-token": "",
"tradier-issued-at": "",
"tradier-lifespan": "",
"tradier-refresh-session": true,

// oanda configuration
"oanda-environment": "Practice",
"oanda-access-token": "",
"oanda-account-id": "",

// fxcm configuration
"fxcm-server": "http://www.fxcorporate.com/Hosts.jsp",
"fxcm-terminal": "Demo", //Real or Demo
"fxcm-user-name": "",
"fxcm-password": "",
"fxcm-account-id": "",

// iqfeed configuration
"iqfeed-username": "",
"iqfeed-password": "",
"iqfeed-productName": "",
"iqfeed-version": "1.0",

// gdax configuration
"gdax-api-secret": "",
"gdax-api-key": "",
"gdax-passphrase": "",

// Required to access data from Quandl
// To get your access token go to https://www.quandl.com/account/api
"quandl-auth-token": "",

// Required to access data from Tiingo
// To get your access token go to https://www.tiingo.com
"tiingo-auth-token": "",

// parameters to set in the algorithm (the below are just samples)
"parameters": {
// Intrinio account user and password
"intrinio-username": "",
"intrinio-password": "",

"ema-fast": 10,
"ema-slow": 20
},

"environments": {

// defines the 'backtesting' environment
"backtesting": {
"live-mode": false,

"setup-handler": "QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.BacktestingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler",
"history-provider": "QuantConnect.Lean.Engine.HistoricalData.SubscriptionDataReaderHistoryProvider",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler"
},

// defines the 'live-paper' environment
"live-paper": {
"live-mode": true,

// the paper brokerage requires the BacktestingTransactionHandler
"live-mode-brokerage": "PaperBrokerage",

"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"data-queue-handler": "QuantConnect.Lean.Engine.DataFeeds.Queues.LiveDataQueue",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler"
},

// defines the 'live-tradier' environment
"live-tradier": {
"live-mode": true,

// this setting will save tradier access/refresh tokens to a tradier-tokens.txt file
// that can be read in next time, this makes it easier to start/stop a tradier algorithm
"tradier-save-tokens": true,

// real brokerage implementations require the BrokerageTransactionHandler
"live-mode-brokerage": "TradierBrokerage",
"data-queue-handler": "TradierBrokerage",

"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler"
},

// defines the 'live-interactive' environment
"live-interactive": {
"live-mode": true,

// real brokerage implementations require the BrokerageTransactionHandler
"live-mode-brokerage": "InteractiveBrokersBrokerage",
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"data-queue-handler": "QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler",
"history-provider": "BrokerageHistoryProvider"
},

// defines the 'live-interactive-iqfeed' environment
"live-interactive-iqfeed": {
"live-mode": true,

// real brokerage implementations require the BrokerageTransactionHandler
"live-mode-brokerage": "InteractiveBrokersBrokerage",
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"data-queue-handler": "QuantConnect.ToolBox.IQFeed.IQFeedDataQueueHandler",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler",
"history-provider": "QuantConnect.ToolBox.IQFeed.IQFeedDataQueueHandler"
},

// defines the 'live-fxcm' environment
"live-fxcm": {
"live-mode": true,

// real brokerage implementations require the BrokerageTransactionHandler
"live-mode-brokerage": "FxcmBrokerage",
"data-queue-handler": "FxcmBrokerage",
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler",
"history-provider": "BrokerageHistoryProvider"
},

// defines the 'live-oanda' environment
"live-oanda": {
"live-mode": true,

// real brokerage implementations require the BrokerageTransactionHandler
"live-mode-brokerage": "OandaBrokerage",
"data-queue-handler": "OandaBrokerage",
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler",
"history-provider": "BrokerageHistoryProvider"
},

// defines the 'backtesting-desktop' environment
"backtesting-desktop": {
"live-mode": false,
"send-via-api": true,

"setup-handler": "QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.BacktestingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler",
"messaging-handler": "QuantConnect.Messaging.StreamingMessageHandler",
"log-handler": "QuantConnect.Logging.QueueLogHandler",
"desktop-http-port": "8888",
"desktop-exe": "../../../UserInterface/bin/Debug/QuantConnect.Views.exe"
},

// defines the 'live-desktop' environment
"live-desktop": {
"live-mode": true,
"send-via-api": true,

// Set your own brokerage and data queue handlers here.
// Live desktop charting isn't as cool as on quantconnect.com but its pretty neat!
"live-mode-brokerage": "FxcmBrokerage",
"data-queue-handler": "FxcmBrokerage",
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler",
"messaging-handler": "QuantConnect.Messaging.StreamingMessageHandler",
"log-handler": "QuantConnect.Logging.QueueLogHandler",
"desktop-http-port": "1234",
"desktop-exe": "../../../UserInterface/bin/Release/QuantConnect.Views.exe"
},

"live-gdax": {
"live-mode": true,

// real brokerage implementations require the BrokerageTransactionHandler
"live-mode-brokerage": "GDAXBrokerage",
"data-queue-handler": "GDAXDataQueueHandler",
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler",
"history-provider": "BrokerageHistoryProvider"
}

}
}
/*
* 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.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Interfaces;

namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash. This is a skeleton
/// framework you can use for designing an algorithm.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="using quantconnect" />
/// <meta name="tag" content="trading and orders" />
public class FirstBacktest : QCAlgorithm, IRegressionAlgorithmDefinition
{
// private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
private Symbol _eurusd = QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, Market.FXCM);

/// <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(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash

// Find more symbols here: http://quantconnect.com/data
// Forex, CFD, Equities Resolutions: Tick, Second, Minute, Hour, Daily.
// Futures Resolution: Tick, Second, Minute
// Options Resolution: Minute Only.
// AddEquity("SPY", Resolution.Minute);
AddForex("EURUSD", Resolution.Minute);

// There are other assets with similar methods. See "Selecting Options" etc for more details.
// AddFuture, AddForex, AddCfd, AddOption
}

/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
SetHoldings(_eurusd, 1);
Debug("Purchased Stock");
}
}

/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;

/// <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", "264.583%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.668%"},
{"Sharpe Ratio", "4.41"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.007"},
{"Beta", "76.354"},
{"Annual Standard Deviation", "0.193"},
{"Annual Variance", "0.037"},
{"Information Ratio", "4.354"},
{"Tracking Error", "0.193"},
{"Treynor Ratio", "0.011"},
{"Total Fees", "$3.27"}
};
}
}
0

Is your FirstBacktest class inside your Algorithm.CSharp project? If not, you need to point to the right dll file in algorithm-location.

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed