Skip to content

Commit

Permalink
Merge branch 'master' into minor-algo-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredbroad committed Sep 20, 2017
2 parents 52d0baa + accb3d8 commit ffec40e
Show file tree
Hide file tree
Showing 30 changed files with 1,156 additions and 84 deletions.
24 changes: 14 additions & 10 deletions Algorithm.CSharp/AddRemoveSecurityRegressionAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -14,16 +14,18 @@
*/

using System;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Orders;

namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash
/// This algorithm demonstrates the runtime addition and removal of securities from your algorithm.
/// With LEAN it is possible to add and remove securities after the initialization.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="assets" />
/// <meta name="tag" content="regression test" />
public class AddRemoveSecurityRegressionAlgorithm : QCAlgorithm
{
private DateTime lastAction;
Expand All @@ -40,8 +42,6 @@ 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

AddSecurity(SecurityType.Equity, "SPY");
}

Expand Down Expand Up @@ -78,15 +78,19 @@ public void OnData(TradeBars data)
}
}

/// <summary>
/// Order events are triggered on order status changes. There are many order events including non-fill messages.
/// </summary>
/// <param name="orderEvent">OrderEvent object with details about the order status</param>
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.Status == OrderStatus.Submitted)
{
Console.WriteLine(Time + ": Submitted: " + Transactions.GetOrderById(orderEvent.OrderId));
Debug(Time + ": Submitted: " + Transactions.GetOrderById(orderEvent.OrderId));
}
if (orderEvent.Status.IsFill())
{
Console.WriteLine(Time + ": Filled: " + Transactions.GetOrderById(orderEvent.OrderId));
Debug(Time + ": Filled: " + Transactions.GetOrderById(orderEvent.OrderId));
}
}
}
Expand Down
26 changes: 18 additions & 8 deletions Algorithm.CSharp/BasicTemplateAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -18,12 +18,15 @@
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash
/// 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" />
/// <meta name="tag" content="regression test" />
public class BasicTemplateAlgorithm : QCAlgorithm
{
private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);

/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
Expand All @@ -32,8 +35,15 @@ 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);
// Forex, CFD, Equities Resolutions: Tick, Second, Minute, Hour, Daily.
// Futures Resolution: Tick, Second, Minute
// Options Resolution: Minute Only.
AddEquity("SPY", Resolution.Minute);

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

/// <summary>
Expand All @@ -44,7 +54,7 @@ public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
SetHoldings(_spy, 1);
SetHoldings("SPY", 1);
Debug("Purchased Stock");
}
}
Expand Down
15 changes: 8 additions & 7 deletions Algorithm.CSharp/BasicTemplateDailyAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -18,12 +18,13 @@
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash
/// Demonstration of requesting daily resolution data for US Equities.
/// This is a simple regression test algorithm using a skeleton algorithm and requesting daily data.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="regression test" />
public class BasicTemplateDailyAlgorithm : QCAlgorithm
{
private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);

/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
Expand All @@ -44,7 +45,7 @@ public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
SetHoldings(_spy, 1);
SetHoldings("SPY", 1);
Debug("Purchased Stock");
}
}
Expand Down
15 changes: 8 additions & 7 deletions Algorithm.CSharp/BasicTemplateFillForwardAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -18,12 +18,13 @@
namespace QuantConnect.Algorithm.Examples
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash
/// Skeleton algorithm demonstrating filling forward data through gaps and inconsistent data. By default LEAN fills the previous bar forward
/// so you get regular bars.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="regression test" />
public class BasicTemplateFillForwardAlgorithm : QCAlgorithm
{
private Symbol _asur = QuantConnect.Symbol.Create("ASUR", SecurityType.Equity, Market.USA);

/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
Expand All @@ -44,7 +45,7 @@ public void OnData(TradeBars data)
{
if (!Portfolio.Invested)
{
SetHoldings(_asur, 1);
SetHoldings("ASUR", 1);
Debug("Purchased Stock");
}
}
Expand Down
13 changes: 9 additions & 4 deletions Algorithm.CSharp/BasicTemplateForexAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -19,8 +19,13 @@
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash
/// Algorithm demonstrating FOREX asset types and requesting history on them in bulk. As FOREX uses
/// QuoteBars you should request slices or
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="history and warm up" />
/// <meta name="tag" content="history" />
/// <meta name="tag" content="forex" />
public class BasicTemplateForexAlgorithm : QCAlgorithm
{
/// <summary>
Expand Down
19 changes: 12 additions & 7 deletions Algorithm.CSharp/BasicTemplateFuturesAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -17,17 +17,19 @@
using System;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Orders;
using QuantConnect.Securities;

namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to add futures for a given underlying.
/// It also shows how you can prefilter contracts easily based on expirations.
/// It also shows how you can inspect the futures chain to pick a specific contract to trade.
/// This example demonstrates how to add futures for a given underlying asset.
/// It also shows how you can prefilter contracts easily based on expirations, and how you
/// can inspect the futures chain to pick a specific contract to trade.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesAlgorithm : QCAlgorithm
{
// S&P 500 EMini futures
Expand All @@ -38,6 +40,9 @@ public class BasicTemplateFuturesAlgorithm : QCAlgorithm
private const string RootGold = Futures.Metals.Gold;
public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.USA);

/// <summary>
/// Initialize your algorithm and add desired assets.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 07);
Expand Down
13 changes: 10 additions & 3 deletions Algorithm.CSharp/BasicTemplateFuturesConsolidationAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -23,6 +23,13 @@

namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// A demonstration of consolidating futures data into larger bars for your algorithm.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="consolidating data" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesConsolidationAlgorithm : QCAlgorithm
{
private const string RootSP500 = Futures.Indices.SP500EMini;
Expand Down
15 changes: 9 additions & 6 deletions Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs
@@ -1,11 +1,11 @@
/*
* 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");
*
* 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.
Expand All @@ -17,7 +17,6 @@
using System;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Data.UniverseSelection;
Expand All @@ -26,9 +25,13 @@ namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to get access to futures history for a given root symbol.
/// It also shows how you can prefilter contracts easily based on expirations.
/// It also shows how you can inspect the futures chain to pick a specific contract to trade.
/// It also shows how you can prefilter contracts easily based on expirations, and inspect the futures
/// chain to pick a specific contract to trade.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="history and warm up" />
/// <meta name="tag" content="history" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm
{
// S&P 500 EMini futures
Expand Down

0 comments on commit ffec40e

Please sign in to comment.