Alternative Data: Users’ Data in Optimization

Optimization description

A trader using alternative data who already forecasted expected returns of different stocks want to find what is the optimal weights of his portfolio. Let’s input the users’ data in the optimization.

Our goal is to maximize the expected return given by the user divided by the square root of the variance and find what are the optimal weights for the portfolio.

 goal = expected_return / variance.sqrt() 

The optimization is run on 2 years of data from 01/01/2012 to 01/01/2014.  A portfolio is created with 2 stocks: AAPL and GOOG. Expected return is inputted by user. Portfolio’s initial value is $1 million.


After running the optimzation, we found that the optimal weights are the following for Apple and Google. The first 3 months correspond to the warming period of the model.


We can also backtest our optimize porfotfolio. Here we decided to calculate the variance of the portfolio.


How to install hft Python package

Use Anaconda2, install JDK. Refer yourself to this manual.

conda install -c portfolioeffect hft

Implementation of the strategy using hft Python package

from hft.optimization import *
from hft.metric import *
import pandas as pd
import time
import datetime

#Create Portfolio
portfolio = Portfolio("2012-01-01 09:30:00", "2014-01-01 16:00:00", 'SPY')
positionG = portfolio.add_position('GOOG', 10000)
positionA = portfolio.add_position('AAPL', 10000)
portfolio.settings(portfolioMetricsMode='price', inputSamplingInterval='30s',
 resultsSamplingInterval='1d', windowLength='50d')

#Read expected return input data 
filename = 'return.csv'
data = pd.read_csv(filename)

#Optimize portfolio's weights
variance = portfolio.variance()
expected_return = portfolio.expected_return()
goal = expected_return / variance.sqrt()
optimizer = Optimizer(goal, direction="max")

for symbol in list(set(data['symbol'])):
 temp = data[data.symbol == symbol]
 Time = [(time.mktime(datetime.datetime.strptime(i, "%m/%d/%Y").timetuple())+57600)* 1000 
         for i in temp['date']]
 optimizer = optimizer.forecast("ExpReturn", Metric([Time, list(temp['alpha'])], symbol))

optimalPortfolio =

#Plot optimal weights
optimalPortfolio.get_position('AAPL').weight().plot(title='AAPL Weight')
optimalPortfolio.get_position('GOOG').weight().plot(title='GOOG Weight')

#Plot portfolio's variance
optimalPortfolio.variance().plot(title='Portfolio Variance')

Added Optimization Features

Updated hft package is now available on Anaconda2 for Linux, Max and Windows distribution.

To install this package with conda run:

conda install -c portfolioeffect hft

Do not forget to install JDK as explain in this manual.

We added more optimization features. One very interesting feature is to be able to import your own data into the optimization. Let’s say you work with alternative data and you forecasted the returns of different stocks and you want to optimize your portfolio weight. You can now do it. We also added Kelly’s optimization. We will describe some examples in the next blog.

Our key optimization properties:

  • Dynamic portfolio optimization
  • Fast calculation
  • Optimize your portfolio weight
  • Kelly’s optimization
  • Users can import their own data in optimization
  • More than 20+ goals and constraints

Contact us at for more info.



Fordham-PortfolioEffect Algo Trading Workshop with Python, NYC

NYC, Sunday, May 21st from 9am to 4pm

During the workshop, you will learn how to compute intraday risk with PortfolioEffect HFT package available on Anaconda. The complexity of tick market data will be explained. You will study how to build your own portfolio, create a strategy, backtest it, optimize it, and use vol forecasting.


Beginner knowledge of Python and finance, college level math and laptop

We will learn how to use Jupyter Notebook.



9:00 AM – 9:30 AM: Welcome

9:30 AM – 10:00 AM: Introduction to tick market data

10:00 AM – 10:30 AM: Intraday risk metrics

10:30 AM – 11:00 AM: Exercise

11:00 AM – 11:30 AM: Backtesting & build your strategies

11:30 AM – 12:00 PM: Exercise with a moving average strategy

12:00 PM – 1:00 PM: Lunch break

1:00 PM – 1:30 PM: Vol forecasting

1:30 PM – 2:00 PM: Exercise on vol forecasting

2:00 PM – 2:30 PM: Break

2:30 PM – 3:00 PM: Portfolio optimization

3:00 PM – 3:30 PM: Exercise

3:30 PM – 3:45 PM: Strategies

3:45 PM – 4:00 PM: Closing remarks



Fordham Quantitative Finance Society

To register click here.

BZ Awards Finalist

We are happy to be part of BZ awards finalist. Thanks for voting for us!

Clean tick market data to get real time portfolio analytics, optimization and forecasting have never been so important to understands better the market.

At PortfolioEffect, we take care for you of the tick market data challenges so you can just focus on building the winning strategy that produce the most alpha.

Tick market data challenges solved by PortfolioEffect:

  • Microstructure Noise Model
  • Non Gaussian Returns Model
  • Price Jumps & Outliers Model
  • Portfolio Factors Model
  • Fractal Time Scaling Model
  • Spot Sensitivity Model

Jupyter Notebook, Python or R Kernel & PortfolioEffect HFT Package

Using Jupyter notebook to develop strategies, do research or monitor your portfolio is a great idea.  Jupyter supports different languages.

At PortfolioEffect, our users are currently using R or Python kernel. They directly login through our web browser to see their portfolios. Examples on how to develop strategies and monitor risks are provided.

This solution is great for institutional that use R or Python &  Academics who do research or teach a class. No installation to do, all is done for you. You just need to login and do your work.

Contact if you want more information.


