| Overall Statistics |
|
Total Trades 2 Average Win 1.75% Average Loss 0% Compounding Annual Return 32.970% Drawdown 1.200% Expectancy 0 Net Profit 1.746% Sharpe Ratio 3.55 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.223 Beta -0.021 Annual Standard Deviation 0.062 Annual Variance 0.004 Information Ratio 0.553 Tracking Error 0.106 Treynor Ratio -10.504 Total Fees $2.00 |
using System;
using QuantConnect.Securities;
using QuantConnect.Orders.Fees;
using QuantConnect.Notifications;
using QuantConnect.Orders;
using QuantConnect.Data.Market;
using QuantConnect.Packets;
using QuantConnect.Util;
using System.Reflection;
using QuantConnect.Scheduling;
using System.Linq;
using System.Net;
namespace QuantConnect
{
public class BasicTemplateAlgorithm : QCAlgorithm
{
string symbol;
int _holdings;
decimal _pct;
bool first = true;
static string globalString;
static decimal _symPrice;
static decimal _profits;
bool ready = false;
const decimal StopLossPercent = 0.003m;
private decimal highestPrice = 0.0m;
private OrderTicket CurrentOrder;
private OrderTicket StopLoss;
string time;
string date;
string utctime;
string utcdate;
const string url = @"https://www.dropbox.com/s/qx8hs2q81im9zmu/SymbolToday.csv?dl=1";
public override void Initialize()
{
SetBrokerageModel(BrokerageName.TradierBrokerage, AccountType.Cash);
SetStartDate(2016, 03, 7);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetCash(2750);
_pct = Portfolio.Cash/3 * .03m;
//Schedule.Event().EveryDay().At(9,35).Run(() =>
//{
using (var client = new WebClient())
{
var file = client.DownloadString(url);
var csv = file.Split(',');
var csvdatetime = csv[4];
symbol = csv[1];
DateTime dt = DateTime.Parse(csvdatetime);
time = dt.ToString("HH:mm:ss");
date = dt.Date.ToString("MM/dd/yyyy");
utctime = UtcTime.ToString("HH:mm:ss");
utcdate = UtcTime.Date.ToString("MM/dd/yyyy");
Log("t"+time);
Log("d"+date);
Log("ut"+utctime);
Log("ud"+utcdate);
}
AddSecurity(SecurityType.Equity, symbol, Resolution.Second, fillDataForward: true,
extendedMarketHours: false,
leverage: 1);
//});
}
//public void PostInitialize()
//{
//}
public void OnData(TradeBars data)
{
_symPrice = data[symbol].Price;
_profits = Portfolio.TotalUnrealizedProfit;
var shareCount = CalculateOrderQuantity(symbol, 1m/3);
//if(date = utcdate)
//{
if(first)
{
first = false;
CurrentOrder = Order(symbol, shareCount);
StopLoss = StopMarketOrder(symbol, -shareCount, _symPrice * (1m - .03m));
Notify.Sms("+15126454560", "Buy " + globalString);
}
//}
if (Portfolio.HoldStock)
{
if (_symPrice > highestPrice && _profits > _pct)
{
highestPrice = _symPrice;
StopLoss.Update(new UpdateOrderFields{ StopPrice = _symPrice * (1m - StopLossPercent) });
}
Schedule.Event().EveryDay().BeforeMarketClose(symbol, 1).Run(() =>
{
Liquidate();
});
}
string messageString = String.Format("{0} \nTime: {1} \nPrice: {2} \nProfit: {3} \nHigh {4}",
symbol, time, _symPrice.ToString(), _profits, StopLoss.ToString());
globalString = messageString;
}
}
}