Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
15.562%
Drawdown
30.400%
Expectancy
0
Net Profit
165.453%
Sharpe Ratio
0.896
Probabilistic Sharpe Ratio
32.312%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.152
Beta
0.005
Annual Standard Deviation
0.17
Annual Variance
0.029
Information Ratio
0.146
Tracking Error
0.234
Treynor Ratio
28.923
Total Fees
$0.00
from QuantConnect.Python import *
from QuantConnect.Python import PythonData
from QuantConnect.Data import SubscriptionDataSource

import numpy as np
from datetime import datetime, timedelta

class CustomDataBitcoinAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2013, 9, 3)
        self.SetCash(100000)

        # Define the symbol and "type" of our generic data:
        if not self.LiveMode:
            self.AddData(AAPL, "AAPL")
        else:
            self.AddEquity('AAPL', Resolution.Minute)


    def OnData(self, data):
        # if not data.ContainsKey("AAPL"): return

        if not self.Portfolio.Invested:
            self.SetHoldings("AAPL", 1)
            self.Log('bought apple')

        # self.Log("AAPL Bar OHLCV: {0}, {1}, {2}, {3}, {4}".format(data['AAPL'].Open,
        #                                                          data['AAPL'].High,
        #                                                          data['AAPL'].Low,
        #                                                          data['AAPL'].Close,
        #                                                          data['AAPL'].Volume))



class AAPL(PythonData):
    
    def GetSource(self, config, date, isLiveMode):
        if isLiveMode:
            return

        return SubscriptionDataSource("https://www.dropbox.com/s/3qly3rdwkfeju8l/EOD%20AAPL.csv?dl=1", SubscriptionTransportMedium.RemoteFile);


    def Reader(self, config, line, date, isLiveMode):
        equity = AAPL()
        equity.Symbol = config.Symbol

        if isLiveMode:
            return None



        # Example Line Format:
        # Date        Open     High     Low       Close     Volume    Dividend    Split    Adj_Open       Adj_High       Adj_Low        Adj_Close     Adj_Volume
        # 9/3/2013    493.1    500.6    487.35    488.58    11854600  0           1        62.70198278    63.65567345    61.97081993    62.1272252    82982200

        if not (line.strip() and line[0].isdigit()): return None

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

            # If adj. close price is zero, return None
            value = data[11]
            if value == 0: return None

            equity.Time = datetime.strptime(data[0], "%m/%d/%Y") + timedelta(1)
            equity.Value = value
            equity["Open"] = float(data[8])
            equity["High"] = float(data[9])
            equity["Low"] = float(data[10])
            equity["Close"] = float(data[11])
            equity["Volume"] = float(data[12])
            return equity;

        except ValueError:
            # Do nothing, possible error in json decoding
            return None