IBKR Quant Blog


1 2 3 4 5 2 31


Quant

How To Install TensorFlow GPU (With Detailed Steps)


By Varun Divakar

When I started working on Deep Learning (DL) models, I found that the amount of time needed to train these models on a CPU was too high and it hinders your research work if you are creating multiple models in a day. Later I heard about the superior performance of the GPUs, so I decided to get one for myself. One of the basic problems that I initially faced was the installation of TensorFlow GPU.

After a lot of trouble and a burnt motherboard (not due to TensorFlow), I learnt how to do it. A few days earlier I spoke to someone who was facing a similar issue, so I thought I might help people who are stuck in a similar situation, by writing down the steps that I followed to get it working.

In this blog, we will understand how to install tensorflow on a Nvidia GPU system. Before we do that, let us look at the various steps involved in the process of installation:

  1. Uninstall Nvidia
  2. Install Visual Studio
  3. Install CUDA
  4. Install cuDNN
  5. Install Anaconda
  6. Install TensorFlow-GPU
  7. Install Keras

 

1. Uninstall Nvidia

This may not look like a necessary step, but believe me, it will save you a lot of trouble if there are compatibility issues between your current driver and the CUDA. Once you login to your system, go to the control panel, and then to the ‘Uninstall a program’ link. Then scroll below to the section with programs that have been published by the NVIDIA corporation.

Quant

Here, you uninstall all the NVIDIA programs. Do not worry if you have some drivers, they can be updated later once you finish the setup.

Once you have removed all the programs, go to the C drive and check all the program files folders and delete any NVIDIA folders in them.

Quant

 

2. Install Visual Studio

In the next step, we will install the visual studio community from here

Qaunt

 

Here, make sure that you select the community option.

 

Quant

 

 

Once you have downloaded the Visual Studio, follow the setup process and complete the installation.

 

3. Install CUDA

This is a tricky step, and before you go ahead and install the latest version of CUDA (which is what I initially did), check the version of CUDA that is supported by the latest TensorFlow, by using this link.

I have a windows based system, so the corresponding link shows me that the latest supported version of CUDA is 9.0 and its corresponding cuDNN version is 7.

Quant

As it goes without saying, to install TensorFlow GPU you need to have an actual GPU in your system. So please check if you have a GPU on your system and if you do have it, check if it is a compatible version using the third link in the above screenshot.

Once you are certain that your GPU is compatible, download the CUDA Toolkit 9.0 from this link.

Please choose your OS, architecture (CPU type of the platform) and version of the OS correctly. Then click on the exe(local) button,

Now download the base installer and all the available patches along with it.

Quant

Once the download is complete, install the base installer first followed by the patches starting from Patch 1 to Patch 4.

 

4. Install cuDNN

Once your installation is completed, you can download the cuDNN files. To do this, go to this link.

Here to download the required files, you need to have a developer’s login. So, please go ahead and create your login if you do not have one.

Once you create your login and agree to the terms and conditions, visit the archived cuDNN files using this link.

And click on the cuDNN version 7.0 for CUDA 9.0

Quant

Then choose the appropriate OS option for your system.

Quant

This will download a zip file on to your system. Once you unzip the file, you will see three folders in it: bin, include and lib. Extract these three files onto your desktop.

Quant

Once you have extracted them. Go to the C drive, there you will find a folder named NVIDIA GPU Computing Toolkit. Inside this, you will find a folder named CUDA which has a folder named v9.0. In this folder, you can see that you have the same three folders: bin, include and lib. Copy the contents of the bin folder on your desktop to the bin folder in the v9.0 folder. Similarly, transfer the contents of the include and lib folders.

Once you are done with the transfer of the contents, go to the start menu and search for ”edit the environment variables”. Click on the search result and open the System Properties window and within it open the Advanced tab.

Quant

Now click on the ‘Environment Variables’,

Quant

and under System Variables look for PATH, and select it and then click edit.

Add the following two paths to the path variable:

  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp

Quant

Once you are done with this, you can download Anaconda, and if you already have it, then create a Python 3.5 environment in it.

 

5. Install Anaconda

To install Anaconda on your system, visit this link.

Here choose your OS and the Python 3.6 version, then click on download. Follow the instructions in the setup manager and complete the installation process.

Once you have completed the installation of Anaconda. Create a python 3.5 environment using the following command in the terminal or anaconda prompt.

conda create -n tensorflow python=3.5

Once the environment is created, activate it using the following command in the terminal or anaconda prompt:

activate tensorflow

 

6. Install TensorFlow- GPU

Once you have the environment ready, you can install the tensorflow GPU using the following command in the terminal or anaconda prompt:

pip install --ignore-installed --upgrade tensorflow-gpu

You will need to specify the version of tensorflow-gpu, if you are using a different version of CUDA and cuDNN than what is shown in this blog. The above line installs the latest version of tensorflow by default. If you have any issues while installing tensorflow, please check this link.

 

7. Install Keras

Once the tensorflow is installed, you can install Keras. Using the following command:

pip install keras

Once the installation of keras is successfully completed, you can verify it by running the following command on Spyder IDE or Jupyter notebook:

import keras

Some people might face an issue with the msg package. In case you do, you can install it using the following command

conda install -c anaconda msgpack-python

 

I hope you have successfully installed the tensorflow- gpu on your system.

In this article, we have covered many important aspects like how to install Anaconda, how to install tensorflow, how to install keras, by installing tensorflow gpu on windows. We started by uninstalling the Nvidia GPU system and progressed to learning how to install tensorflow gpu.

 

If you want to learn more about QuantInsti, or to download sample code, visit QuantInsti website and the educational offerings at their Executive Programme in Algorithmic Trading (EPAT™).

 

This article is from QuantInsti and is being posted with QuantInsti’s permission. The views expressed in this article are solely those of the author and/or QuantInsti and IB is not endorsing or recommending any investment or trading discussed in the article. This material is for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IB to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


20049




Quant

Introduction to the IBKR TWS C++ API - a webinar recording with IBKR API Team


View the recording

The Interactive Brokers API Team demonstrated:
 

  1. Overview of TWS API capabilities and setup
  2. Availability of C++ API on various platforms (Windows, Linux, OSX)
  3. API architecture from a programming perspective
  4. Example of the flow of an API program execution using the 'Testbed' sample from version 9.72
  5. Examples of API functions, such as to request market data and place orders, and expected results

 

IBKR

 

Start your FREE Trial Simulated account and test your trading strategies with the IBKR C++ API!

FREE TRIAL

 

Information posted on IBKR Quant that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Quant are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.


20197




Quant

Practical Statistics for Algo Traders - Part 4


Why the Law of Large Numbers Matters to Traders


The first installments in this series are available here.

As much as I’m sure you enjoy thinking about the statistics of burger review systems, let’s turn our attention to trading. In particular, I want to show you how our intuition around the law of large numbers can lead us to make bad decisions in our trading, and what to do about it.

High-frequency trading strategies typically have a much higher Sharpe ratio than low frequency strategies, since the variability of returns is generally much higher in the latter. If you had a high-frequency strategy with a Sharpe ratio in the high single digits, you’d only need to see a week or two of negative returns – perhaps less – to be quite sure that your strategy was broken.

But most of us don’t have the capital or infrastructure to realise a high-frequency strategy. Instead, we trade lower frequency strategies and accept that our Sharpe ratios are going to be lower as well. In my experience, a typical non-professional might consider trading a strategy with a Sharpe between about 1.0 and 2.0.

How long does it take to realise such a strategy’s true Sharpe? And how much could that Sharpe vary when measured on samples of various sizes? The answer, which we’ll get too shortly, might surprise you, or even scare you! Because it turns out that a “large” number may or may not be so large, depending on the context. And that lack of context awareness is precisely where we tend to make our most severe errors in the application of the Law of Large Numbers.

First of all, let’s simulate various realisations of 40 days of trading a strategy with a true Sharpe ratio of 1.5. This is equivalent to around two months of trading.

If we set the strategy’s mean daily return, mu , to 0.1%, we can calculate the standard deviation of returns, sigma , that results in a true Sharpe of 1.5:

Quant

And here’s 5,000 realisations of 40 days of trading a strategy with this performance (under the assumption that daily returns are normally distributed, an inaccurate but convenient simplification that won’t detract too much from the point):

Quant

Quant

Whoa! The histogram shows that it isn’t inconceivable (in fact it’s quite likely) that our Sharpe 1.5 strategy could give us an annualised Sharpe of -2 or less over a 40-day period!

What would you do if the strategy you’d backtested to a Sharpe of 1.5 had delivered an annualised Sharpe of -2 over the first two months of trading? Would you turn it off? Tinker with it? Maybe adjust a parameter or two?

You should probably do nothing! At least until you’ve assessed the probability of your strategy delivering the actual results, assuming it’s performance was indeed what you’d backtested it to be. To do that, you can just sum up the number of simulated 40-day Sharpes that were less than or equal to -2, and then divide by the number of Sharpes we simulated:

Quant

which works out to about 8.5%.

Let’s now look at the convergence of our Sharpe ratio to the expected Sharpe as we increase the sample size, just as we did in the burger review example above. Here’s the code:

