In [1]:
# You may need to install htmllib5,lxml, and BeautifulSoup4. In your terminal/command prompt run:

# conda install lxml
# conda install html5lib
# conda install BeautifulSoup4
# Then restart Jupyter Notebook. (or use pip install if you aren't using the Anaconda Distribution)

import numpy as np
import pandas as pd
import os.path
from datetime import datetime, timedelta

one_hour_ago = datetime.now() - timedelta(hours=1)
if os.path.exists("history.csv"):
    filetime = datetime.fromtimestamp(os.path.getctime("history.csv"))
    if filetime < one_hour_ago:
        histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
        histdata[0].to_csv('history.csv',index=False)
else:
    histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
    histdata[0].to_csv('history.csv',index=False)

df = pd.read_csv('history.csv').set_index('Ticker')
df.index.name=None

df[["Date","Catalyst"]] = df.Catalyst.str.extract('(?P<Date>[0-9]{2}\/[0-9]{2}\/[0-9]{4})(?P<Catalyst>.*)', expand=True)

df.loc["OCUL"]


Out[1]:
Drug Stage Catalyst Date
OCUL DEXTENZA Allergic conjunctivitis Phase 3 Phase 3 trial did not meet primary endpoint ... 06/06/2016
OCUL DEXTENZA Ocular inflammation and pain followi... Approved CRL July 25 2016 - due to manufacturing defi... 07/25/2016
OCUL DEXTENZA Ocular inflammation and pain followi... Approved CRL July 25 2016 - due to manufacturing defi... 07/11/2017
OCUL DEXTENZA Ocular inflammation and pain followi... Approved FDA approval announced December 3, 2018. 12/03/2018

In [469]:
# You may need to install htmllib5,lxml, and BeautifulSoup4. In your terminal/command prompt run:

# conda install lxml
# conda install html5lib
# conda install BeautifulSoup4
# Then restart Jupyter Notebook. (or use pip install if you aren't using the Anaconda Distribution)
import numpy as np
import pandas as pd
import os.path
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
from pandas.tseries.offsets import *
from pylab import text
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import quandl


# Quandl API key
quandl.ApiConfig.api_key = "UsYsv7dKGxHHQ5oURP4B"

# Some formatting
pd.set_option('display.max_colwidth', -1)
pd.set_option('display.max_seq_items', 2)

# Only pull fresh PDUFA data
three_weeks_ago = relativedelta(weeks=3)
one_week_ahead = relativedelta(weeks=1)
one_hour_ago = datetime.now() - timedelta(hours=1)
if os.path.exists("history.csv"):
    filetime = datetime.fromtimestamp(os.path.getctime("history.csv"))
    if filetime < one_hour_ago:
        histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
        histdata[0].to_csv('history.csv',index=False)
else:
    histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
    histdata[0].to_csv('history.csv',index=False)

# Create dataframe
df = pd.read_csv('history.csv').set_index('Ticker')
df.index.name=None
df[["Date","Catalyst"]] = df.Catalyst.str.extract('(?P<Date>[0-9]{2}\/[0-9]{2}\/[0-9]{4})(?P<Catalyst>.*)', expand=True)
df['Date'] = pd.to_datetime(df['Date'])
df["Past"] = df["Date"] - DateOffset(weeks=3)
df["Future"] = df["Date"] + DateOffset(weeks=1)

df
# Set stock ticker
stockpick="HALO"
dataset=str(f"WIKI/{stockpick}")
# Set variables for plot creation
length = len(df.loc[stockpick].index)
count = 0
fig, axes = plt.subplots(nrows=length, ncols=1,figsize=(16,length * 3))
fig.subplots_adjust(hspace=0, wspace=0)
allplots=[]

