In [ ]:
import numpy as np
import pandas as pd
from bqplot import *
from datetime import datetime as dt
from bqplot.traits import *
In [ ]:
price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[0.5, 0.8], [0.8, 1.0]]), axis=0) + 100,
columns=['Security 1', 'Security 2'],
index=pd.date_range(start='01-01-2007', periods=150))
In [ ]:
x_data = price_data.index.values
x_data[:5]
In [ ]:
dt_x = DateScale()
sc_y = LinearScale()
line = Lines(x=x_data, y=price_data['Security 1'].values, scales={'x': dt_x, 'y': sc_y})
ax_x = Axis(scale=dt_x)
ax_y = Axis(scale=sc_y, orientation='vertical')
Figure(marks=[line], axes=[ax_x, ax_y])
In [ ]:
import datetime
ref_date = dt.datetime(2010, 1, 1)
num_items = range(250)
x_data = [ref_date + datetime.timedelta(x) for x in num_items]
x_data[:5]
In [ ]:
dt_x = DateScale()
sc_y = LinearScale()
date_x = convert_to_date(x_data)
line = Lines(x=date_x, y=price_data['Security 1'].values, scales={'x': dt_x, 'y': sc_y})
ax_x = Axis(scale=dt_x)
ax_y = Axis(scale=sc_y, orientation='vertical')
Figure(marks=[line], axes=[ax_x, ax_y])
In [ ]:
x_data = np.array(x_data)
x_data[:5]
In [ ]:
dt_x = DateScale()
sc_y = LinearScale()
date_x = convert_to_date(x_data)
line = Lines(x=date_x, y=price_data['Security 1'].values, scales={'x': dt_x, 'y': sc_y})
ax_x = Axis(scale=dt_x)
ax_y = Axis(scale=sc_y, orientation='vertical')
Figure(marks=[line], axes=[ax_x, ax_y])
In [ ]:
date_format = '%m-%d-%Y'
x_data = price_data.index.values
x_data[:5]
In [ ]:
dt_x = DateScale()
sc_y = LinearScale()
date_x = convert_to_date(x_data)
line = Lines(x=date_x, y=price_data['Security 1'].values, scales={'x': dt_x, 'y': sc_y})
ax_x = Axis(scale=dt_x)
ax_y = Axis(scale=sc_y, orientation='vertical')
Figure(marks=[line], axes=[ax_x, ax_y])
In [ ]:
x_data = x_data.tolist()
x_data[:5]
In [ ]:
dt_x = DateScale()
sc_y = LinearScale()
line = Lines(x=x_data, y=price_data['Security 1'].values, scales={'x': dt_x, 'y': sc_y})
ax_x = Axis(scale=dt_x)
ax_y = Axis(scale=sc_y, orientation='vertical')
Figure(marks=[line], axes=[ax_x, ax_y])
In [ ]:
date_format = '%m-%d-%Y'
x_data = price_data.index.values
data_2 = price_data.iloc[30: ,]
x_data_2 = data_2.index.values
In [ ]:
final_y = pd.concat([price_data['Security 1'], data_2['Security 2']], axis=1).values.T
In [ ]:
dt_x = DateScale()
sc_y = LinearScale()
line = Lines(x=x_data, y=final_y, scales={'x': dt_x, 'y': sc_y}, labels=['spx', 'sp2'],
display_legend=True, colors=['hotpink', 'orange'])
ax_x = Axis(scale=dt_x)
ax_y = Axis(scale=sc_y, orientation='vertical')
Figure(marks=[line], axes=[ax_x, ax_y])
In [ ]:
In [ ]:
In [ ]: