GeezerVison is showing github.com — Added tags to some C# algorithms · nuswgg/Lean@4ebc44d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/AddRemoveSecurityRegressionAlgorithm.cs +14-10Lines changed: 14 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 14 | 14 | */ | 15 | 15 |
| 16 | 16 | using System; | 17 | | -using QuantConnect.Data; | 18 | 17 | using QuantConnect.Data.Market; | 19 | | -using QuantConnect.Data.UniverseSelection; | 20 | 18 | using QuantConnect.Orders; | 21 | 19 |
| 22 | 20 | namespace QuantConnect.Algorithm.CSharp | 23 | 21 | { | 24 | 22 | /// <summary> | 25 | | - /// Basic template algorithm simply initializes the date range and cash | | 23 | + /// This algorithm demonstrates the runtime addition and removal of securities from your algorithm. | | 24 | + /// With LEAN it is possible to add and remove securities after the initialization. | 26 | 25 | /// </summary> | | 26 | + /// <meta name="tag" content="using data" /> | | 27 | + /// <meta name="tag" content="assets" /> | | 28 | + /// <meta name="tag" content="regression test" /> | 27 | 29 | public class AddRemoveSecurityRegressionAlgorithm : QCAlgorithm | 28 | 30 | { | 29 | 31 | private DateTime lastAction; | @@ -40,8 +42,6 @@ public override void Initialize() | 40 | 42 | SetStartDate(2013, 10, 07); //Set Start Date | 41 | 43 | SetEndDate(2013, 10, 11); //Set End Date | 42 | 44 | SetCash(100000); //Set Strategy Cash | 43 | | - // Find more symbols here: http://quantconnect.com/data | 44 | | - | 45 | 45 | AddSecurity(SecurityType.Equity, "SPY"); | 46 | 46 | } | 47 | 47 |
| @@ -78,15 +78,19 @@ public void OnData(TradeBars data) | 78 | 78 | } | 79 | 79 | } | 80 | 80 |
| | 81 | + /// <summary> | | 82 | + /// Order events are triggered on order status changes. There are many order events including non-fill messages. | | 83 | + /// </summary> | | 84 | + /// <param name="orderEvent">OrderEvent object with details about the order status</param> | 81 | 85 | public override void OnOrderEvent(OrderEvent orderEvent) | 82 | 86 | { | 83 | 87 | if (orderEvent.Status == OrderStatus.Submitted) | 84 | 88 | { | 85 | | - Console.WriteLine(Time + ": Submitted: " + Transactions.GetOrderById(orderEvent.OrderId)); | | 89 | + Debug(Time + ": Submitted: " + Transactions.GetOrderById(orderEvent.OrderId)); | 86 | 90 | } | 87 | 91 | if (orderEvent.Status.IsFill()) | 88 | 92 | { | 89 | | - Console.WriteLine(Time + ": Filled: " + Transactions.GetOrderById(orderEvent.OrderId)); | | 93 | + Debug(Time + ": Filled: " + Transactions.GetOrderById(orderEvent.OrderId)); | 90 | 94 | } | 91 | 95 | } | 92 | 96 | } | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/BasicTemplateAlgorithm.cs +18-8Lines changed: 18 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 18 | 18 | namespace QuantConnect.Algorithm.CSharp | 19 | 19 | { | 20 | 20 | /// <summary> | 21 | | - /// Basic template algorithm simply initializes the date range and cash | | 21 | + /// Basic template algorithm simply initializes the date range and cash. This is a skeleton | | 22 | + /// framework you can use for designing an algorithm. | 22 | 23 | /// </summary> | | 24 | + /// <meta name="tag" content="using data" /> | | 25 | + /// <meta name="tag" content="using quantconnect" /> | | 26 | + /// <meta name="tag" content="trading and orders" /> | | 27 | + /// <meta name="tag" content="regression test" /> | 23 | 28 | public class BasicTemplateAlgorithm : QCAlgorithm | 24 | 29 | { | 25 | | - private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA); | 26 | | - | 27 | 30 | /// <summary> | 28 | 31 | /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. | 29 | 32 | /// </summary> | @@ -32,8 +35,15 @@ public override void Initialize() | 32 | 35 | SetStartDate(2013, 10, 07); //Set Start Date | 33 | 36 | SetEndDate(2013, 10, 11); //Set End Date | 34 | 37 | SetCash(100000); //Set Strategy Cash | | 38 | + | 35 | 39 | // Find more symbols here: http://quantconnect.com/data | 36 | | - AddEquity("SPY", Resolution.Second); | | 40 | + // Forex, CFD, Equities Resolutions: Tick, Second, Minute, Hour, Daily. | | 41 | + // Futures Resolution: Tick, Second, Minute | | 42 | + // Options Resolution: Minute Only. | | 43 | + AddEquity("SPY", Resolution.Minute); | | 44 | + | | 45 | + // There are other assets with similar methods. See "Selecting Options" etc for more details. | | 46 | + // AddFuture, AddForex, AddCfd, AddOption | 37 | 47 | } | 38 | 48 |
| 39 | 49 | /// <summary> | @@ -44,7 +54,7 @@ public override void OnData(Slice data) | 44 | 54 | { | 45 | 55 | if (!Portfolio.Invested) | 46 | 56 | { | 47 | | - SetHoldings(_spy, 1); | | 57 | + SetHoldings("SPY", 1); | 48 | 58 | Debug("Purchased Stock"); | 49 | 59 | } | 50 | 60 | } | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/BasicTemplateDailyAlgorithm.cs +8-7Lines changed: 8 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 18 | 18 | namespace QuantConnect.Algorithm.CSharp | 19 | 19 | { | 20 | 20 | /// <summary> | 21 | | - /// Basic template algorithm simply initializes the date range and cash | | 21 | + /// Demonstration of requesting daily resolution data for US Equities. | | 22 | + /// This is a simple regression test algorithm using a skeleton algorithm and requesting daily data. | 22 | 23 | /// </summary> | | 24 | + /// <meta name="tag" content="using data" /> | | 25 | + /// <meta name="tag" content="regression test" /> | 23 | 26 | public class BasicTemplateDailyAlgorithm : QCAlgorithm | 24 | 27 | { | 25 | | - private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA); | 26 | | - | 27 | 28 | /// <summary> | 28 | 29 | /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. | 29 | 30 | /// </summary> | @@ -44,7 +45,7 @@ public override void OnData(Slice data) | 44 | 45 | { | 45 | 46 | if (!Portfolio.Invested) | 46 | 47 | { | 47 | | - SetHoldings(_spy, 1); | | 48 | + SetHoldings("SPY", 1); | 48 | 49 | Debug("Purchased Stock"); | 49 | 50 | } | 50 | 51 | } | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/BasicTemplateFillForwardAlgorithm.cs +8-7Lines changed: 8 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 18 | 18 | namespace QuantConnect.Algorithm.Examples | 19 | 19 | { | 20 | 20 | /// <summary> | 21 | | - /// Basic template algorithm simply initializes the date range and cash | | 21 | + /// Skeleton algorithm demonstrating filling forward data through gaps and inconsistent data. By default LEAN fills the previous bar forward | | 22 | + /// so you get regular bars. | 22 | 23 | /// </summary> | | 24 | + /// <meta name="tag" content="using data" /> | | 25 | + /// <meta name="tag" content="regression test" /> | 23 | 26 | public class BasicTemplateFillForwardAlgorithm : QCAlgorithm | 24 | 27 | { | 25 | | - private Symbol _asur = QuantConnect.Symbol.Create("ASUR", SecurityType.Equity, Market.USA); | 26 | | - | 27 | 28 | /// <summary> | 28 | 29 | /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. | 29 | 30 | /// </summary> | @@ -44,7 +45,7 @@ public void OnData(TradeBars data) | 44 | 45 | { | 45 | 46 | if (!Portfolio.Invested) | 46 | 47 | { | 47 | | - SetHoldings(_asur, 1); | | 48 | + SetHoldings("ASUR", 1); | 48 | 49 | Debug("Purchased Stock"); | 49 | 50 | } | 50 | 51 | } | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/BasicTemplateForexAlgorithm.cs +12-7Lines changed: 12 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 19 | 19 | namespace QuantConnect.Algorithm.CSharp | 20 | 20 | { | 21 | 21 | /// <summary> | 22 | | - /// Basic template algorithm simply initializes the date range and cash | | 22 | + /// Algorithm demonstrating FOREX asset types and requesting history on them in bulk. As FOREX uses | | 23 | + /// QuoteBars you should request slices or | 23 | 24 | /// </summary> | | 25 | + /// <meta name="tag" content="using data" /> | | 26 | + /// <meta name="tag" content="history and warm up" /> | | 27 | + /// <meta name="tag" content="history" /> | | 28 | + /// <meta name="tag" content="forex" /> | 24 | 29 | public class BasicTemplateForexAlgorithm : QCAlgorithm | 25 | 30 | { | 26 | 31 | /// <summary> | @@ -32,9 +37,9 @@ public override void Initialize() | 32 | 37 | SetEndDate(2013, 10, 11); //Set End Date | 33 | 38 | SetCash(100000); //Set Strategy Cash | 34 | 39 | // Find more symbols here: http://quantconnect.com/data | 35 | | - AddForex("EURUSD", Resolution.Minute); | 36 | | - AddForex("GBPUSD", Resolution.Minute); | 37 | | - AddForex("EURGBP", Resolution.Minute); | | 40 | + AddForex("EURUSD"); | | 41 | + AddForex("GBPUSD"); | | 42 | + AddForex("EURGBP"); | 38 | 43 |
| 39 | 44 | History(5, Resolution.Daily); | 40 | 45 | History(5, Resolution.Hour); | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/BasicTemplateFuturesAlgorithm.cs +12-7Lines changed: 12 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 17 | 17 | using System; | 18 | 18 | using System.Linq; | 19 | 19 | using QuantConnect.Data; | 20 | | -using QuantConnect.Data.Market; | 21 | 20 | using QuantConnect.Orders; | 22 | 21 | using QuantConnect.Securities; | 23 | 22 |
| 24 | 23 | namespace QuantConnect.Algorithm.CSharp | 25 | 24 | { | 26 | 25 | /// <summary> | 27 | | - /// This example demonstrates how to add futures for a given underlying. | 28 | | - /// It also shows how you can prefilter contracts easily based on expirations. | 29 | | - /// It also shows how you can inspect the futures chain to pick a specific contract to trade. | | 26 | + /// This example demonstrates how to add futures for a given underlying asset. | | 27 | + /// It also shows how you can prefilter contracts easily based on expirations, and how you | | 28 | + /// can inspect the futures chain to pick a specific contract to trade. | 30 | 29 | /// </summary> | | 30 | + /// <meta name="tag" content="using data" /> | | 31 | + /// <meta name="tag" content="benchmarks" /> | | 32 | + /// <meta name="tag" content="futures" /> | 31 | 33 | public class BasicTemplateFuturesAlgorithm : QCAlgorithm | 32 | 34 | { | 33 | 35 | // S&P 500 EMini futures | @@ -38,6 +40,9 @@ public class BasicTemplateFuturesAlgorithm : QCAlgorithm | 38 | 40 | private const string RootGold = Futures.Metals.Gold; | 39 | 41 | public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.USA); | 40 | 42 |
| | 43 | + /// <summary> | | 44 | + /// Initialize your algorithm and add desired assets. | | 45 | + /// </summary> | 41 | 46 | public override void Initialize() | 42 | 47 | { | 43 | 48 | SetStartDate(2013, 10, 07); | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/BasicTemplateFuturesConsolidationAlgorithm.cs +10-3Lines changed: 10 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 23 | 23 |
| 24 | 24 | namespace QuantConnect.Algorithm.CSharp | 25 | 25 | { | | 26 | + /// <summary> | | 27 | + /// A demonstration of consolidating futures data into larger bars for your algorithm. | | 28 | + /// </summary> | | 29 | + /// <meta name="tag" content="using data" /> | | 30 | + /// <meta name="tag" content="benchmarks" /> | | 31 | + /// <meta name="tag" content="consolidating data" /> | | 32 | + /// <meta name="tag" content="futures" /> | 26 | 33 | public class BasicTemplateFuturesConsolidationAlgorithm : QCAlgorithm | 27 | 34 | { | 28 | 35 | private const string RootSP500 = Futures.Indices.SP500EMini; | |
Collapse file Copy file name to clipboardExpand all lines: Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs +9-6Lines changed: 9 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* | 2 | 2 | * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | 3 | 3 | * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | 4 | | - * | 5 | | - * Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | + * | | 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 6 | 6 | * you may not use this file except in compliance with the License. | 7 | 7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | 8 | | - * | | 8 | + * | 9 | 9 | * Unless required by applicable law or agreed to in writing, software | 10 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 17 | 17 | using System; | 18 | 18 | using System.Linq; | 19 | 19 | using QuantConnect.Data; | 20 | | -using QuantConnect.Data.Market; | 21 | 20 | using QuantConnect.Orders; | 22 | 21 | using QuantConnect.Securities; | 23 | 22 | using QuantConnect.Data.UniverseSelection; | @@ -26,9 +25,13 @@ namespace QuantConnect.Algorithm.CSharp | 26 | 25 | { | 27 | 26 | /// <summary> | 28 | 27 | /// This example demonstrates how to get access to futures history for a given root symbol. | 29 | | - /// It also shows how you can prefilter contracts easily based on expirations. | 30 | | - /// It also shows how you can inspect the futures chain to pick a specific contract to trade. | | 28 | + /// It also shows how you can prefilter contracts easily based on expirations, and inspect the futures | | 29 | + /// chain to pick a specific contract to trade. | 31 | 30 | /// </summary> | | 31 | + /// <meta name="tag" content="using data" /> | | 32 | + /// <meta name="tag" content="history and warm up" /> | | 33 | + /// <meta name="tag" content="history" /> | | 34 | + /// <meta name="tag" content="futures" /> | 32 | 35 | public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm | 33 | 36 | { | 34 | 37 | // S&P 500 EMini futures | |
|