# Combine all data together into list of dataframes, iterate through each part of the list, plot each frame.
while (count < length):
    pasttime= df.loc[stockpick].iloc[count]["Past"]
    futuretime= df.loc[stockpick].iloc[count]["Future"]
    pdufa=df.loc[stockpick].iloc[count]["Date"]
    annotate = df.loc[stockpick].iloc[count]["Date"] + timedelta(days=1)
    stage = df.loc[stockpick].iloc[count]["Stage"]
    catalyst = df.loc[stockpick].iloc[count]["Catalyst"]
    drug = df.loc[stockpick].iloc[count]["Drug"]
    
    #Annotation
    tooltip = f"stage:{stage}  -{catalyst}\n{drug}"
    at = AnchoredText(tooltip,
                      prop=dict(size=10), frameon=True,
                      loc=2, 
                      )
    at.patch.set_boxstyle("round,pad=0.2,rounding_size=0.2")
    axes[count].add_artist(at)
    axes[count].margins(0.0, 0.5)
    #Get quandl data
    mydata = quandl.get(dataset,start_date=pasttime,end_date=futuretime)
    allplots.append(mydata)
#     axes[count].annotate('local max', xy=(pdufa, allplots[count]["Close"].max()), xytext=(annotate, (allplots[count]["Close"].max() - allplots[count]["Close"].min()) * 0.9 + allplots[count]["Close"].min()),
#             arrowprops=dict(facecolor='black', shrink=0.05, width=1, headwidth=5),)
    # Set y limit for notes
    axes[count].set_ylim(allplots[count]["Close"].min() * .99 , (allplots[count]["Close"].max()-allplots[count]["Close"].min()) * 0.5 + allplots[count]["Close"].max())
    axes[count].hlines(allplots[count]["Close"].max() * 1.01, allplots[count].head(1).index, allplots[count].tail(1).index, linestyle="-", lw=1, color='black')
    if count % 2 == 0:
        axes[count].set_facecolor((0.91, 0.91, 0.91))  

    axes[count].vlines(pdufa, allplots[count]["Close"].min() * .99, allplots[count]["Close"].max() * 1.01, linestyle="--", color='black')
    axes[count].plot(allplots[count].index,allplots[count]["Close"],c=np.random.rand(3,), lw=2, label=pdufa) 
    axes[count].axes.get_xaxis().set_visible(False) # remove x axis
    count = count + 1
plt.show()



In [54]:
# You may need to install htmllib5,lxml, and BeautifulSoup4. In your terminal/command prompt run:

# conda install lxml
# conda install html5lib
# conda install BeautifulSoup4
# Then restart Jupyter Notebook. (or use pip install if you aren't using the Anaconda Distribution)
import numpy as np
import pandas as pd
import os.path
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
from pandas.tseries.offsets import *
from pylab import text
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import quandl


# Quandl API key
quandl.ApiConfig.api_key = "UsYsv7dKGxHHQ5oURP4B"

# Some formatting
pd.set_option('display.max_colwidth', -1)
pd.set_option('display.max_seq_items', 2)

# Only pull fresh PDUFA data
three_weeks_ago = relativedelta(weeks=3)
one_week_ahead = relativedelta(weeks=1)
one_hour_ago = datetime.now() - timedelta(hours=1)
if os.path.exists("history.csv"):
    filetime = datetime.fromtimestamp(os.path.getctime("history.csv"))
    if filetime < one_hour_ago:
        histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
        histdata[0].to_csv('history.csv',index=False)
else:
    histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
    histdata[0].to_csv('history.csv',index=False)

# Create dataframe
df = pd.read_csv('history.csv').set_index('Ticker')
df.index.name=None
df[["Date","Catalyst"]] = df.Catalyst.str.extract('(?P<Date>[0-9]{2}\/[0-9]{2}\/[0-9]{4})(?P<Catalyst>.*)', expand=True)
df['Date'] = pd.to_datetime(df['Date'])
df["Past"] = df["Date"] - DateOffset(weeks=3)
df["Future"] = df["Date"] + DateOffset(weeks=1)

df
# Set stock ticker
stockpick="HALO"
dataset=str(f"WIKI/{stockpick}")
# Set variables for plot creation
length = len(df.loc[stockpick].index)
count = 0
allplots=[]

