Git Product home page Git Product logo

stitcher's Introduction

What it is

Stitcher is a utility writen in Julia for constructing continuous contract data needed for analysing trading instruments of either financial or commodity futures. The continuous contract can be used for devising or backtesting of trading strategies. Stitcher takes historical data of individual contracts in CSV format, selects the trading data of the contract of most interests on any given trading day, thus forming a new linage of trading history, then back-adjust prices to eliminate prices gaps on changes of actual contracts, outputs the data in the same CSV format.

How it works

The historical data of individual contracts can be provided in separate files or a lumpsum file. The names of the files should contain "Contract" and end with ".csv".

The files need to have at least these columns:

"Date","Open","High","Low","Close","Open_Interest","Contract"

They can have other columns, and the extra columns will just pass through without touch.

"Date" should be String in the format of "yyyy-mm-dd", like "2010-03-24".

"Open","High","Low","Close" should be floating point numbers

The column of "Contract" notes the name of the contract, for instance, "F2015", "K2015" etc. The actual name given is not of a concern to Stitcher as long as they are consistent duing one batch of processing.

So on any given trading day, there are various contracts being traded. Stitcher selects the contract with the highest "Open_Interest" on that day. If the name of the column "Open_Interest" is not such, you can specify it with argument as "openInterest = :Interest" (if your column is denominated as "Interest"). Anyhow, the openInterest column should be floating point numbers.

Function Stitch takes the following arguments, with defaults specified:

Instr="". By default, Stitch uses the current directory as the working directory for inputs and outputs. If you specify Instr="Gold", then it uses the subdirectory of "Data/Gold" as the working directory.

StartDate="2010-01-01" and EndDate="2050-12-31" are to specify the date range of the output file. Dates outside of this range in the input files are dropped.

AdjMethod="M" specifies the method to back adjust price data due to gaps. The default uses multiplication (or division) method. If you specify otherwise, it will use addition (or subtraction) method (note: this can generate negative prices which can be not proper for trading analysis).

Finally, openInterest::Symbol=:Open_Interest has been addressed above.

On outputs, there are three files:

Stitched.csv is the stitched data but not back adjusted.

Roll.csv contains only the dates with contract changes.

StitchedAdjM.csv (or StitchedAdjA.csv) is the final stitched and adjusted data.

How to use it

Stitcher is compatible with Julia 1.7.2.

As prerequisites, it requires three Julia packages: Dates, CSV, DataFrames

Test data are provided under Data subdirectory.

To run the test, do:

$ julia

julia> using DataRoutines

julia> cd("Data")

julia> Stitch()

License

Stitcher is provided under MIT License: https://opensource.org/licenses/MIT

Used Libraries and their licenses

Julia

CSV

DataFrames

No warrantee and No guarrantee

The author hereby provides no warrantee of the utility and no guarantee for trading success.

stitcher's People

Contributors

xilinjia 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.