You can see below an example of Jupyter notebook:


Princeton R Workshop



Princeton-PortfolioEffect Algo Trading Workshop

Sunday, April 9th from 9:00 am – 4:30 pm

Princeton, NJ

We are glad to announce that this year we are partnering with Quant Trading Conference to deliver an R Workshop.


Beginner knowledge of R and finance, college level math with RStudio installed


9:00 AM          9:30 AM          Welcome

9:30 AM          10:00 AM        Introduction to high frequency market data

10:00 AM        10:30 AM        Intraday risk metrics

10:30 AM        11:00 AM        Exercise

11:00 AM        11:30 AM        Backtesting portfolio and build your own strategies

11:30 AM        12:00 PM         Exercise on backtesting with a moving average strategy

12:00 PM         1:00 PM           Lunch break

1:00 PM           1:30 PM           Vol forecasting

1:30 PM           2:00 PM           Exercise on vol forecasting

2:00 PM           2:30 PM           Break

2:30 PM           3:00 PM           Portfolio optimization

3:00 PM           3:30 PM           Exercise

3:30 PM           4:00 PM           Strategies

4:00 PM           4:15 PM           Closing remarks


Andrey Kostin, PhD & Stephanie Toper
For any questions, email


Registration: Click here, space is limited

PortfolioEffect Utilizes Real-Time Risk Metrics To Create Alpha

Benzinga’s article on PorftolioEffect can be found on this link. We decided to post the article in the blog as it is a good description of what we do.

You can vote for PortfolioEffect here on Facebook and Linkedin for 2 votes.

PortfolioEffect Utilizes Real-Time Risk Metrics To Create Alpha

PortfolioEffect Utilizes Real-Time Risk Metrics To Create Alpha

It’s almost that time of year.

The 2017 Benzinga Global Fintech Awards is a competition to showcase the companies with the most impressive technology that are paving the future in financial services and capital markets.
To get you prepared for this year’s awards, Benzinga will profile each fintech company that has applied. Want to get involved? Submit your company here. For this installment, we spoke with PortfolioEffect Director Stephanie Toper (answers have been edited for length and clarity).


What does your company do? What unique problem does it solve?

Toper: PortfolioEffect provides a unique platform to compute real time risk metrics, optimize, backtest and forecast. All our computations are using tick market data. It means if you have a news event or a flash crash, you risk metrics should indicate you right away what is happening and you can react accordingly. Imagine if you had to wait the end of day numbers to be able to rebalance your portfolio accordingly, it might be too late.

It’s powerful tool to develop your strategy and create alpha. We have some of the strategy examples on our website or blog.

  • 40+ portfolio metrics (VaR, ETL, alpha, beta, Sharpe ratio, Omega ratio, etc.)
  • Supports R, Matlab, Java & Python
  • 10+ portfolio optimizations
  • 8k+ market tick data sources since 2012 (stocks, indices & ETFs traded on NASDAQ). Clients can also upload their own market data (e.g.: Chinese stocks).

Who are your customers?

Toper: Our main customers are hedge funds, asset managers and single users. We have two main products right now:

  • Our user friendly platform that you can access through 4 APIs: Python, Matlab, Java and R
  • Two databases that we sell through Quandl (Vol&Risk Factors, Risk&Performance Metrics)
  • Coming up: Forecasted Vol databases end of day (today,1D,1W) & Intra-day (now, 15min, 30min). If some people are interested, let us know and we can keep you up updated when they are live.

How long have you been in business?

Toper: We have been in business for about five years. At first, we had a long research phase to be able to compute real time risk as this topic is still under research of a lot of academics. Product is now ready to use. We are currently the selling and partnering phase.

I used to work in different front office positions. I noticed that a lot of institutions are not able to provide intra-day risk, which could be very frustrating as a trader where knowing alpha, beta, vol of your portfolio is crucial to understand the complexity of the market or develop accurate strategy.

Being able to deal with tick market data is the future.

Is there anything else Benzinga should know about your company?

Toper: We are working with different partners to integrate our real time risks to their platforms. If you want to become partners, contact us.

Moving Average Strategy using hft Python package

Package Installation

For hft package installation, you will need to have Anaconda2 and JDK installed. Please take a look at the manual.

conda install -c portfolioeffect hft

Strategy description

We use price vector to create a strategy based on moving average. We assume
that prices tend to revert to its moving average. Therefore, if the prices are
below its moving average, we get into the position by 1 unit. If prices are above
the moving average, we are out of position. The window length of the moving
average is 150 seconds.

  • if stock price<MA(price, N-second) => buy 1 share
  • if stock price>MA(price, N-second) => out of position

Using 3 stocks :

  • Dr. Reddy’s Laboratories Ltd (RDY)
  • ICICI Bank Limited (IBN)
  • Tata Motors Ltd Tata Motors Limited (TTM)





Expected Return


Value at Risk

Implementation of the strategy using hft Python package

 dateStart = "t-7"
 dateEnd = "t"
 portfolio = Portfolio(fromTime=dateStart, toTime=dateEnd)
 for symbol in symbols:
    portfolioTemp = Portfolio(fromTime=dateStart, toTime=dateEnd)
    position = portfolioTemp.add_position(symbol, 1)
    price = compute(position.price())[0]
    price_value = np.asarray(price[1])
    print_time = price[0]
    strategy = np.asarray([0] * len(price_value))
    price_value_MA = np.asarray(MA(price_value, 150))
    strategy[price_value < price_value_MA] = 100
    position = portfolio.add_position(symbol=symbol, quantity=strategy.tolist(),