using System;
using System.Collections;
using System.Collections.Generic;
using QuantConnect.Securities;
using QuantConnect.Models;
namespace QuantConnect {
/***************************************************************************
INITIALIZING ALGORITHMS
The algorithm settings are entirely configured from code so you can work
on them at home in your own coding environment. There are three required
settings to initialize: Data Required, Strategy Cash, and Date Range
These must be set in the Initialize() method.
WARNING! If you don't enter values for date and cash, the default
values are:
Cash:$100.000
Start Date: Jan 1st, 2008
End Date: Yesterday
THIS IS AN EXAMPLE ALGORITHM FROM THE QUANTCONNECT'S API DOCUMENTATION
***************************************************************************/
//Your Algorithm Class
public class InitializingAlgorithmExample : QCAlgorithm
{
string[] securities = {"MSFT", "SPY", "EURUSD", "EURGBP"};
//Initialize the data and resolution you require for your strategy:
public override void Initialize()
{
//Add Securities, determine their resolution, if you want fill
//forward, the leverage and if you want to operate out of market hours
AddSecurity(SecurityType.Equity, "MSFT", Resolution.Minute, true, 2, false);
AddSecurity(SecurityType.Equity, "SPY", Resolution.Second, true, false);
AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick, true, 20, false);
AddSecurity(SecurityType.Forex, "EURGBP", Resolution.Minute, true, false);
//Set Strategy Starting Capital to $100,000 (in USD). Be careful with fees!
SetCash(100000);
//Initialize the start & end dates for simulation. Format: YYYY, M, D
SetStartDate(2014, 6, 1);
SetEndDate(2014, 7, 1);
}
//Purchase 100 of every security at the begining and sell it at the end of simulation
public void OnData(TradeBars securityData)
{
//Always good practice to use try/catch in case the algorithm fails
try
{
//Because we're doing both equities and FX; wait for equities market open to trade:
if (Securities["MSFT"].Exchange.ExchangeOpen == false) return;
if (Securities["SPY"].Exchange.ExchangeOpen == false) return;
//Our strategy only buy securities at the begining, when we dont have any.
//this will be explained in the following sections of the API
foreach (var security in securities)
{
if (!Portfolio[security].HoldStock)
{
Order(security, 100);
}
}
}
catch(Exception err)
{
Error("OnData Err: " + err.Message);
}
}
/***************************************************************************
NOTICE: This algorithm is just an example, it is not optimized at all:
We are mixing stocks and forex, minute daily & tick data, so it will
take a while to process.
***************************************************************************/
}
}