-
Notifications
You must be signed in to change notification settings - Fork 9
/
BasicTemplateFrameworkAlgorithm.cs
65 lines (56 loc) · 2.26 KB
/
BasicTemplateFrameworkAlgorithm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using QuantConnect;
using QuantConnect.Algorithm;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Risk;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Configuration;
using QuantConnect.Orders;
namespace Algorithm
{
/// <summary>
/// Basic template framework algorithm uses framework components to define the algorithm.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="using quantconnect" />
/// <meta name="tag" content="trading and orders" />
public class BasicTemplateFrameworkAlgorithm : 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()
{
// Set requested data resolution
UniverseSettings.Resolution = Resolution.Minute;
// Note: Config.GetInt( "LBL-minute-resolution" ) is available to use for consolidators
// Set start and end date
SetStartDate( DateTime.Parse( Config.Get( "LBL-start-date" ) ) );
SetEndDate( DateTime.Parse( Config.Get( "LBL-end-date" ) ) );
// Set universe
SetUniverseSelection( new ManualUniverseSelectionModel( QuantConnect.Symbol.Create( Config.Get( "LBL-symbol" ), SecurityType.Forex, Market.Oanda ) ) );
// Get alpha parameters
int fastEma = Config.GetInt( "LBL-ema-fast" );
int slowEma = Config.GetInt( "LBL-ema-slow" );
// Initialise available alphas
var availableAlphas = new IAlphaModel[]{
new EmaCrossAlphaModel( fastEma, slowEma, Resolution.Minute )
};
// Set the alpha, for now we're assuming "ALL" has been passed
if ( Config.Get( "LBL-alpha-model-name" ) == "ALL" )
SetAlpha( new CompositeAlphaModel( availableAlphas ) );
// Set remaining models
SetPortfolioConstruction( new EqualWeightingPortfolioConstructionModel() );
SetExecution( new ImmediateExecutionModel() );
SetRiskManagement( new NullRiskManagementModel() );
}
public override void OnOrderEvent( OrderEvent orderEvent )
{
if ( orderEvent.Status.IsFill() ) {
Debug( $"Purchased Stock: {orderEvent.Symbol}" );
}
}
}
}