Quant

 

And the output:

Quant

 

Once again we see the sample uncertainty shrink as we increase the sample size, but this time it’s magnitude looks much more frightening. Note the uncertainty even after 500 trading days! This implies that our strategy with a long-term Sharpe of 1.5 could conceivably deliver very small or even negative returns in a two-year period.

If you’ve done a lot of backtesting, you probably understand from experience that a strategy with a Sharpe of 1.5 can indeed have drawdowns that last one or two years. So maybe this result doesn’t surprise you that much. But consider how you’d feel and act in real time if you suffered through such a drawdown after going live with this strategy that you’d painstakingly developed. Would you factor the uncertainty of the sample size into your decision making?

The point is that this time the uncertainty really matters. Maybe you don’t care that much if you thought you were getting a 5-star burger, but ended up eating a 4-star offering. You could probably live with that. But what if you were expecting to realise your Sharpe 1.5 strategy, but after 2 years you’d barely broken even?

Returning to our 40-days of unprofitable trading of our allegedly profitable strategy. As mentioned above, there’s an 8.5% chance of getting an annualised Sharpe of -2 from this scenario. Maybe that’s enough to convince you that your strategy is not actually going to deliver a Sharpe of 1.5. Maybe you’d be willing to stick it out until the probability dropped below 5%. It’s up to you, and in my opinion should depend at least to some extent on your prior beliefs about your strategy.1  For instance, if you had a strong conviction that your strategy was based on a real market anomaly, maybe you’d stick to your guns longer than if you had simply data-mined a pattern in a price chart with no real rationalisation for it’s profitability. This is an important point, and I’ll touch on it again towards the end of the article.

No doubt you’ve already realised that the backtest itself is unlikely to be a true representation of the strategy’s real performance. Due to it’s finite history, the backtest itself is just a “sample” from the true “population”! So how much confidence can you have in your backtest anyway?

In the next article, I’ll show you a method for incorporating both our prior beliefs about our strategy’s backtest and the new information from the 40 trading days to construct credible limits on our strategy’s likely true performance. As you might imagine from the scatterplot above, that interval will likely be quite wide, so there’s really no way around acknowledging the inherent uncertainty in the problem of whether or not to continue trading our strategy.

 

  1. I deliberately used the term “prior” here as a reference to Bayesian reasoning, which in my opinion is a great way to think about all kinds of problems like these. I’d like to come back to this topic in the future. Let me know in the comments if that interests you.

---------------------------------------------------------------------------

To download the code used in this article, and to learn more about Robot Wealth click here: https://robotwealth.com/

This article is from Robot Wealth and is being posted with Robot Wealth’s permission. The views expressed in this article are solely those of the author and/or Robot Wealth and IB is not endorsing or recommending any investment or trading discussed in the article. This material is for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IB to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


20107




Quant

