Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-1.031
Tracking Error
0.276
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# five day sma of vol
import numpy

class VAlgorithm(QCAlgorithmFramework):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        # self.SetEndDate(2021, 3, 1)
        self.spy = self.AddEquity("SPY", Resolution.Hour).Symbol
        self.lookbackSTD = 30  
        self.lookbackSMA = 5   
        self.SetWarmup(self.lookbackSTD + self.lookbackSMA, Resolution.Daily)
        
        self.std = self.STD(self.spy, self.lookbackSTD, Resolution.Daily) # standard deviation of returns over past [x] days
        self.stdAvg = IndicatorExtensions.SMA(self.std, self.lookbackSMA) # [x]-day moving average of standard deviation
        
        self.vol = 0
        self.volAvg = 0



    def OnEndOfDay(self):
        if self.IsWarmingUp or not self.stdAvg.IsReady: return
        
        # Calculate annualized volatility
        self.vol = self.std.Current.Value*np.sqrt(252)
        self.volAvg = self.stdAvg.Current.Value*np.sqrt(252)

        self.Plot("Indicators", "Vol", self.vol)
        self.Plot("Indicators", "Vol-Avg", self.volAvg)