Overall Statistics
Total Trades
58
Average Win
2.99%
Average Loss
-1.39%
Compounding Annual Return
18.571%
Drawdown
7.600%
Expectancy
0.464
Net Profit
20.975%
Sharpe Ratio
0.774
Sortino Ratio
0.998
Probabilistic Sharpe Ratio
60.557%
Loss Rate
54%
Win Rate
46%
Profit-Loss Ratio
2.15
Alpha
0.051
Beta
0.191
Annual Standard Deviation
0.102
Annual Variance
0.01
Information Ratio
-0.523
Tracking Error
0.132
Treynor Ratio
0.413
Total Fees
$58.00
Estimated Strategy Capacity
$130000000.00
Lowest Capacity Asset
TLT SGNKIKYGE9NP
Portfolio Turnover
7.13%
# region imports
from AlgorithmImports import *
from tlt import *
from sym2 import *

# endregion

class UglyBluePig(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2023, 1, 1)
        self.SetCash(10000)
        self.leverage = 1
        
        self.spy =self.AddEquity("SPY", Resolution.Hour).Symbol
        self.sym1 =self.AddEquity("TLT", Resolution.Daily).Symbol
        self.sym2 =self.AddEquity("QQQ", Resolution.Daily).Symbol

        # Percent of each stock to hold and Supertrend params. These params are optimized thru backtesting
        self.pct = .5
        sym1Per = 4
        sym1Mult = 1.75
        sym2Per = 3
        sym2Mult = 3.25

        self.st1 = self.STR(self.sym1, sym1Per, sym1Mult, MovingAverageType.LinearWeightedMovingAverage)
        self.st2 = self.STR(self.sym2, sym2Per, sym2Mult, MovingAverageType.LinearWeightedMovingAverage)
        self.SetWarmup(5, Resolution.Daily)
     

    def OnData(self, data: Slice):
        
        # Call to second algo
        self.invested = [ x.Symbol.Value for x in self.Portfolio.Values if x.Invested ]
        #ugly_blue_pig = UglyBluePig()
        sym1 = Sym1(self)
        sym2 = Sym2(self)
        if self.Time.hour == 11:
            sym1.Call_a()
            sym2.Call_a()

         
        # Calll to main algo
 




       
        
   
#region imports
#from AlgorithmImports import *
        

class Sym2:
    def __init__(self, algo):
        self.algo=algo

    def Call_a(self):
        #self.algo.AddEquity("QQQ", Resolution.Hour)
        invested = [ x.Symbol.Value for x in self.algo.Portfolio.Values if x.Invested ] 
        self.algo.Log("invested B: " + str(self.algo.invested))
        profit = self.algo.Portfolio[self.algo.sym2].UnrealizedProfitPercent*100
        self.algo.Log("{} Unrealized profit %: {:.2f}".format(self.algo.Time,profit))
        long = self.algo.Securities[self.algo.sym2].Price > self.algo.st2.Current.Value
        shares = self.algo.Portfolio[self.algo.sym2].Quantity
        maxShares = round(self.algo.Portfolio.TotalPortfolioValue * self.algo.pct/self.algo.Securities[self.algo.sym2].Price)
        if long:
            if shares == 0: # Not invested
                self.algo.Log("Going long {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym2].Symbol))
                self.algo.MarketOrder(self.algo.sym2, maxShares)
            elif shares < 0:
                self.algo.Log ("Closing short {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym2].Symbol))
                self.algo.SetHoldings(self.algo.sym2, 0)
        else:
            if shares == 0: # Not invested
                self.algo.Log("Going short {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym2].Symbol))
                self.algo.MarketOrder(self.algo.sym2, -maxShares)
            elif shares > 0:
                self.algo.Log ("Closing long {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym2].Symbol))
                self.algo.SetHoldings(self.algo.sym2, 0)
   
        if profit >15 or profit < -7: 
            self.algo.SetHoldings(self.algo.sym2,0)
            self.algo.Log("Exited because of {:.2f} profit".format(profit))
        return 2
#region imports
#from AlgorithmImports import *
        

class Sym1:
    def __init__(self, algo):
        self.algo=algo

    def Call_a(self):
        #self.algo.AddEquity("QQQ", Resolution.Hour)
        invested = [ x.Symbol.Value for x in self.algo.Portfolio.Values if x.Invested ] 
        self.algo.Log("invested B: " + str(self.algo.invested))
        profit = self.algo.Portfolio[self.algo.sym1].UnrealizedProfitPercent*100
        self.algo.Log("{} Unrealized profit %: {:.2f}".format(self.algo.Time,profit))
        long = self.algo.Securities[self.algo.sym1].Price > self.algo.st1.Current.Value
        shares = self.algo.Portfolio[self.algo.sym1].Quantity
        maxShares = round(self.algo.Portfolio.TotalPortfolioValue * self.algo.pct/self.algo.Securities[self.algo.sym1].Price)
        if long:
            if shares == 0: # Not invested
                self.algo.Log("Going long {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym1].Symbol))
                self.algo.MarketOrder(self.algo.sym1, maxShares)
            elif shares < 0:
                self.algo.Log ("Closing short {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym1].Symbol))
                self.algo.SetHoldings(self.algo.sym1, 0)
        else:
            if shares == 0: # Not invested
                self.algo.Log("Going short {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym1].Symbol))
                self.algo.MarketOrder(self.algo.sym1, -maxShares)
            elif shares > 0:
                self.algo.Log ("Closing long {} shares of {}".format(maxShares, self.algo.Securities[self.algo.sym1].Symbol))
                self.algo.SetHoldings(self.algo.sym1, 0)
   
        if profit >15 or profit < -7: 
            self.algo.SetHoldings(self.algo.sym1,0)
            self.algo.Log("Exited because of {:.2f} profit".format(profit))
        return 2