Giter VIP home page Giter VIP logo

Comments (1)

git-shogg avatar git-shogg commented on June 5, 2024

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

from quantstats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.