# Combine all data together into list of dataframes, iterate through each part of the list, plot each frame.
while (count < length):
    pasttime= df.loc[stockpick].iloc[count]["Past"]
    futuretime= df.loc[stockpick].iloc[count]["Future"]
    pdufa=df.loc[stockpick].iloc[count]["Date"]
    annotate = df.loc[stockpick].iloc[count]["Date"] + timedelta(days=1)
    stage = df.loc[stockpick].iloc[count]["Stage"]
    catalyst = df.loc[stockpick].iloc[count]["Catalyst"]
    drug = df.loc[stockpick].iloc[count]["Drug"]
    
    #Annotation
    #Get quandl data
    mydata = quandl.get(dataset,start_date=pasttime,end_date=futuretime)
    allplots.append(mydata)
    count = count + 1
# len(allplots[3].index) # 21
i=0
total = len(allplots[3].index) - 1

while (i < total):
    print(allplots[3].iloc[i]["Close"])
    n = i + 1
    while (n < total):  # see 14 - 8 = 1.0 !!!
        rangevalue=(allplots[3].iloc[n]["Close"] - allplots[3].iloc[i]["Close"])

        print(f"{n} - {i} = {rangevalue}")
        n=n + 1


#     print(allplots[3].iloc[i + 1]["Close"] - allplots[3].iloc[i]["Close"] )
    i = i + 1


