Hi Guys,
I am trying to backtest and draw chart locally with latest download Lean-master 2016-05-17.
When I am using the C# BasicTemplateAlgorithm and Resolution.Second, everything works as expected.One trade is made, statistics generated and chart shown.
But when I change to Resolution.Daily, no trades are made, no stats are generated and no chart is shown (see logs below)
I have changed BasicTemplateAlgorithm.cs to the following:
using QuantConnect.Data;
using QuantConnect.Data.Market;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash
/// </summary>
public class BasicTemplateAlgorithm : QCAlgorithm
{
/// <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
AddEquity("SPY", Resolution.Second); // This works with public override void OnData(Slice data)
//AddEquity("SPY", Resolution.Daily); // This does not work with public void OnData(TradeBars data), which i think it should
//AddEquity("SPY", Resolution.Minute); // This does not work with public void OnData(TradeBars data), which i think it should
}
// Uncomment the following to backtest with Resolution.Second (this works), at the the same time comment out OnData(TradeBars data) method below
public override void OnData(Slice data) // This works with Resolution.Second
{
if (!Portfolio.Invested) {
SetHoldings("SPY", 1);
Debug("Purchased Stock");
}
}
// Uncomment the following to backtest with Resolution.Daily (doesn't work), at the the same time comment out OnData(Slice data) method above
//public void OnData(TradeBars data) { // This doesn't work with Resolution.Daily (or Resolution.Minute), which I think it should.
// if (!Portfolio.Invested) {
// SetHoldings("SPY", 1);
// Debug("Purchased Stock");
// }
//}
}
}
The reasong I chage the OnData() method from Slice to TradeBars when using daily data is that I could not get Slice to work with Resolution.Daily. So I looked at how it is done in DailyAlgorithm.cs, but this still doesn't work.
Relevant lines in my Launcher/config.json are as follows (the only changes are 'environment', 'job-user-id' and 'api-access-token'):
"environment": "backtesting-desktop",
"algorithm-type-name": "BasicTemplateAlgorithm",
"algorithm-language": "CSharp",
"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
"data-folder": "../../../Data/",
"job-user-id": "#####", (where ##### is the job id i got from the backtesting terminal)
"api-access-token": "xxx", (where xxx is my access token from quantconnect.com/account)
Log output to LeanWinForm when it is working OK with Resolution.Second and OnData(Slice data):
2016-05-20T08:25:04.2270452Z Trace Config.Get(): Configuration key not found. Key: data-directory - Using default value: ../../../Data/
2016-05-20T08:25:04.2280452Z Trace Config.Get(): Configuration key not found. Key: version-id - Using default value:
2016-05-20T08:25:04.2280452Z Trace Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.2.0.2 Mode: DEBUG
2016-05-20T08:25:04.2280452Z Trace Engine.Main(): Started 10:25
2016-05-20T08:25:05.4641159Z Trace Engine.Main(): Memory 42Mb-App 3Mb-Used 2195Mb-Total
2016-05-20T08:25:05.4691162Z Trace Config.GetValue(): job-project-id - Using default value: 0
2016-05-20T08:25:05.7131302Z Trace JobQueue.NextJob(): Selected QuantConnect.Algorithm.CSharp.dll
2016-05-20T08:25:05.7211306Z Trace Config.Get(): Configuration key not found. Key: history-provider - Using default value: SubscriptionDataReaderHistoryProvider
2016-05-20T08:25:05.7491322Z Trace JOB HANDLERS:
2016-05-20T08:25:05.7491322Z Trace DataFeed: QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed
2016-05-20T08:25:05.7501323Z Trace Setup: QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler
2016-05-20T08:25:05.7501323Z Trace RealTime: QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler
2016-05-20T08:25:05.7501323Z Trace Results: QuantConnect.Lean.Engine.Results.BacktestingResultHandler
2016-05-20T08:25:05.7501323Z Trace Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
2016-05-20T08:25:05.7501323Z Trace History: QuantConnect.Lean.Engine.HistoricalData.SubscriptionDataReaderHistoryProvider
2016-05-20T08:25:05.7501323Z Trace Commands: QuantConnect.Queues.EmptyCommandQueueHandler
2016-05-20T08:25:05.7501323Z Trace Config.GetValue(): ignore-version-checks - Using default value: False
2016-05-20T08:25:05.7561326Z Trace Config.GetValue(): algorithm-manager-time-loop-maximum - Using default value: 10
2016-05-20T08:25:05.7771338Z Trace Config.Get(): Configuration key not found. Key: ironpython-location - Using default value: ../ironpython/Lib
2016-05-20T08:25:05.7811341Z Trace Loader.TryCreateILAlgorithm(): Loading only the algorithm assembly
2016-05-20T08:25:05.8081356Z Trace Loader.TryCreateILAlgorithm(): Loaded BasicTemplateAlgorithm
2016-05-20T08:25:05.9581442Z Trace BacktestingResultHandler(): Sample Period Set: 04,00
2016-05-20T08:25:05.9591443Z Trace Time.TradeableDates(): Security Count: 1
2016-05-20T08:25:05.9611444Z Trace Config.GetValue(): forward-console-messages - Using default value: True
2016-05-20T08:25:05.9811455Z Trace AlgorithmManager.Run(): Begin DataStream - Start: 2013-10-07 00:00:00 Stop: 2013-10-11 23:59:59
2016-05-20T08:25:05.9901460Z Trace FileSystemDataFeed.GetEnumerator(): Begin: 2013-10-07 04:00:00 UTC
2016-05-20T08:25:15.8337091Z Trace FileSystemDataFeed.Run(): Data Feed Completed at 2013-10-11 20:00:00 UTC
2016-05-20T08:25:15.8337091Z Trace AlgorithmManager.Run(): Firing On End Of Algorithm...
2016-05-20T08:25:15.8337091Z Trace Engine.Run(): Exiting Algorithm Manager
2016-05-20T08:25:15.9617164Z Trace Launching analysis for BasicTemplateAlgorithm with LEAN Engine v2.2.0.2
2016-05-20T08:25:19.0918954Z Trace Purchased Stock
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Total Trades 1
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Average Win 0%
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Average Loss 0%
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Compounding Annual Return 264,956%
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Drawdown 2,200%
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Expectancy 0
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Net Profit 0%
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Sharpe Ratio 4.411
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Loss Rate 0%
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Win Rate 0%
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Profit-Loss Ratio 0
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Alpha 0.002
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Beta 1
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Annual Standard Deviation 0.193
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Annual Variance 0.037
2016-05-20T08:25:19.1819006Z Trace STATISTICS:: Information Ratio 6.816
2016-05-20T08:25:19.1829006Z Trace STATISTICS:: Tracking Error 0
2016-05-20T08:25:19.1839007Z Trace STATISTICS:: Treynor Ratio 0.851
2016-05-20T08:25:19.1849007Z Trace STATISTICS:: Total Fees $3,09
2016-05-20T08:25:19.1919011Z Trace StreamingApi.Transmit(): Packet too long: QuantConnect.Packets.BacktestResultPacket
2016-05-20T08:25:19.3759117Z Trace Algorithm Id:(BasicTemplateAlgorithm) completed in 9,95 seconds at 12k data points per second. Processing total of 117 005 data points.
2016-05-20T08:25:20.1519560Z Trace BacktestingResultHandler.SendAnalysisResult(): Processed final packet
2016-05-20T08:25:20.1529561Z Trace FileSystemDataFeed.Exit(): Exit triggered.
2016-05-20T08:25:20.1869580Z Trace BrokerageTransactionHandler.Run(): Ending Thread...
2016-05-20T08:25:20.1969586Z Trace BacktestingResultHandler.ProcessLogMessages(): Ready: http://data.quantconnect.com/backtests/#####/0/BasicTemplateAlgorithm-log.txt
2016-05-20T08:25:20.1979587Z Trace StateCheck.Ping.Run(): Exited thread.
2016-05-20T08:25:20.2329607Z Trace FileSystemDataFeed.Run(): Ending Thread...
2016-05-20T08:25:20.2389610Z Trace Your log was successfully created and can be downloaded from: http://data.quantconnect.com/backtests/#####/0/BasicTemplateAlgorithm-log.txt
2016-05-20T08:25:20.2979644Z Trace Waiting for threads to exit...
2016-05-20T08:25:20.5269775Z Trace BacktestingResultHandler.Run(): Ending Thread...
2016-05-20T08:25:20.5979816Z Trace Waiting for threads to exit...
2016-05-20T08:25:20.5979816Z Trace Engine.Run(): Disconnecting from brokerage...
2016-05-20T08:25:20.5979816Z Trace Engine.Run(): Disposing of setup handler...
2016-05-20T08:25:20.6009817Z Trace Engine.Main(): Analysis Completed and Results Posted.
2016-05-20T08:25:20.6019818Z Trace BacktestingResultHandler.ProcessLogMessages(): Ready: http://data.quantconnect.com/backtests/#####/0/BasicTemplateAlgorithm-log.txt
2016-05-20T08:25:20.6029818Z Trace FileSystemDataFeed.Exit(): Exit triggered.
Log output to LeanWinForm when it isn't working with Resolution.Daily and OnData(TradeBars data):
2016-05-20T08:45:28.7140818Z Trace Time.TradeableDates(): Security Count: 1
2016-05-20T08:45:28.7160820Z Trace Config.GetValue(): forward-console-messages - Using default value: True
2016-05-20T08:45:28.7560842Z Trace AlgorithmManager.Run(): Begin DataStream - Start: 2013-10-07 00:00:00 Stop: 2013-10-11 23:59:59
2016-05-20T08:45:28.7650848Z Trace FileSystemDataFeed.GetEnumerator(): Begin: 2013-10-07 04:00:00 UTC
2016-05-20T08:45:28.9300942Z Trace FileSystemDataFeed.Run(): Data Feed Completed at 2013-10-12 04:00:00 UTC
2016-05-20T08:45:28.9310943Z Trace AlgorithmManager.Run(): Firing On End Of Algorithm...
2016-05-20T08:45:28.9310943Z Trace Engine.Run(): Exiting Algorithm Manager
2016-05-20T08:45:29.1051042Z Trace BacktestingResultHandler.SendAnalysisResult(): Processed final packet
2016-05-20T08:45:29.1061043Z Trace FileSystemDataFeed.Exit(): Exit triggered.
2016-05-20T08:45:29.1451065Z Trace BrokerageTransactionHandler.Run(): Ending Thread...
2016-05-20T08:45:29.1641076Z Trace BacktestingResultHandler.ProcessLogMessages(): Ready: http://data.quantconnect.com/backtests/#####/0/BasicTemplateAlgorithm-log.txt
2016-05-20T08:45:29.1661077Z Trace StateCheck.Ping.Run(): Exited thread.
2016-05-20T08:45:29.1841087Z Trace FileSystemDataFeed.Run(): Ending Thread...
2016-05-20T08:45:29.1881090Z Trace BacktestingResultHandler.Run(): Ending Thread...
2016-05-20T08:45:29.2671135Z Trace Waiting for threads to exit...
2016-05-20T08:45:29.2671135Z Trace Engine.Run(): Disconnecting from brokerage...
2016-05-20T08:45:29.2671135Z Trace Engine.Run(): Disposing of setup handler...
2016-05-20T08:45:29.2671135Z Trace Engine.Main(): Analysis Completed and Results Posted.
2016-05-20T08:45:29.2671135Z Trace BacktestingResultHandler.ProcessLogMessages(): Ready: http://data.quantconnect.com/backtests/#####/0/BasicTemplateAlgorithm-log.txt
2016-05-20T08:45:29.2671135Z Trace FileSystemDataFeed.Exit(): Exit triggered.
I am backtesting this locally in Win7 and use VS2015.2 community edition.
What am I missing here?
Jared Broad
Hi Dough, I just ran it using daily data and the backtesting desktop view and it worked fine -- guessing there's some local modifications you've made or the engine cannot find the data directory you're referring to (or can't parse your data).
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.
More Dough
Hi Jared,
Thanks for your quick response.
I understand your guess I must have made some local modifications, but no, that can't be it!
I have now checked everything I can think of, but still no luck:
1. Deleted old Lean-master and extracted new from zip downloaded 2016-05-17 via QC Lean page.
2. Set environment, job-user-id and api-access-token in Launcher/config.json
3. Tested with original BasicTemplateAlgorithm.cs ===> everything behaves as expected. (OK)
4. Only changed BasicTemplateAlgorithm to Resolution.Daily, nothing else changed in BasicTemplateAlgorithm or in the rest of the solution. ===> No trade, no stats, no chart. Just like the last log in original post above (WTF!!!)
6. Changed BasicTemplateAlgorithm to use OnData(TradeBars data) ===> Same problem
The data used for testing is the original data that comes with Lean in the zip, so this shouldn't be the problem..I have checked the \Lean-master\Data\equity\usa\daily\spy.zip file and it contains data for the period 2013-10-07 to 2013-10-11. Is this the data you tested with?
When you tested, did you: Download the zip via the link on QC Lean page? Test on Win7? Test locally with Debug build in VisualStudio 2015.2 community edition?This is getting really wierd, what is the problem?
Please help, I'm totally stuck on this and getting a bit desparate!
/Dough
Jared Broad
Do you see "Vector smash protection is enabled." in the console log? Occassionally I've repeated the issue when the form hasn't had time to load (such as only backtesting 3 days of daily data of the basic template).
I got daily to work just by extending the backtesting period.
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.
More Dough
No, I have never seen "Vector smash protection is enabled" in the log.
Per your suggestion above, I extended the period: 2010-10-07 to 2013-10-11 ===> Same problem
I then extended the backtesting period still further: 2000-10-07 to 2013-10-11 ===> And now it works as expected!
So there seems to be some kind of race condition in local charting, right?
This should be relatively easy to correct. I am looking forward to it!
Please let me know when I can download Lean with a fix for this.
Thanks,
/Dough
More Dough
Correction!
Yes, I do see "Vector smash protection is enabled" in the console log. (Didn't observe the "console" qualifier at first, so I looked at the LeanWinForm log output)
"Vector smash" does not sound good. Is this dangerous? Should I wear a condom while backtesting locally?
/Dough
More Dough
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!