Learning TensorFlow: Setting up the Environment

I am going to create a series of myself going through the TensorFlow training. My ultimate goal is to be better using the framework and expand beyond RL.

First, I had to create a new environment (tf_current) so that I won’t break my other projects that are NOT using TensorFlow 1.12. To do that I ran the following commands from the Anaconda 3.3 prompt:

conda create -n tf_current python=3.6

After that I had to download the latest TensorFlow version:

pip install tensorflow

I had to install a plugin that would allow the Juypter Notebook to change kernels

conda install nb_conda

Once I did that I had new entries in the start menu for both (root) and (tf_current). But, since Windows hates me the links don’t work because the length of the shortcut text. It doesn’t matter because I can load the normal Jupyter Notebook and when I select “New” I can select the tf_current environment.


DDQN TensorFlow v2 Upgrade

In my previous blog post I showed how I upgraded my Black Scholes/Monte Carlo notebook to use TensorFlow v2. Today, I am going to show how I was EXTREMELY easily able to convert DDQN to the pre release of TensorFlow v2.

The notebook is located here: DDQN-TFv2.ipynb

Since I was mostly using Keras there were a few library changes but the code ran pretty much as is.

Black Scholes TensorFlow v2 Upgrade

In my previous blog post I showed how to use TensorFlow to price options using Black Scholes and running a Monte Carlo Simulation. Today, I am going to show how I was able to convert that code to the pre release of TensorFlow v2.

The notebook is located here: MonteCarloBlackScholes-TF2.ipynb

The largest change was moving from using Sessions to using Functions with the addition of eager execution. There were some stumbling blocks but once I went through a few changes it all made sense and should be easy for any future upgrades.

TensorFlow and Quants

During this post I am going to go over a topic I found online by Matthias Groncki about using TensorFlow for Monte Carlo simulations using the Black-Scholes model. For sure check out his post but I am going to walk through doing this work as a way to force myself into using features of TensorFlow.

First, if you didn’t know, a Monte Carlo Simulation is a way to find the probability of different outcomes. In investing they are used to help understand the impact of risk and uncertainty. I have seen these done in Excel before but until I read Matthais’ post I never thought to give them a run in TensorFlow.

Second, the Black-Scholes model is a mathematical model that is used for pricing derivative investments.

Third, a plain vanilla call that I will be using is when you buy a call with a certain strike price and a certain expiration date. Buying the call means that you promise to buy that stock at a set price on a set date. Typically, there is something called an option premium that you will pay in order to enter into the contract. For example, let say that Wells Fargo (WFC) is trading at $50 on August 30th. You think it will go up at least 10% before the end of the year. So, you would buy the December 21st expiration with a strike price of $55. For the rights to buy that you would pay $3 in options premium. There are 3 common scenarios. First, the stock stays below $55 and you lose the premium and you don’t get the shares. Second, the stock goes above $55 and you get to purchase those shares for $55. Third, you sell the options to someone else and collect the money.

Tying this back to Black-Scholes, they thought they knew of a formula to correctly price these through the time to maturity. They actually won a noble prize for their creation. For a fun little read, check out Long-Term Capital Management to see how poorly this did when the 1997 Asian and 1998 Russian financial crises hit.

Checkout my Jupyter Notebook from my GitHub page for all the code and a more in depth walk-through: MonteCarloBlackScholes.ipynb. I work through a simple python implementation of Black-Scholes and then first up TensorFlow and run a lot of simulations.