13.65
1 - 0 = 0.11999999999999922
2 - 0 = -0.14000000000000057
3 - 0 = -0.33999999999999986
4 - 0 = 0.20999999999999908
5 - 0 = 1.0299999999999994
6 - 0 = 0.8899999999999988
7 - 0 = 0.7599999999999998
8 - 0 = -0.3600000000000012
9 - 0 = -0.16000000000000014
10 - 0 = -0.1899999999999995
11 - 0 = -0.120000000000001
12 - 0 = 0.6199999999999992
13 - 0 = 0.5600000000000005
14 - 0 = 0.6399999999999988
15 - 0 = -0.620000000000001
16 - 0 = -0.6899999999999995
17 - 0 = -0.6600000000000001
18 - 0 = -0.5700000000000003
19 - 0 = -0.75
13.77
2 - 1 = -0.2599999999999998
3 - 1 = -0.4599999999999991
4 - 1 = 0.08999999999999986
5 - 1 = 0.9100000000000001
6 - 1 = 0.7699999999999996
7 - 1 = 0.6400000000000006
8 - 1 = -0.4800000000000004
9 - 1 = -0.27999999999999936
10 - 1 = -0.3099999999999987
11 - 1 = -0.2400000000000002
12 - 1 = 0.5
13 - 1 = 0.4400000000000013
14 - 1 = 0.5199999999999996
15 - 1 = -0.7400000000000002
16 - 1 = -0.8099999999999987
17 - 1 = -0.7799999999999994
18 - 1 = -0.6899999999999995
19 - 1 = -0.8699999999999992
13.51
3 - 2 = -0.1999999999999993
4 - 2 = 0.34999999999999964
5 - 2 = 1.17
6 - 2 = 1.0299999999999994
7 - 2 = 0.9000000000000004
8 - 2 = -0.22000000000000064
9 - 2 = -0.019999999999999574
10 - 2 = -0.049999999999998934
11 - 2 = 0.019999999999999574
12 - 2 = 0.7599999999999998
13 - 2 = 0.7000000000000011
14 - 2 = 0.7799999999999994
15 - 2 = -0.4800000000000004
16 - 2 = -0.5499999999999989
17 - 2 = -0.5199999999999996
18 - 2 = -0.4299999999999997
19 - 2 = -0.6099999999999994
13.31
4 - 3 = 0.5499999999999989
5 - 3 = 1.3699999999999992
6 - 3 = 1.2299999999999986
7 - 3 = 1.0999999999999996
8 - 3 = -0.02000000000000135
9 - 3 = 0.17999999999999972
10 - 3 = 0.15000000000000036
11 - 3 = 0.21999999999999886
12 - 3 = 0.9599999999999991
13 - 3 = 0.9000000000000004
14 - 3 = 0.9799999999999986
15 - 3 = -0.28000000000000114
16 - 3 = -0.34999999999999964
17 - 3 = -0.3200000000000003
18 - 3 = -0.23000000000000043
19 - 3 = -0.41000000000000014
13.86
5 - 4 = 0.8200000000000003
6 - 4 = 0.6799999999999997
7 - 4 = 0.5500000000000007
8 - 4 = -0.5700000000000003
9 - 4 = -0.3699999999999992
10 - 4 = -0.3999999999999986
11 - 4 = -0.33000000000000007
12 - 4 = 0.41000000000000014
13 - 4 = 0.3500000000000014
14 - 4 = 0.4299999999999997
15 - 4 = -0.8300000000000001
16 - 4 = -0.8999999999999986
17 - 4 = -0.8699999999999992
18 - 4 = -0.7799999999999994
19 - 4 = -0.9599999999999991
14.68
6 - 5 = -0.14000000000000057
7 - 5 = -0.2699999999999996
8 - 5 = -1.3900000000000006
9 - 5 = -1.1899999999999995
10 - 5 = -1.2199999999999989
11 - 5 = -1.1500000000000004
12 - 5 = -0.41000000000000014
13 - 5 = -0.46999999999999886
14 - 5 = -0.39000000000000057
15 - 5 = -1.6500000000000004
16 - 5 = -1.7199999999999989
17 - 5 = -1.6899999999999995
18 - 5 = -1.5999999999999996
19 - 5 = -1.7799999999999994
14.54
7 - 6 = -0.129999999999999
8 - 6 = -1.25
9 - 6 = -1.049999999999999
10 - 6 = -1.0799999999999983
11 - 6 = -1.0099999999999998
12 - 6 = -0.2699999999999996
13 - 6 = -0.3299999999999983
14 - 6 = -0.25
15 - 6 = -1.5099999999999998
16 - 6 = -1.5799999999999983
17 - 6 = -1.549999999999999
18 - 6 = -1.459999999999999
19 - 6 = -1.6399999999999988
14.41
8 - 7 = -1.120000000000001
9 - 7 = -0.9199999999999999
10 - 7 = -0.9499999999999993
11 - 7 = -0.8800000000000008
12 - 7 = -0.14000000000000057
13 - 7 = -0.1999999999999993
14 - 7 = -0.120000000000001
15 - 7 = -1.3800000000000008
16 - 7 = -1.4499999999999993
17 - 7 = -1.42
18 - 7 = -1.33
19 - 7 = -1.5099999999999998
13.29
9 - 8 = 0.20000000000000107
10 - 8 = 0.1700000000000017
11 - 8 = 0.2400000000000002
12 - 8 = 0.9800000000000004
13 - 8 = 0.9200000000000017
14 - 8 = 1.0
15 - 8 = -0.2599999999999998
16 - 8 = -0.3299999999999983
17 - 8 = -0.29999999999999893
18 - 8 = -0.20999999999999908
19 - 8 = -0.3899999999999988
13.49
10 - 9 = -0.02999999999999936
11 - 9 = 0.03999999999999915
12 - 9 = 0.7799999999999994
13 - 9 = 0.7200000000000006
14 - 9 = 0.7999999999999989
15 - 9 = -0.46000000000000085
16 - 9 = -0.5299999999999994
17 - 9 = -0.5
18 - 9 = -0.41000000000000014
19 - 9 = -0.5899999999999999
13.46
11 - 10 = 0.06999999999999851
12 - 10 = 0.8099999999999987
13 - 10 = 0.75
14 - 10 = 0.8299999999999983
15 - 10 = -0.4300000000000015
16 - 10 = -0.5
17 - 10 = -0.47000000000000064
18 - 10 = -0.3800000000000008
19 - 10 = -0.5600000000000005
13.53
12 - 11 = 0.7400000000000002
13 - 11 = 0.6800000000000015
14 - 11 = 0.7599999999999998
15 - 11 = -0.5
16 - 11 = -0.5699999999999985
17 - 11 = -0.5399999999999991
18 - 11 = -0.4499999999999993
19 - 11 = -0.629999999999999
14.27
13 - 12 = -0.05999999999999872
14 - 12 = 0.019999999999999574
15 - 12 = -1.2400000000000002
16 - 12 = -1.3099999999999987
17 - 12 = -1.2799999999999994
18 - 12 = -1.1899999999999995
19 - 12 = -1.3699999999999992
14.21
14 - 13 = 0.0799999999999983
15 - 13 = -1.1800000000000015
16 - 13 = -1.25
17 - 13 = -1.2200000000000006
18 - 13 = -1.1300000000000008
19 - 13 = -1.3100000000000005
14.29
15 - 14 = -1.2599999999999998
16 - 14 = -1.3299999999999983
17 - 14 = -1.299999999999999
18 - 14 = -1.209999999999999
19 - 14 = -1.3899999999999988
13.03
16 - 15 = -0.06999999999999851
17 - 15 = -0.03999999999999915
18 - 15 = 0.05000000000000071
19 - 15 = -0.129999999999999
12.96
17 - 16 = 0.02999999999999936
18 - 16 = 0.11999999999999922
19 - 16 = -0.0600000000000005
12.99
18 - 17 = 0.08999999999999986
19 - 17 = -0.08999999999999986
13.08
19 - 18 = -0.17999999999999972
12.9

