Giter Club home page Giter Club logo

trading_evolved's Introduction

Introduction

This repository contains the code from the book Trading Evolved: Anyone Can Build Killer Trading Strategies In Python by Andreas F. Clenow.

Why?

The goal of this repository is to make it easy for traders who are not software developers and/or Python programmers to get started experimenting with the code in the book. Readers do not have to worry about installing or patching zipline.

Prerequisites

Download and install the following software:

  1. Docker Desktop
  2. VS Code

Usage

  1. Create an image for zipline.

    In a terminal, execute:

    docker build -t quantopian/zipline:trading_evolved https://github.com/hsm207/zipline.git#trading-evolved
  2. Clone this project.

  3. Open devcontainer.json and replace the value of QUANDL_API_KEY with your own API key (line 33). Click here for details on how to retrieve your Quandle API key.

  4. In VS Code, open this project's root directory in a container defined by Dockerfile.

  5. When inside the container, execute jupyter notebook --allow-root to start viewing the notebooks.

  6. To ingest the quandl bundle, refer to the 01_get_quandl_data notebook,

Useful Resources

trading_evolved's People

Contributors

hsm207 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

trading_evolved's Issues

Expanded momentum model - Invalid comparison between dtype=datetime64[ns] and Timestamp

Hi, I'm stuck in chapter Chapter 12 - Momentum of the book. Tried everything. I got the following error both in Your fixed version and in the original code from the book. Can You help?

1997-01-02 - Last Month Result: 0.00%

TypeError Traceback (most recent call last)
c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\arrays\datetimelike.py in _validate_comparison_value(self, other)
444 try:
--> 445 self._check_compatible_with(other)
446 except TypeError as err:

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\arrays\datetimes.py in _check_compatible_with(self, other, setitem)
474 return
--> 475 self._assert_tzawareness_compat(other)
476 if setitem:

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\arrays\datetimes.py in _assert_tzawareness_compat(self, other)
651 if other_tz is not None:
--> 652 raise TypeError(
653 "Cannot compare tz-naive and tz-aware datetime-like objects."

TypeError: Cannot compare tz-naive and tz-aware datetime-like objects.

The above exception was the direct cause of the following exception:

InvalidComparison Traceback (most recent call last)
c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\arrays\datetimelike.py in _cmp_method(self, other, op)
931 try:
--> 932 other = self._validate_comparison_value(other)
933 except InvalidComparison:

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\arrays\datetimelike.py in _validate_comparison_value(self, other)
447 # e.g. tzawareness mismatch
--> 448 raise InvalidComparison(other) from err
449

InvalidComparison: 1997-01-02 21:00:00+00:00

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
in

c:\users...\appdata\local\programs\python\python38\lib\site-packages\zipline\utils\run_algo.py in run_algorithm(start, end, initialize, capital_base, handle_data, before_trading_start, analyze, data_frequency, bundle, bundle_timestamp, trading_calendar, metrics_set, benchmark_returns, default_extension, extensions, strict_extensions, environ, custom_loader, blotter)
395 benchmark_spec = BenchmarkSpec.from_returns(benchmark_returns)
396
--> 397 return _run(
398 handle_data=handle_data,
399 initialize=initialize,

c:\users...\appdata\local\programs\python\python38\lib\site-packages\zipline\utils\run_algo.py in _run(handle_data, initialize, before_trading_start, analyze, algofile, algotext, defines, data_frequency, capital_base, bundle, bundle_timestamp, start, end, output, trading_calendar, print_algo, metrics_set, local_namespace, environ, blotter, custom_loader, benchmark_spec)
198
199 try:
--> 200 perf = TradingAlgorithm(
201 namespace=namespace,
202 data_portal=data,

c:\users...\appdata\local\programs\python\python38\lib\site-packages\zipline\algorithm.py in run(self, data_portal)
622 try:
623 perfs = []
--> 624 for perf in self.get_generator():
625 perfs.append(perf)
626

c:\users...\appdata\local\programs\python\python38\lib\site-packages\zipline\gens\tradesimulation.py in transform(self)
226 for dt, action in self.clock:
227 if action == BAR:
--> 228 for capital_change_packet in every_bar(dt):
229 yield capital_change_packet
230 elif action == SESSION_START:

c:\users...\appdata\local\programs\python\python38\lib\site-packages\zipline\gens\tradesimulation.py in every_bar(dt_to_use, current_data, handle_data)
141 metrics_tracker.process_commission(commission)
142
--> 143 handle_data(algo, current_data, dt_to_use)
144
145 # grab any new orders from the blotter, then clear the list.

c:\users...\appdata\local\programs\python\python38\lib\site-packages\zipline\utils\events.py in handle_data(self, context, data, dt)
204 with self._create_context(data):
205 for event in self._events:
--> 206 event.handle_data(
207 context,
208 data,

c:\users...\appdata\local\programs\python\python38\lib\site-packages\zipline\utils\events.py in handle_data(self, context, data, dt)
227 """
228 if self.rule.should_trigger(dt):
--> 229 self.callback(context, data)
230
231

~\AppData\Local\Temp\tmpmim2g0sm/ipykernel_14288/3887532712.py in rebalance(context, data)
9
10 # Second, get the index makeup for all days prior to today.
---> 11 all_prior = context.index_members.loc[context.index_members.index < today]
12
13 # Now let's snag the first column of the last, i.e. latest, entry.

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\indexes\extension.py in wrapper(self, other)
132
133 op = getattr(self._data, opname)
--> 134 return op(other)
135
136 wrapper.name = opname

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\ops\common.py in new_method(self, other)
63 other = item_from_zerodim(other)
64
---> 65 return method(self, other)
66
67 return new_method

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\arraylike.py in lt(self, other)
35 @unpack_zerodim_and_defer("lt")
36 def lt(self, other):
---> 37 return self._cmp_method(other, operator.lt)
38
39 @unpack_zerodim_and_defer("le")

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\arrays\datetimelike.py in _cmp_method(self, other, op)
932 other = self._validate_comparison_value(other)
933 except InvalidComparison:
--> 934 return invalid_comparison(self, other, op)
935
936 dtype = getattr(other, "dtype", None)

c:\users...\appdata\local\programs\python\python38\lib\site-packages\pandas\core\ops\invalid.py in invalid_comparison(left, right, op)
32 else:
33 typ = type(right).name
---> 34 raise TypeError(f"Invalid comparison between dtype={left.dtype} and {typ}")
35 return res_values
36

TypeError: Invalid comparison between dtype=datetime64[ns] and Timestamp

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.