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
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
from System.Drawing import Color

class Fundamentals(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2018, 7, 1)                       # the starting date for our backtest
        #self.SetEndDate(2020, 2, 1)                        # the ending date for our backtest (if no date, then it will test up until today)
        self.start_value = 5000                             # define the amount of starting cash
        self.SetCash(self.start_value)                      # initialize our wallet
        self.EQY = "MSFT"                                    # define the stock ticker
        self.stock = self.AddEquity(self.EQY, Resolution.Daily)          # add a stock to the list of those we want to trade, and how often to pull data
        #self.symbols = Symbol.Create(self.EQY, SecurityType.Equity, Market.USA)
        #self.symbols = Symbol.Create(self.EQY, SecurityType.Equity, Market.USA)
        
    def OnData(self, data):
        
        x = self.stock.FinancialStatements
        
        F = FScore(x.FinancialStatements.IncomeStatement.NetIncome.TwelveMonths, 
            x.FinancialStatements.CashFlowStatement.CashFlowFromContinuingOperatingActivities.TwelveMonths,
            x.OperationRatios.ROA.ThreeMonths, x.OperationRatios.ROA.OneYear,
            x.FinancialStatements.BalanceSheet.ShareIssued.ThreeMonths, x.FinancialStatements.BalanceSheet.ShareIssued.TwelveMonths,  
            x.OperationRatios.GrossMargin.ThreeMonths, x.OperationRatios.GrossMargin.OneYear,
            x.OperationRatios.LongTermDebtEquityRatio.ThreeMonths, x.OperationRatios.LongTermDebtEquityRatio.OneYear,
            x.OperationRatios.CurrentRatio.ThreeMonths, x.OperationRatios.CurrentRatio.OneYear,
            x.OperationRatios.AssetsTurnover.ThreeMonths, x.OperationRatios.AssetsTurnover.OneYear).ObjectiveScore()
            
        self.Log(self.EQY + " : " + str(F))
        
        
        # plotting stuff
        # self.SPY_candles.AddPoint(self.Time + timedelta(minutes=1), self.Securities[self.EQY].Open)
        # self.SPY_candles.AddPoint(self.Time + timedelta(minutes=2), self.Securities[self.EQY].High)
        # self.SPY_candles.AddPoint(self.Time + timedelta(minutes=3), self.Securities[self.EQY].Low)
        # self.SPY_candles.AddPoint(self.Time + timedelta(minutes=4), self.Securities[self.EQY].Close)
        self.Plot("F Score",self.EQY,F)
        
        
class FScore(object):
    def __init__(self, netincome, operating_cashflow, roa_current,
                 roa_past, issued_current, issued_past, grossm_current, grossm_past,
                 longterm_current, longterm_past, curratio_current, curratio_past,
                 assetturn_current, assetturn_past):
        self.netincome = netincome
        self.operating_cashflow = operating_cashflow
        self.roa_current = roa_current
        self.roa_past = roa_past
        self.issued_current = issued_current
        self.issued_past = issued_past
        self.grossm_current = grossm_current
        self.grossm_past = grossm_past
        self.longterm_current = longterm_current
        self.longterm_past = longterm_past
        self.curratio_current = curratio_current
        self.curratio_past = curratio_past
        self.assetturn_current = assetturn_current
        self.assetturn_past = assetturn_past

    def ObjectiveScore(self):
        fscore = 0
        fscore += np.where(self.netincome > 0, 1, 0)
        fscore += np.where(self.operating_cashflow > 0, 1, 0)
        fscore += np.where(self.roa_current > self.roa_past, 1, 0)
        fscore += np.where(self.operating_cashflow > self.roa_current, 1, 0)
        fscore += np.where(self.longterm_current <= self.longterm_past, 1, 0)
        fscore += np.where(self.curratio_current >= self.curratio_past, 1, 0)
        fscore += np.where(self.issued_current <= self.issued_past, 1, 0)
        fscore += np.where(self.grossm_current >= self.grossm_past, 1, 0)
        fscore += np.where(self.assetturn_current >= self.assetturn_past, 1, 0)
        return fscore