In [8]:
# You may need to install htmllib5,lxml, and BeautifulSoup4. In your terminal/command prompt run:

# conda install lxml
# conda install html5lib
# conda install BeautifulSoup4
# Then restart Jupyter Notebook. (or use pip install if you aren't using the Anaconda Distribution)
import numpy as np
import pandas as pd
import os.path
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
from pandas.tseries.offsets import *
from pylab import text
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import quandl


# Quandl API key
quandl.ApiConfig.api_key = "UsYsv7dKGxHHQ5oURP4B"

# Some formatting
pd.set_option('display.max_colwidth', -1)
pd.set_option('display.max_seq_items', 2)

# Only pull fresh PDUFA data
three_weeks_ago = relativedelta(weeks=3)
one_week_ahead = relativedelta(weeks=1)
one_hour_ago = datetime.now() - timedelta(hours=1)
if os.path.exists("history.csv"):
    filetime = datetime.fromtimestamp(os.path.getctime("history.csv"))
    if filetime < one_hour_ago:
        histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
        histdata[0].to_csv('history.csv',index=False)
else:
    histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
    histdata[0].to_csv('history.csv',index=False)

# Create dataframe
df = pd.read_csv('history.csv').set_index('Ticker')
df.index.name=None
df[["Date","Catalyst"]] = df.Catalyst.str.extract('(?P<Date>[0-9]{2}\/[0-9]{2}\/[0-9]{4})(?P<Catalyst>.*)', expand=True)
df['Date'] = pd.to_datetime(df['Date'])
df["Past"] = df["Date"] - DateOffset(weeks=5)
df["Future"] = df["Date"] + DateOffset(weeks=2)

df
# Set stock ticker
stockpick="HALO"
dataset=str(f"WIKI/{stockpick}")
# Set variables for plot creation
length = len(df.loc[stockpick].index)
count = 0
fig, axes = plt.subplots(nrows=length, ncols=1,figsize=(16,length * 3))
fig.subplots_adjust(hspace=0, wspace=0)
allplots=[]

