Coder Social home page Coder Social logo

laokpa / pe-hft-r Goto Github PK

View Code? Open in Web Editor NEW

This project forked from portfolioeffect/pe-hft-r

0.0 0.0 0.0 6.5 MB

R package for high frequency trading (HFT) backtests, intraday portfolio analysis and portfolio optimization.

Home Page: https://www.portfolioeffect.com/docs/platform/quant

License: GNU General Public License v3.0

R 100.00%

pe-hft-r's Introduction

PortfolioEffect

PortfolioEffectHFT Package for R

R package/API to PortfolioEffect cloud service for high frequency trading (HFT) strategy backtests, intraday portfolio analysis and portfolio optimization.

About PortfolioEffect

PortfolioEffect platform employs high frequency microstructure model pipeline, cloud computing and server-side market data to enable classic portfolio analysis at intraday horizons.

Package Installation

Install Latest JDK/JRE Runtime

Download and install latest Java distribution (JDK or JRE) for your platform from Oracle's website

Configure Java Environment (Optional)

If you are using Windows, installation wizard from the previous step should have done everything for you. If you are on Linux or Mac and you used a tarball file, you will need to manually append the following lines to /etc/environment using your favorite text editor:

export JAVA_HOME=/path/to/java/folder
export PATH=$PATH:$JAVA_HOME/bin

Apply environment changes:

source /etc/environment

To complete with the set-up of Java environment inside R, run the following line:

sudo R CMD javareconf

Install Required Packages (Optional)

If you manually installing PortfolioEffectHFT package (you don't want to use CRAN repositories for some reason), you would need to install all required package dependencies first.

Start R from the command line or in your GUI editor and type

install.packages(c("rJava", "ggplot2"))

Install Main Package

Package builds are available from website downloads. If you are building PortfolioEffect from source, check out its source code from this repository and use R build tools to create a package:

R CMD build PortfolioEffectHFT
R CMD Rd2pdf PortfolioEffectHFT

Account Credentials

Locate API Credentials

All portfolio computations are performed on PortfolioEffect cloud servers. To obtain a free non-professional account, you need to follow a quick sign-up process on our website

Please use a valid sign-up address - it will be used to email your account activation link to enable API access then log in to you account and locate your API credentials on the main page:

API Credentials

Set API Credentials

Run the following commands to set your account API credentials for the PortfolioEffectHFT Package for R.

util_setCredentials('API Username', 'API Password', 'API Key')

You will need to do it only once as your credentials are stored between sessions on your local machine to speed up future logons. You would need to repeat this procedure if you change your account password or install PortfolioEffectHFT package on another computer.

You are now ready to call PortfolioEffectHFT methods.

Portfolio Construction

User Data

Users may supply their own historical datasets for index and position entries. This external data could be one a OHLC bar column element (e.g. 1-second close prices) or a vector of actual transaction prices that contains non-equidistant data points. You might want to pre-pend at least N =(4 x windowLength) data points to the beginning of the interval of interest which would be used for initial calibration of portfolio metrics.

Create Portfolio

Method portfolio_create() takes a vector of index prices in the format (UTC timestamp, price) with UTC timestamp expressed in milliseconds from 1970-01-01 00:00:00 EST.

Time          Value
[1,] 1412256601000 99.30
[2,] 1412256602000 99.33
[3,] 1412256603000 99.30
[4,] 1412256604000 99.26
[5,] 1412256605000 99.36
[6,] 1412256606000 99.36
[7,] 1412256607000 99.36
[8,] 1412256608000 99.38
[9,] 1412256609000 99.40
[10,] 1412256610000 99.37

If index symbol is specified, it is silently ignored.

# Create portfolio
portfolio=portfolio_create(priceDataIx=spy.data)

Add Positions

Positions are added using portfolio_addPosition() with 'priceData' in the same format as index price.

data(goog.data)
data(aapl.data)

# Single position without rebalancing
portfolio_addPosition(portfolio, 
			symbol='GOOG', 
 			quantity=100, 
 			priceData=goog.data) 

# Single position with rebalancing
portfolio_addPosition(portfolio, 
  			symbol='AAPL', 
			quantity=c(300,150), 
			time=c("2014-09-01 09:00:00","2014-09-07 14:30:00"), 
			priceData=aapl.data)

Server Data

At PortfolioEffect we are capturing and storing 1-second intraday bar history for a all NASDAQ traded equites (see symbology).

This server-side dataset spans from January 2013 to the latest trading time minus five minutes. It could be used to construct asset portfolios and compute intraday portfolio metrics.

Create Portfolio

Method portfolio_create() creates new asset portfolio or overwrites an existing portfolio object with the same name.

When using server-side data, it only requires a time interval that would be treated as a default position holding period unless positions are added with rebalancing. Index symbol could be specified as well with a default value of "SPY" - SPDR S&P 500 ETF Trust.

Interval boundaries are passed in the following format:

  • "yyyy-MM-dd HH:MM:SS" (e.g. "2014-10-01 09:30:00")
  • "yyyy-MM-dd" (e.g. "2014-10-01")
  • "t-N" (e.g. "t-5" is latest trading time minus 5 days)
  • UTC timestamp in milliseconds (mills from "1970-01-01 00:00:00") in EST time zone

For example:

# Timestamp in "yyyy-MM-dd HH:MM:SS" format
portfolio=portfolio_create(fromTime="2014-10-01 09:30:00", 
							 toTime="2014-10-02 16:00:00")
		
# Timestamp in "yyyy-MM-dd" format
portfolio=portfolio_create(fromTime="2014-10-01", 
						 toTime="2014-10-02")
		
# Timestamp in "t-N" format
portfolio=portfolio_create(fromTime="t-5", 
						 toTime="t")

Add Positions

Positions are added by calling portfolio_addPosition() method on a portfolio object with a list of symbols and quantities. For positions that were rebalanced or had non-default holding periods a 'time' argument could be used to specify rebalancing timestamps.

 portfolio_addPosition(portfolio,
				   symbol='GOOG', 
				   quantity=100)
		
 # Multiple positions without rebalancing
 portfolio_addPosition(portfolio,
					symbol=c('C','GOOG'),
					quantity=c(500,600))
		
# Single position with rebalancing
portfolio_addPosition(portfolio,
					symbol='AAPL', 
					quantity=c(300,150), 
					time=c("2014-09-01 09:00:00","2014-09-07 14:30:00"))

License

This package is released under the GPLv3 license. See the file LICENSE.

Usage of this package with PortfolioEffect services shall be subject to the Terms of Service.

Copyright

Copyright © 2015 PortfolioEffect

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.