Skip to content

Instantly share code, notes, and snippets.

View quantra-go-algo's full-sized avatar

Algorithmic Trading quantra-go-algo

View GitHub Profile
#Importing pandas
import pandas as pd
‘to_datetime’ method in pandas are used to convert date strings to dates.
#Using pandas to parse dates
datestrs = ['1/14/2018', '2/14/2018']
pd.to_datetime(datestrs)
#Slicing the Time Series
ts[datetime(2011,1,7):]
#Creating a Time Series with duplicated indices
datesdup = [datetime(2018, 1, 1), datetime(2018, 1, 2), datetime(2018, 1, 2), datetime(2018, 1, 2), datetime(2018, 1, 3)]
dup_ts = pd.Series(np.random.randn(5), index=datesdup)
dup_ts
#Shifting the Time Series
ts.shift(2)