# Combine all data together into list of dataframes, iterate through each part of the list, plot each frame.
while (count < length):
    pasttime= df.loc[stockpick].iloc[count]["Past"]
    futuretime= df.loc[stockpick].iloc[count]["Future"]
    pdufa=df.loc[stockpick].iloc[count]["Date"]
    annotate = df.loc[stockpick].iloc[count]["Date"] + timedelta(days=1)
    stage = df.loc[stockpick].iloc[count]["Stage"]
    catalyst = df.loc[stockpick].iloc[count]["Catalyst"]
    drug = df.loc[stockpick].iloc[count]["Drug"]
    
    #Annotation
    tooltip = f"stage:{stage}  -{catalyst}\n{drug}"
    at = AnchoredText(tooltip,
                      prop=dict(size=10), frameon=True,
                      loc=2, 
                      )
    at.patch.set_boxstyle("round,pad=0.2,rounding_size=0.2")
    axes[count].add_artist(at)
    axes[count].margins(0.0, 0.5)
    #Get quandl data
    mydata = quandl.get(dataset,start_date=pasttime,end_date=futuretime)
    allplots.append(mydata)
#     axes[count].annotate('local max', xy=(pdufa, allplots[count]["Close"].max()), xytext=(annotate, (allplots[count]["Close"].max() - allplots[count]["Close"].min()) * 0.9 + allplots[count]["Close"].min()),
#             arrowprops=dict(facecolor='black', shrink=0.05, width=1, headwidth=5),)
    # Set y limit for notes
    axes[count].set_ylim(allplots[count]["Close"].min() * .99 , (allplots[count]["Close"].max()-allplots[count]["Close"].min()) * 0.5 + allplots[count]["Close"].max())
    axes[count].hlines(allplots[count]["Close"].max() * 1.01, allplots[count].head(1).index, allplots[count].tail(1).index, linestyle="-", lw=1, color='black')
    if count == 3:
        axes[count].set_facecolor((0.91, 0.91, 0.91))  

    axes[count].vlines(pdufa, allplots[count]["Close"].min() * .99, allplots[count]["Close"].max() * 1.01, linestyle="--", color='black')
    axes[count].plot(allplots[count].index,allplots[count]["Close"],c=np.random.rand(3,), lw=2, label=pdufa) 
    axes[count].axes.get_xaxis().set_visible(False) # remove x axis
    count = count + 1
plt.show()



In [3]:
# You may need to install htmllib5,lxml, and BeautifulSoup4. In your terminal/command prompt run:

# conda install lxml
# conda install html5lib
# conda install BeautifulSoup4
# Then restart Jupyter Notebook. (or use pip install if you aren't using the Anaconda Distribution)
import numpy as np
import pandas as pd
import os.path
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
from pandas.tseries.offsets import *
from pylab import text
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import quandl


# Quandl API key
quandl.ApiConfig.api_key = "UsYsv7dKGxHHQ5oURP4B"

# Some formatting
pd.set_option('display.max_colwidth', -1)
pd.set_option('display.max_seq_items', 2)

# Only pull fresh PDUFA data
three_weeks_ago = relativedelta(weeks=3)
one_week_ahead = relativedelta(weeks=1)
one_hour_ago = datetime.now() - timedelta(hours=1)
if os.path.exists("history.csv"):
    filetime = datetime.fromtimestamp(os.path.getctime("history.csv"))
    if filetime < one_hour_ago:
        histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
        histdata[0].to_csv('history.csv',index=False)
else:
    histdata = pd.read_html("https://www.biopharmcatalyst.com/calendars/historical-catalyst-calendar")
    histdata[0].to_csv('history.csv',index=False)

# Create dataframe
df = pd.read_csv('history.csv').set_index('Ticker')
df.index.name=None
df[["Date","Catalyst"]] = df.Catalyst.str.extract('(?P<Date>[0-9]{2}\/[0-9]{2}\/[0-9]{4})(?P<Catalyst>.*)', expand=True)
df['Date'] = pd.to_datetime(df['Date'])
df["Past"] = df["Date"] - DateOffset(weeks=5)
df["Future"] = df["Date"] + DateOffset(weeks=2)

