Giter Site home page Giter Site logo

mastering-python-for-finance-second-edition's Introduction

Mastering Python for Finance - Second Edition

Mastering Python for Finance - Second Edition

This is the code repository for Mastering Python for Finance - Second Edition, published by Packt.

Implement advanced state-of-the-art financial statistical applications using Python

What is this book about?

The second edition of Mastering Python for Finance will guide you through carrying out complex financial calculations practiced in the industry of finance by using next-generation methodologies. You will master the Python ecosystem by leveraging publicly available tools to successfully perform research studies and modeling, and learn to manage risks with the help of advanced examples.

This book covers the following exciting features:

  • Solve linear and nonlinear models representing various financial problems
  • Perform principal component analysis on the DOW index and its components
  • Analyze, predict, and forecast stationary and non-stationary time series processes
  • Create an event-driven backtesting tool and measure your strategies
  • Build a high-frequency algorithmic trading platform with Python

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Errata

  • Page 51 - A minimization example with integer programming (3rd sentence): Dealer Y charges $450 per contract plus a transaction fee of $2,000. should be Dealer Y charges $350 per contract plus a transaction fee of $2,000.

Instructions and Navigations

All of the code is organized into folders. For example,

The code will look like the following:

In [ ]:
%matplotlib inline
import quandl
quandl.ApiConfig.api_key = QUANDL_API_KEY
df = quandl.get('EURONEXT/ABN.4')
daily_changes = df.pct_change(periods=1)
daily_changes.plot();

Following is what you need for this book: If you are a financial or data analyst or a software developer in the financial industry who is interested in using advanced Python techniques for quantitative methods in finance, this is the book you need! You will also find this book useful if you want to extend the functionalities of your existing financial applications by using smart machine learning techniques. Prior experience in Python is required.

With the following software and hardware list you can run all code files present in the book (Chapter 1-11).

Software and Hardware List

Chapter Software required OS required
1-10 Python 3.7 Windows, Mac OS X, and Linux (Any)
11 Python 3.6 Windows, Mac OS X, and Linux (Any)

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

Related products

Get to Know the Author

James Ma Weiming is a software engineer based in Singapore. His studies and research are focused on financial technology, machine learning, data sciences, and computational finance. James started his career in financial services working with treasury fixed income and foreign exchange products, and fund distribution. His interests in derivatives led him to Chicago, where he worked with veteran traders of the Chicago Board of Trade to devise high-frequency, low-latency strategies to game the market. He holds an MS degree in finance from Illinois Tech's Stuart School of Business in the United States and a bachelor's degree in computer engineering from Nanyang Technological University.

Other books by the authors

Suggestions and Feedback

Click here if you have any feedback or suggestions.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781789346466

mastering-python-for-finance-second-edition's People

Contributors

jamesmawm avatar manikandankurup-packt avatar packt-itservice avatar packtutkarshr 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

mastering-python-for-finance-second-edition's Issues

regression model in ch10 not working

tried to run the code, but linear_reg_model.df_result comes empty.

tried to change date parameters to NA (specific dates instead of 2018-2019), seems to be something different.

Chap 7 alpha_vantage SPX & VIX data no longer available

Could I get some help finding substitute data source as I think alpha_vantage no longer provides data for the subject tickers.

symbol='^GSPC'
symbol='^VIX'

Strangely symbol='NDAQ' still works.

Update
I incorrectly assumed NDAQ was Nasdaq index. See comment below and Alpha Vantage website stating indexes no longer supported.

no numeric data to plot

issue with plotting, df_result

TypeError Traceback (most recent call last)
in
1 get_ipython().run_line_magic('matplotlib', 'inline')
2
----> 3 linear_reg_model.df_result.plot(
4 title='JPM prediction by OLS',
5 style=['-', '--'], figsize=(12,8));

/opt/anaconda3/lib/python3.8/site-packages/pandas/plotting/_core.py in call(self, *args, **kwargs)
947 data.columns = label_name
948
--> 949 return plot_backend.plot(data, kind=kind, **kwargs)
950
951 call.doc = doc