What Works (and Doesn't Work) in Cryptocurrencies*


By Quantpedia

Authors: Yang

Title: Behavioral Anomalies in Cryptocurrency Markets

Link: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3174421

Abstract:

If behavioral biases explain asset pricing anomalies, they should also materialize in cryptocurrency markets. I test more than 20 stock return anomalies based on daily cryptocurrency data, and document strong evidence of price momentum. Unlike stock markets, price reversal and risk-based anomalies are weak, controlling for market and size. Cryptocurrency anomalies can be explained by behavioral theories that place more emphasis on the role of speculators than fundamental traders.

Notable quotations from the academic research paper:

"The speculative and hard-to-value nature makes the cryptocurrency market a novel environment that facilitates the study of behavioral impacts on asset prices. Because speculators account for the vast majority of cryptocurrency market participants, the behavioral impact can be stronger than traditional markets. Aside from this, cryptocurrency markets enjoy some good properties: the overall level of investor sophistication in cryptocurrency markets are much lower; there are only a few institutional investors until recently. Thus, mispricing can be severe. Above stylized facts of cryptocurrency markets fit well into many behavioral theories that particularly emphasize investor irrationality. Thus, if asset pricing anomalies can be explained by behavioral theories, they shall also be reflected in cryptocurrency markets.

Having this in mind, I test more than 20 stock price anomalies based on cryptocurrency data.

 

Quant

 

Interestingly, anomalies that are commonly recognized as behavior-driven, in particular, price momentum, are also observed in cryptocurrency markets. Price momentum describes the phenomenon that past winner (loser) assets may continue to outperform (underperform) in the future. The momentum effect turns out statistically significant and robust in various aspects. In contrast, risk-based anomalies, for example, return moment risks, are insignificant. The results are not surprising, as if the incentive for holding cryptocurrencies is largely speculative, it is not expected that exposure to certain form of risk earns a premium.

Unlike stock markets, short-term price reversal in cryptocurrency markets is very weak at a daily frequency. No evidence of long-term price reversal is revealed. This empirical finding makes cryptocurrency anomalies distinct from stock market anomalies.

 

Quantpedia

 

The most plausible explanation of cryptocurrency momentum is given by De Long, Shleifer, Summers, and Waldmann (1990). Their model implies that overconfident noise traders push up the price and create risk that makes fundamental traders reluctant to combat mispricing. If noise traders dominate, overpricing can be even more severe, as is the case of cryptocurrency markets, where speculators play the role of overconfident noise traders. Further, their model does not predict a long-term reversal as long as noise traders remain overconfident. This situation is analogous to cryptocurreny markets and consistent with the empirical findings of this paper. Moreover, their model implies an excessive volatility, another empirical stylized fact of cryptocurrency markets."

 

 

To learn more about this paper, view the full article on Quantpedia website:

https://quantpedia.com/Blog/Details/what-works-and-doesnt-work-in-cryptocurrencies

 

 

*These financial products are not suitable for all investors and customers should read the relevant risk warnings before investing. You should be aware that your losses may exceed the value of your original investment.
TRADING IN BITCOIN FUTURES IS ESPECIALLY RISKY AND IS ONLY FOR CLIENTS WITH A HIGH RISK TOLERANCE AND THE FINANCIAL ABILITY TO SUSTAIN LOSSES.
More information about the risk of trading Bitcoin products can be found on the IB website.

 

About Quantpedia

Quantpedia Mission is to process financial academic research into a more user-friendly form to help anyone who seeks new quantitative trading strategy ideas. Quantpedia team consists of members with strong financial and mathematical background (former quantitative portfolio managers and founders of Quantconferences.com) combined with members with outstanding IT and technical knowledge. Learn more about Quantpedia here: https://quantpedia.com

This article is from Quantpedia and is being posted with Quantpedia’s permission. The views expressed in this article are solely those of the author and/or Quantpedia and IB is not endorsing or recommending any investment or trading discussed in the article. This material is for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IB to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


20101




Quant

Introduction to the IBKR TWS Java API - a webinar recording with IBKR API Team


View the recording

The Interactive Brokers API Team demonstrated:
 

  1. Overview of IB TWS API capabilities and requirements
  2. Architecture of the IB API from a development perspective
  3. Basic flow of an API program with version 9.72 ‘Testbed’ sample as an example
  4. v. 9.72 Github API reference guide
  5. Demonstration of API functions to perform tasks such as requesting account values, or historical data
  6. v. 9.72 Github API reference guide
  7. Demonstration of API functions to perform tasks such as requesting account values, or historical data

 

IBKR

 

Start your FREE Trial Simulated account and test your trading strategies with the IBKR Java API!

FREE TRIAL

 

Information posted on IBKR Quant that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Quant are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.


20156




1 2 3 4 5 2 31

Disclosures

We appreciate your feedback. If you have any questions or comments about IBKR Quant Blog please contact ibkrquant@ibkr.com.

The material (including articles and commentary) provided on IBKR Quant Blog is offered for informational purposes only. The posted material is NOT a recommendation by Interactive Brokers (IB) that you or your clients should contract for the services of or invest with any of the independent advisors or hedge funds or others who may post on IBKR Quant Blog or invest with any advisors or hedge funds. The advisors, hedge funds and other analysts who may post on IBKR Quant Blog are independent of IB and IB does not make any representations or warranties concerning the past or future performance of these advisors, hedge funds and others or the accuracy of the information they provide. Interactive Brokers does not conduct a "suitability review" to make sure the trading of any advisor or hedge fund or other party is suitable for you.

Securities or other financial instruments mentioned in the material posted are not suitable for all investors. The material posted does not take into account your particular investment objectives, financial situations or needs and is not intended as a recommendation to you of any particular securities, financial instruments or strategies. Before making any investment or trade, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice. Past performance is no guarantee of future results.

Any information provided by third parties has been obtained from sources believed to be reliable and accurate; however, IB does not warrant its accuracy and assumes no responsibility for any errors or omissions.

Any information posted by employees of IB or an affiliated company is based upon information that is believed to be reliable. However, neither IB nor its affiliates warrant its completeness, accuracy or adequacy. IB does not make any representations or warranties concerning the past or future performance of any financial instrument. By posting material on IB Quant Blog, IB is not representing that any particular financial instrument or trading strategy is appropriate for you.