df
# Set stock ticker
stockpick="HALO"
dataset=str(f"WIKI/{stockpick}")
# Set variables for plot creation
length = len(df.loc[stockpick].index)
count = 0
allplots=[]
e = []
# Combine all data together into list of dataframes, iterate through each part of the list, plot each frame.
while (count < length):
    pasttime= df.loc[stockpick].iloc[count]["Past"]
    futuretime= df.loc[stockpick].iloc[count]["Future"]
    pdufa=df.loc[stockpick].iloc[count]["Date"]
    annotate = df.loc[stockpick].iloc[count]["Date"] + timedelta(days=1)
    stage = df.loc[stockpick].iloc[count]["Stage"]
    catalyst = df.loc[stockpick].iloc[count]["Catalyst"]
    drug = df.loc[stockpick].iloc[count]["Drug"]
    d = []
    #Annotation
    #Get quandl data
    mydata = quandl.get(dataset,start_date=pasttime,end_date=futuretime)
    allplots.append(mydata)
    i=0
#     print(len(allplots[count].index))
    total = len(allplots[count].index) - 1
    while (i < total):
        n = i + 1
        while (n < total):  # see 14 - 8 = 1.0 !!!
            rangevalue=(allplots[count].iloc[n]["Close"] - allplots[count].iloc[i]["Close"])
            d.append(rangevalue)
            range = f"{n} - {i}"
            n=n + 1
        i = i + 1
    e.append(d)
    count = count + 1
#need to add row names to see what the ranges are specifically.
finaldf=pd.DataFrame(e).transpose()
finaldf


Out[3]:
0 1 2 3 4 5 6 7
0 -0.420 0.33 0.14 -0.11 0.23 0.08 0.08 -1.250
1 -0.090 0.17 0.59 -0.39 0.83 0.08 0.08 -1.370
2 0.560 0.16 0.65 -0.07 0.78 0.01 0.01 -1.410
3 0.770 0.24 0.08 0.37 0.86 -0.15 -0.15 -1.320
4 0.680 0.14 0.40 0.36 1.32 -0.29 -0.29 -1.560
5 0.350 0.35 0.30 0.64 1.55 -0.30 -0.30 -1.750
6 0.220 0.29 0.03 0.67 1.42 -0.51 -0.51 -2.000
7 0.110 0.02 -0.22 0.61 0.80 -0.24 -0.24 -2.360
8 -0.110 -0.30 -0.25 0.48 1.17 0.14 0.14 -1.920
9 0.210 -0.25 0.02 1.15 1.61 0.15 0.15 -1.480
10 -0.270 -0.02 0.43 0.85 1.73 0.44 0.44 -1.490
11 -0.240 0.16 0.11 0.69 1.47 -0.38 -0.38 -1.380
12 0.000 0.01 0.08 0.98 1.27 0.02 0.02 -1.450
13 0.370 -0.27 -0.45 1.04 1.82 -1.23 -1.23 -1.320
14 0.250 -0.23 -1.01 0.94 2.64 -1.35 -1.35 -1.260
15 0.010 -0.28 -0.67 0.99 2.50 -1.39 -1.39 -1.310
16 -0.380 0.03 -0.92 0.89 2.37 -1.30 -1.30 -0.960
17 -0.455 -0.45 -1.32 0.45 1.25 -1.54 -1.54 -0.950
18 -0.320 -0.53 -1.29 0.42 1.45 -1.73 -1.73 -1.110
19 0.380 -0.43 -1.35 0.65 1.42 -1.98 -1.98 -0.720
20 0.825 -0.68 -1.24 1.25 1.49 -2.34 -2.34 0.010
21 0.430 -0.42 -0.54 1.20 2.23 -1.90 -1.90 0.160
22 0.070 -0.28 1.38 1.28 2.17 -1.46 -1.46 0.430
23 -0.390 -0.33 2.15 1.74 2.25 -1.47 -1.47 0.670
24 -4.650 -0.74 3.01 1.97 0.99 -1.36 -1.36 0.730
25 -4.340 -0.69 1.66 1.84 0.92 -1.43 -1.43 0.430
26 -4.130 0.15 0.68 1.22 0.95 -1.30 -1.30 -0.170
27 -2.890 0.15 0.63 1.59 1.04 -1.24 -1.24 -0.610
28 -2.970 0.07 0.16 2.03 0.86 -1.29 -1.29 -1.185
29 -3.060 -0.10 -0.34 2.15 0.49 -0.94 -0.94 -1.340
... ... ... ... ... ... ... ... ...
565 NaN NaN NaN NaN -0.36 NaN NaN NaN
566 NaN NaN NaN NaN -0.47 NaN NaN NaN
567 NaN NaN NaN NaN 0.09 NaN NaN NaN
568 NaN NaN NaN NaN -0.09 NaN NaN NaN
569 NaN NaN NaN NaN -0.46 NaN NaN NaN
570 NaN NaN NaN NaN -0.35 NaN NaN NaN
571 NaN NaN NaN NaN -0.32 NaN NaN NaN
572 NaN NaN NaN NaN -0.39 NaN NaN NaN
573 NaN NaN NaN NaN -0.50 NaN NaN NaN
574 NaN NaN NaN NaN -0.18 NaN NaN NaN
575 NaN NaN NaN NaN -0.55 NaN NaN NaN
576 NaN NaN NaN NaN -0.44 NaN NaN NaN
577 NaN NaN NaN NaN -0.41 NaN NaN NaN
578 NaN NaN NaN NaN -0.48 NaN NaN NaN
579 NaN NaN NaN NaN -0.59 NaN NaN NaN
580 NaN NaN NaN NaN -0.37 NaN NaN NaN
581 NaN NaN NaN NaN -0.26 NaN NaN NaN
582 NaN NaN NaN NaN -0.23 NaN NaN NaN
583 NaN NaN NaN NaN -0.30 NaN NaN NaN
584 NaN NaN NaN NaN -0.41 NaN NaN NaN
585 NaN NaN NaN NaN 0.11 NaN NaN NaN
586 NaN NaN NaN NaN 0.14 NaN NaN NaN
587 NaN NaN NaN NaN 0.07 NaN NaN NaN
588 NaN NaN NaN NaN -0.04 NaN NaN NaN
589 NaN NaN NaN NaN 0.03 NaN NaN NaN
590 NaN NaN NaN NaN -0.04 NaN NaN NaN
591 NaN NaN NaN NaN -0.15 NaN NaN NaN
592 NaN NaN NaN NaN -0.07 NaN NaN NaN
593 NaN NaN NaN NaN -0.18 NaN NaN NaN
594 NaN NaN NaN NaN -0.11 NaN NaN NaN

