GithubHelp home page GithubHelp logo

tutorials's Introduction

Tutorials

IPython notebooks for trading and math tutorials. You can view these here in github, or you can download and run locally on your computer. You will need to have the auquanToolbox installed to be able to run them.

For instructions on how to install the toolbox, visit here

Contents:

Trading Strategies:

  1. Mean Reversion Basics
  2. Momentum Strategy Basics
  3. How to measure momentum
  4. Model Selection Pitfalls
  5. Avoid Overfitting
  6. Pairs Trading
  7. Long-Short Strategies using Ranking

Math

  1. Random Variables
  2. Expected Value and Standard Deviation
  3. Covariance, Correlation and Confidence Intervals
  4. Stationarity, Integration and CoIntegration

Time Series Analysis

  1. Part 1 - Stationarity, Auto Correlation, White Noise and Random Walks
  2. Part 2 - AR and MA models
  3. Part 3 - ARMA and ARIMA models
  4. Part 4 - ARCH and GARCH models

tutorials's People

Contributors

belachkar avatar chandinijain avatar davidardagh avatar jackyk-ssk avatar jhurley13 avatar kanavarora avatar kunal017 avatar teamauquan avatar yankovai-google 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  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

tutorials's Issues

Tensorboard Plot View

Very interesting code to ML for Trading. Having tried
tensorboard --logdir=tb_logs/
for several times, still couldn't view the live plots because of Tensorboard timeout issue. Is there anyway to solve or better way to view results?

Thank you.

Pairs trading backtester

Hi there,

I have a question about the pairs trading backtester: how would you calculate the ROI of the algorithm?

Chart is wrong

On the notebook "Integration, Cointegration..." The chart just above the title "Testing for cointegration" is wrong on the github preview. I think it just needs reuploading.

This is mine:
image

Mismatched ARIMA model orders

In [50] block, we have obtained:

aic: 14263.11094 | order: (4, 1, 3)

But why do we end up with the conclusion that the best fit is ARIMA(2,1, 1) then? Shouldn't it be ARIMA(4, 1, 3)?

DataSource

Getting the following error message, how do I rectify?
Capture1

ImportError: No module named backtester.dataSource.yahoo_data_source

Minor Syntax Bugs

In cell 124 can you make the print statement python 3 compatible (the rest of the print statements are)? Also, in cell 122 'Adj Close' should be 'adjClose'.

Question about the momentum_backtest

Hello, I am new to the toolbox. I have the following questions:

  1. When I try to modify the strategy, I add some features like ma_50, ma_200, the current ma value minus the previous one etc., and following the instruction to add those features. However, I encountered a bunch of WARNING:root:NaN or Inf found in input tensor. when running the start trading function. The sample file is attached. How should I solve the problem?
    momentum_backtest.zip

  2. May someone explains the logic of the code of Hurst components? It seems a different approach from the reference link provided or maybe I just don't understand the logic.

Thank you a lot for your help.

key error

ds = YahooStockDataSource(cachedFolderName=cachedFolderName,
dataSetId=dataSetId,
instrumentIds=instrumentIds,
startDateStr=startDateStr,
endDateStr=endDateStr,
event='history')

This line gives following error.
Processing data for stock: SPY

KeyError Traceback (most recent call last)
/tmp/ipykernel_12343/1072003231.py in
13 startDateStr=startDateStr,
14 endDateStr=endDateStr,
---> 15 event='history')
16
17 # Get adjusted closing price

/opt/conda/lib/python3.7/site-packages/backtester/dataSource/yahoo_data_source.py in init(self, cachedFolderName, dataSetId, instrumentIds, startDateStr, endDateStr, event, adjustPrice, downloadId, liveUpdates, pad)
117 self.event = event
118 if liveUpdates:
--> 119 self._allTimes, self._groupedInstrumentUpdates = self.getGroupedInstrumentUpdates()
120 self.processGroupedInstrumentUpdates()
121 self._bookDataFeatureKeys = self.__bookDataByFeature.keys()

/opt/conda/lib/python3.7/site-packages/backtester/dataSource/data_source.py in getGroupedInstrumentUpdates(self)
65 print('Processing data for stock: %s' % (instrumentId))
66 fileName = self.getFileName(instrumentId)
---> 67 if not self.downloadAndAdjustData(instrumentId, fileName):
68 continue
69 with open(fileName) as f:

/opt/conda/lib/python3.7/site-packages/backtester/dataSource/yahoo_data_source.py in downloadAndAdjustData(self, instrumentId, fileName)
131 def downloadAndAdjustData(self, instrumentId, fileName):
132 if not os.path.isfile(fileName):
--> 133 if not downloadFileFromYahoo(self._startDate, self._endDate, instrumentId, fileName):
134 logError('Skipping %s:' % (instrumentId))
135 return False

/opt/conda/lib/python3.7/site-packages/backtester/dataSource/data_source_utils.py in downloadFileFromYahoo(startDate, endDate, instrumentId, fileName, event)
28 def downloadFileFromYahoo(startDate, endDate, instrumentId, fileName, event='history'):
29 logInfo('Downloading %s' % fileName)
---> 30 cookie, crumb = getCookieForYahoo(instrumentId)
31 start = int(mktime(startDate.timetuple()))
32 end = int(mktime(endDate.timetuple()))

/opt/conda/lib/python3.7/site-packages/backtester/dataSource/data_source_utils.py in getCookieForYahoo(instrumentId)
15 req = requests.get(url)
16 txt = req.content
---> 17 cookie = req.cookies['B']
18 pattern = re.compile('.*"CrumbStore":{"crumb":"(?P[^"]+)"}')
19

/opt/conda/lib/python3.7/site-packages/requests/cookies.py in getitem(self, name)
326 .. warning:: operation is O(n), not O(1).
327 """
--> 328 return self._find_no_duplicates(name)
329
330 def setitem(self, name, value):

/opt/conda/lib/python3.7/site-packages/requests/cookies.py in _find_no_duplicates(self, name, domain, path)
397 if toReturn:
398 return toReturn
--> 399 raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
400
401 def getstate(self):

KeyError: "name='B', domain=None, path=None"

Tried locally and on cloud.

Please let me know what is wrong.(all necessary modules are imported)
Also I didn't edit file from tutorial--> pairs_trading.ipynb

pair trading backtester logic is wrong

your PnL calculation for the exit scenario is wrong

        elif abs(zscore[i]) < 0.5:
            money += countS1*S1[i] - S2[i] * countS2
            count = 0

not sure what you are resetting count for since it was never used in the code. and why is countS2 making a negative impact to PnL? if you fix these two issues, the strategy is not profitable at all.

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.