/opt/anaconda3/lib/python3.8/site-packages/pandas/plotting/_matplotlib/init.py in plot(data, kind, **kwargs)
59 kwargs["ax"] = getattr(ax, "left_ax", ax)
60 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
---> 61 plot_obj.generate()
62 plot_obj.draw()
63 return plot_obj.result

/opt/anaconda3/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py in generate(self)
267 def generate(self):
268 self._args_adjust()
--> 269 self._compute_plot_data()
270 self._setup_subplots()
271 self._make_plot()

/opt/anaconda3/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py in _compute_plot_data(self)
416 # no non-numeric frames or series allowed
417 if is_empty:
--> 418 raise TypeError("no numeric data to plot")
419
420 # GH25587: cast ExtensionArray of pandas (IntegerArray, etc.) to

TypeError: no numeric data to plot

How would we adjust the code to calculate implied volatility for a call option?

I was hoping it would be as simple as changing the is_put = False but it kicks up this error?

Traceback (most recent call last):
File "implied_volatility.py", line 44, in
impvols_put = model.get_implied_volatilities(strikes, put_prices)
File "implied_volatility.py", line 33, in get_implied_volatilities
impv = bisection(f, 0.01, 0.99, 0.0001, 100)[0]
File "C:\Python38\Lib\site-packages\bisection.py", line 15, in bisection
if f(c) == 0 or abs(a-b)0.5 < tol:
File "implied_volatility.py", line 31, in
self.option_valuation(Ks[i], sigma)-
File "implied_volatility.py", line 24, in option_valuation
return lr_option.price()
File "C:\Python38\Lib\site-packages\BinomialTreeOption.py", line 59, in price
self.setup_parameters()
File "C:\Python38\Lib\site-packages\BinomialLROption.py", line 23, in setup_parameters
self.d = (1/self.df-self.p
self.u)/(1-self.p)
ZeroDivisionError: float division by zero

the self.d = (1/self.df-self.p*self.u)/(1-self.p) comes from the BinomialLROption script
I tried to fix the problem by increasing N but I think the results are inccorect

I think its just a mathmatical issue caused by numbers being near 0 when you use a more realistic scenario i.e not just flip to false it seems to produce accurate numbers.

chapter 11. TypeError: Cannot join tz-naive with tz-aware DatetimeIndex

df_close "date" is not the same as all the other "technicals" df and trying to join them results in the error:
TypeError: Cannot join tz-naive with tz-aware DatetimeIndex`

I'm sure it's an easy fix for experienced pandas user. If I figure it out I'll post fix.
edit - try inserting 2nd line here:
df['date_time'] = pd.to_datetime(df['date_time'])
df['date_time'] = df['date_time'].dt.date
df = df.set_index('date_time')

alpha_vantage time fraome TimeSeries now seem to be reduced for chapter 6

I want to get the DJIA values for 2020 in order to reproduce it with a Principal Component Analysis following chapter 6 using alpha_vantage. Yet it seems that if James Ma was able to get the data for the whole year, now it seems that we only have two months:

"""
Download the all-time DJIA dataset
"""
from alpha_vantage.timeseries import TimeSeries

# Update your Alpha Vantage API key here...
ALPHA_VANTAGE_API_KEY = 'MYKEY'

from pprint import pprint
ts = TimeSeries(key=ALPHA_VANTAGE_API_KEY, output_format='pandas')
df, meta_data = ts.get_intraday(symbol='DIA',interval='1min', outputsize='full')
pprint(df.info())

Returns:

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 5351 entries, 2021-02-03 20:00:00 to 2021-01-21 04:02:00
Data columns (total 5 columns):
 #   Column     Non-Null Count  Dtype  
---  ------     --------------  -----  
 0   1. open    5351 non-null   float64
 1   2. high    5351 non-null   float64
 2   3. low     5351 non-null   float64
 3   4. close   5351 non-null   float64
 4   5. volume  5351 non-null   float64
dtypes: float64(5)
memory usage: 250.8 KB

Has alpha_vantage reduced the available data? Can I extend the timeframe? If it is not possible, how can I get the data for the DJIA otherwise?

Side note: ticker ^DJI isn't available anymore.

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.