595 rows × 8 columns


In [50]:
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay

date='2018-12-29'
us_bd = CustomBusinessDay(calendar=USFederalHolidayCalendar())

df = pd.DataFrame(pd.DatetimeIndex(start='2018-12-20',end='2019-01-10', freq="D"), columns=["Date"])
df['day_of_week'] = df['Date'].dt.day_name()
df["Date Rounded"] = df["Date"].map(lambda x : x + 0*us_bd)
df


Out[50]:
Date day_of_week Date Rounded
0 2018-12-20 Thursday 2018-12-20
1 2018-12-21 Friday 2018-12-21
2 2018-12-22 Saturday 2018-12-24
3 2018-12-23 Sunday 2018-12-24
4 2018-12-24 Monday 2018-12-24
5 2018-12-25 Tuesday 2018-12-26
6 2018-12-26 Wednesday 2018-12-26
7 2018-12-27 Thursday 2018-12-27
8 2018-12-28 Friday 2018-12-28
9 2018-12-29 Saturday 2018-12-31
10 2018-12-30 Sunday 2018-12-31
11 2018-12-31 Monday 2018-12-31
12 2019-01-01 Tuesday 2019-01-02
13 2019-01-02 Wednesday 2019-01-02
14 2019-01-03 Thursday 2019-01-03
15 2019-01-04 Friday 2019-01-04
16 2019-01-05 Saturday 2019-01-07
17 2019-01-06 Sunday 2019-01-07
18 2019-01-07 Monday 2019-01-07
19 2019-01-08 Tuesday 2019-01-08
20 2019-01-09 Wednesday 2019-01-09
21 2019-01-10 Thursday 2019-01-10

In [ ]: