I am going to analyze the time series of financial data. Since I work on the Pakistan Stock Exchange (PSX), data is not available on yahoo. When I looked at some Quantopian tutorials, the first step is data extraction through yahoo finance. Now when I use the PyFolio module and read in csv (Panda Function) containing the data, there is a problem with the Pandas and PyFolio datetime format. Below is the code of what I am doing.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pyfolio as pf
import datetime
from datetime import datetime
from datetime import timedelta
start_date = '2015-02-01'
end_date = '2017-03-20'
live_date = '2017-03-15'
symbols = ['KEL']
def converter(start_date):
convert=datetime.strptime(start_date, "%Y-%m-%d")
return convert
def data(symbols):
dates=pd.date_range(start_date,end_date)
df=pd.DataFrame(index=dates)
df_temp=pd.read_csv('/home/furqan/Desktop/python_data/{}.csv'.format(str(symbols[0])),usecols=['Date','Close'],
parse_dates=True,index_col='Date',na_values=['nan'])
df_temp = df_temp.rename(columns={'Close': symbols[0]})
df=df.join(df_temp)
df=df.fillna(method='ffill')
df=df.fillna(method='bfill')
return df
new_date = converter (live_date)
df= data(symbols)
sheet = pf.create_returns_tear_sheet(df, live_start_date=new_date)
The above code results in the following error
TypeError: Cannot compare tz-naive and tz-aware timestamps
Given the above information, I have two questions.
1) Can Quantopian be good for my analysis if I have data on my PC? Because the data is not available for financing yahoo.
2) ? .
PyFolio Pandas.
https://quantopian.imtqy.com/pyfolio/notebooks/single_stock_example/#fetch-the-daily-returns-for-a-stock
http://pandas.pydata.org/pandas-docs/stable/