Giter Site home page Giter Site logo

quantiacs / strategy-futures-commodity Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 18 KB

This template uses external commodity International Monetary Fund data for creating an algorithm for futures contracts.

License: MIT License

Jupyter Notebook 100.00%
python commodity imf trading futures

strategy-futures-commodity's Introduction

Using IMF Commodity Data

This trading strategy is designed for the Quantiacs platform, which hosts competitions for trading algorithms. Detailed information about the competitions is available on the official Quantiacs website.

How to Run the Strategy

In an Online Environment

The strategy can be executed in an online environment using Jupiter or JupiterLab on the Quantiacs personal dashboard. To do this, clone the template in your personal account.

In a Local Environment

To run the strategy locally, you need to install the Quantiacs Toolbox.

Strategy Overview

The "Using IMF Commodity Data" notebook showcases the integration of International Monetary Fund (IMF) commodity data into a trading algorithm. It guides through accessing and utilizing this data to inform trading decisions, focusing on a strategy that trades futures based on the comparison of Gold futures prices and the IMF's Gold commodity prices. Key steps include loading the necessary data, implementing a strategy that goes long under specific conditions related to Gold prices, and backtesting the strategy using Quantiacs' toolkit. This example demonstrates the value of incorporating external economic indicators into algorithmic trading strategies.

import xarray as xr
import numpy as np
import pandas as pd

import qnt.backtester as qnbt
import qnt.data as qndata
# commodity listing
commodity_list = qndata.imf_load_commodity_list()
pd.DataFrame(commodity_list)
def load_data(period):
    # load Futures Gold and Gold data:
    futures   = qndata.futures_load_data(assets=['F_GC'], tail=period, dims=('time','field','asset'))
    commodity = qndata.imf_load_commodity_data(assets=['PGOLD'], tail=period).isel(asset=0)
    return dict(commodity=commodity, futures=futures), futures.time.values


def window(data, max_date: np.datetime64, lookback_period: int):
    # build sliding window for rolling evaluation:
    min_date = max_date - np.timedelta64(lookback_period, 'D')
    return dict(
        futures   = data['futures'].sel(time=slice(min_date, max_date)),
        commodity = data['commodity'].sel(time=slice(min_date, max_date))
    )


def strategy(data):
    # strategy uses both Futures Gold and Gold data:
    close = data['futures'].sel(field='close')
    commodity = data['commodity']
    if commodity.isel(time=-1) > commodity.isel(time=-2) and close.isel(time=-1) > close.isel(time=-20):
        return xr.ones_like(close.isel(time=-1))
    else:
        return xr.zeros_like(close.isel(time=-1))


weights = qnbt.backtest(
    competition_type='futures',
    load_data=load_data,
    window=window,
    lookback_period=365,
    start_date='2006-01-01',
    strategy=strategy,
    analyze=True,
    build_plots=True
)

More examples of use data from the International Monetary Fund (IMF) in documentation.

strategy-futures-commodity's People

Contributors

actis-quantnet avatar burdinskiy-quantnet avatar qnt-dmitry avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.