Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
70.633%
Drawdown
28.000%
Expectancy
0
Net Profit
34.927%
Sharpe Ratio
1.569
Probabilistic Sharpe Ratio
55.658%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.782
Beta
-0.378
Annual Standard Deviation
0.473
Annual Variance
0.224
Information Ratio
0.908
Tracking Error
0.705
Treynor Ratio
-1.963
Total Fees
$0.00
from datetime import date, timedelta, datetime

class CustomDataYahooAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetCash(100000)

        # Define the symbol and "type" of our generic data:
        self.AddData(Yahoo, "AAPL")
        self.AddData(Yahoo, "MSFT")


    def OnData(self, data):
        if 'MSFT' not in data: return

        close = data["MSFT"].Value

        if not self.Portfolio.Invested:
            self.SetHoldings("MSFT", 1)
            self.Debug(f"Buying MSFT 'Shares': MSFT: {close}")

class Yahoo(PythonData):
    '''Custom Data Type using Yahoo Finance files saved in Dropbox'''

    def GetSource(self, config, date, isLiveMode):
        # Use a Dictionary for each file in Dropbox keyed by the ticker
        sources = {
            'MSFT': "https://www.dropbox.com/s/qjfem6mw5cpozdw/MSFT.csv?dl=1",
            'AAPL': "https://www.dropbox.com/s/ok4d5hzrkozt41l/AAPL.csv?dl=1"
            }
            
        return SubscriptionDataSource(sources[config.Symbol.Value], SubscriptionTransportMedium.RemoteFile);


    def Reader(self, config, line, date, isLiveMode):
        obj = Yahoo()
        obj.Symbol = config.Symbol

        # Example Line Format:
        # Date      Open   High    Low     Close   Adj Close (BTC)    Volume 
        # 2011-09-13 5.8    6.0     5.65    5.97    58.37138238,    346.0973893944
        if not (line.strip() and line[0].isdigit()): return None

        try:
            data = line.split(',')

            # If value is zero, return None
            value = float(data[5])
            if value == 0: return None

            obj.Time = datetime.strptime(data[0], "%Y-%m-%d")
            obj.EndTime = obj.Time + timedelta(1)
            obj.Value = value
            obj["Open"] = float(data[1])
            obj["High"] = float(data[2])
            obj["Low"] = float(data[3])
            obj["Close"] = float(data[4])
            obj["AdjClose"] = value
            obj["Volume"] = float(data[6])
            return obj;

        except:
            return None