Overall Statistics Total Trades36Average Win0.12%Average Loss-0.02%Compounding Annual Return36.843%Drawdown1.200%Expectancy3.673Net Profit1.263%Sharpe Ratio4.136Loss Rate33%Win Rate67%Profit-Loss Ratio6.01Alpha0.122Beta0.491Annual Standard Deviation0.055Annual Variance0.003Information Ratio0.222Tracking Error0.055Treynor Ratio0.463Total Fees\$127.19
```import math
import numpy as np
import pandas as pd
import statistics
import talib

from datetime import datetime, timedelta

class BasicTemplateAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetCash(100000)
self.SetStartDate(2017, 1, 1)
self.SetEndDate(2017, 1, 15)
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
self.Portfolio.MarginModel = MarginCallModel.Null

# Add securities and indicators
self.bonds = ["SHY","IEF"]
for s in self.bonds:

self.Schedule.On(self.DateRules.EveryDay("SHY"),
self.TimeRules.At(9, 40), Action(self.Rebalance))

self.Schedule.On(self.DateRules.EveryDay("SHY"),
self.TimeRules.At(13, 50), Action(self.Rebalance2))

# Run Portfolio Stats
self.Schedule.On(self.DateRules.EveryDay("SHY"),
self.TimeRules.At(16, 00), Action(self.PortfolioStats))

# Establish day trading leverage at 4x

# Days to warm up the indicators
self.SetWarmup(timedelta(2))

def OnData(self, slice):
pass

def Rebalance(self):

for s in self.bonds:
price = round(self.Securities[s].Price, 2)
self.Log("price:{}" .format(price))
self.SetHoldings(s, 1.5)

def Rebalance2(self):

for s in self.bonds:
price = round(self.Securities[s].Price, 2)
self.Log("price:{}" .format(price))
self.SetHoldings(s, 0.9)

def PortfolioStats(self):

port_val = self.Portfolio.TotalPortfolioValue

for s in self.bonds:
actual_weight = self.Portfolio[s].Quantity * self.Securities[s].Price / port_val
self.Log("{} {}".format(s, round(actual_weight, 3)))
account_leverage = self.Portfolio.TotalAbsoluteHoldingsCost / port_val
self.Log("{}%".format(round(account_leverage,3) * 100))```