Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Futures Data (CME, EUREX, etc) #313

Open
jortiz12 opened this issue Nov 17, 2023 · 1 comment
Open

Futures Data (CME, EUREX, etc) #313

jortiz12 opened this issue Nov 17, 2023 · 1 comment

Comments

@jortiz12
Copy link

Dear Community,
Is it possible to supply QuantStats with external futures data saved in .csv or .xlsx format.
Typical data providers (e.g. YFinance) don´t have data I'm looking for (mostly bond futures at CME, EUREX).

Kind Regards
Jose

@git-shogg
Copy link
Contributor

Hi @jortiz12,

Yes this is possible. I would also recommend you have a look at alternatives that could be used as a substitute to make life a bit easier (e.g. there might be ETFs that track the same instruments?). However, if you are after a higher level of accuracy you can simply download the data for the timeframe you are after (direct from CME, EUREX, etc), save it to .csv or .xlsx format (example below uses csv), place this file in the same folder as your python script, import that into your script and use pandas to convert the datetime string column to real datetime and capture the percentage change of the instrument daily over that time. An example of this shown below.

import quantstats as qs
import pandas as pd

instrument_daily_close_price = pd.read_csv("instrument_daily_close_price.csv")
instrument_daily_close_price['Date'] = pd.to_datetime(instrument_daily_close_price['Date'], format='%d/%m/%Y')
instrument_daily_close_price['pct_change'] = instrument_daily_close_price['Price'].pct_change()
instrument_daily_close_price = instrument_daily_close_price[['Date','pct_change']]  # Drop out all unrequired columns
instrument_daily_close_price = instrument_daily_close_price.set_index('Date')
instrument_daily_close_price_series = instrument_daily_close_price.squeeze()    # Convert to pandas series
instrument_daily_close_price_series.index = instrument_daily_close_price_series.index.tz_localize(None)

comparison_instrument = qs.utils.download_returns('SPY')    # Download historical prices for benchmark.
comparison_instrument.index = comparison_instrument.index.tz_localize(None)
qs.reports.html(instrument_daily_close_price_series, comparison_instrument, output=1, download_filename="output.html")

Let me know if this answers your question?

Kind regards,
git-shogg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants