Back to Community
[Research CLONABLE] Do you want parameter optimization? Click here to get started. [Heat Maps included]

[UPDATE] This is the clonable version.

Okay, I lied a little. This isn't quite parameter optimization. It's more of a brute force parameter search.

What I'm about to show you isn't the most efficient, it isn't the most powerful, and it isn't the fastest and most innovative method out there. But it works, it's simple, and it might just make your life a whole lot easier! I've used this a lot to help with my own algorithm writing and development and it's been super helpful while trying to figure out what parameters (weights, symbols, etc.) are best suited for my algorithms.

The notebook has a much more clear description so I highly recommend that you click '**View Notebook**' in order to get started but if you want the basic summary, here it is:

The Scenario

Let's say I want an algorithm that only longs AAPL and SPY but I don't know how much to hold in each security. I could try hitting 'build algorithm' 50 times in the IDE but that's tedious and my macbook can't open that many tabs. So what do I do?
The answer is easy: Create that same algorithm in Zipline and spin up 50 algorithm runs. Each run will have different parameters and because I can get the results of each run through Zipline, I can see exactly which parameter led to the best returns or Sharpe ratio.

Loading notebook preview...

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

10 responses

**thanks for making it clonable... to my surprise... thought this wud already be plug and play... since its clone...
NameError Traceback (most recent call last)
in ()
----> 2 import zipline
3 import pytz
4 from datetime import datetime
5 import matplotlib.pyplot as pyplot

NameError: name '_af5fc2a173964473da51cec4be503cc8fmake_safe' is not defined**

**NameError Traceback (most recent call last)
in ()
----> 2 data = get_pricing(
3 ['AAPL', 'SPY'],
4 start_date='2014-01-01',
5 end_date = '2015-02-15',

NameError: name 'get_pricing' is not defined**

NameError Traceback (most recent call last)
in ()
----> 1 aapl_weights = [weight for weight in np.arange(0, 1, .2)]
2 spy_weights = [weight for weight in np.arange(0, 1, .2)]
4 #: Create a dictionary to hold all the results of our algorithm run
5 all_sharpes = defaultdict(dict)

NameError: name 'np' is not defined

NameError Traceback (most recent call last)
in ()
----> 1 import matplotlib.pyplot as pyplot
3 def heat_map(df):
4 """
5 This creates our heatmap using our sharpe ratio dataframe
NameError: name '_af5fc2a173964473da51cec4be503cc8fmake_safe' is not defined**

by clicking... theclne note button dats it... :D same as clone algo althou... algo i dont have any issues... after cloning i can clone again... to clarify.. if same results :)

Hi John,

Please check your inbox. We've sent over a couple helpful tips to get you started.


Seong... it already work three times is a charm... the third clone copy is already working... thanks.... I will clone again.. since its already working... ;)

what does zero.. sharpe ratio means... dont invest in that stock I got a zero .. by substituting other stocks. :)

TypeError: argument of type 'TradingAlgorithm' is not iterable

what am I doing wrong?

Loading notebook preview...

Hi Seong,

This must the very nice thing that I am looking for. I've cloned your notebook. But as I run it at the very beginning, I got error:

ImportError Traceback (most recent call last)
in ()
11 from zipline import TradingAlgorithm
---> 12 from zipline.api import order_target, record, symbol, history, add_history, order_target_percent, order
13 import numpy as np
14 import pandas as pd

ImportError: cannot import name add_history

Sorry, after I've taken out the 'add_hidtory', it works.


But this seems just for two dimention (weight of two different stocks)? If I have many parameters, for example I will take concern of the momentum and there are 4 factors, how to do in this case?


At that point, you may want to optimize by local gradient ascent. scipy offers many options for doing so.

But it's important to consider that the more parameters you optimize over, the greater your risk of overlearning. Out-of-sample testing is critical for models with complex parameter spaces.