Overall Statistics
Total Orders
8
Average Win
11.09%
Average Loss
-11.19%
Compounding Annual Return
21.704%
Drawdown
18.700%
Expectancy
0.493
Start Equity
100000
End Equity
121748.08
Net Profit
21.748%
Sharpe Ratio
0.977
Sortino Ratio
0.765
Probabilistic Sharpe Ratio
47.452%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
0.99
Alpha
0.101
Beta
0.328
Annual Standard Deviation
0.157
Annual Variance
0.025
Information Ratio
-0.035
Tracking Error
0.227
Treynor Ratio
0.469
Total Fees
$12.66
Estimated Strategy Capacity
$690000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
2.17%
# region imports
from AlgorithmImports import *
# endregion
class FormalFluorescentYellowArmadillo(QCAlgorithm):

    def Initialize(self):
        self.set_start_date(2020, 1, 1)  # Set Start Date
        self.set_end_date(2021, 1, 1) # Set End Date
        self.set_cash(100000)  # Set Strategy Cash
        
        spy = self.add_equity("SPY", Resolution.DAILY)
        # self.AddForex, self.AddFuture...
        
        spy.SetDataNormalizationMode(DataNormalizationMode.RAW)
        
        self.spy = spy.Symbol
        
        self.set_benchmark("SPY")
        self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE, AccountType.MARGIN)
        
        self.entryPrice = 0
        self.period = timedelta(31)
        self.nextEntryTime = self.time


    def OnData(self, data):
        if not self.spy in data:
            return
        
        # price = data.Bars[self.spy].Close
        if data[self.spy] is not None:
            price = data[self.spy].Close
        # price = self.Securities[self.spy].Close
        
        if not self.portfolio.invested:
            if self.nextEntryTime <= self.time:
                self.set_holdings(self.spy, 1)
                # self.MarketOrder(self.spy, int(self.Portfolio.Cash / price) )
                self.log("BUY SPY @" + str(price))
                self.entryPrice = price
        
        elif self.entryPrice * 1.1 < price or self.entryPrice * 0.90 > price:
            self.liquidate()
            self.log("SELL SPY @" + str(price))
            self.nextEntryTime = self.time + self.period