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
-3.906
Tracking Error
0.203
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
from AlgorithmImports import *

class CoinAPIDataAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 6, 25)
        self.SetEndDate(2020, 7, 5)

        symbols = ["AAPL", "MSFT"]
        self.symbols = [self.AddEquity(ticker, Resolution.Daily).Symbol for ticker in symbols]

        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.CoarseFilterFunction, self.FineFilterFunction)

    def CoarseFilterFunction(self, coarse):
        return [x.Symbol for x in coarse if x.Symbol in self.symbols]

    def FineFilterFunction(self, fine):
        return [x.Symbol for x in fine]

    def OnData(self, data):
        fundamentals = ["ValuationRatios.SustainableGrowthRate", "ValuationRatios.PayoutRatio"]

        #setting empty dataframe that we can concat with
        dataframe = pd.DataFrame()

        #Get the returns of the stocks, and get them shaped proberly
        dataframe = self.History(self.symbols, 10, Resolution.Daily)
        dataframe = dataframe.drop_duplicates().close.unstack(level=0)
        dataframe = dataframe.iloc[0] / dataframe.iloc[-1]
        dataframe.name = 'returns'

        fundamental_dataframe = pd.DataFrame()

        #we need to get the symbols and symbol object, so we can set the name in the dataframe, and also get the fundamental value (ticker = setting name)
        for symbol in self.symbols:
            fundamental = self.Securities[symbol].Fundamentals
            if not fundamental: continue

            ratio =  [fundamental.ValuationRatios.SustainableGrowthRate,
                            fundamental.ValuationRatios.PayoutRatio]

            # Use the SID as index to ensure same naming to concatenate the dataframe
            ratio = pd.DataFrame([ratio], index=[str(symbol.ID)], columns=fundamentals)

            fundamental_dataframe = pd.concat([ratio, fundamental_dataframe], axis=0)

        dataframe = pd.concat([fundamental_dataframe, dataframe.T], axis=1)
        
        self.Log(dataframe)