Skip to content

Instantly share code, notes, and snippets.

@why-not
Created September 13, 2019 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save why-not/51084838fa3e1ff8d16a68af8e11f907 to your computer and use it in GitHub Desktop.
Save why-not/51084838fa3e1ff8d16a68af8e11f907 to your computer and use it in GitHub Desktop.
pandas data reader for stock data.
# command to install this library.
# conda install pandas-datareader
# example 1
import pandas_datareader as pdr
tsla = pdr.DataReader('tsla', data_source='google', start='2017-1-1')
# example 2
# calculates the trailing stop order price, can be used for weight loss like time series as well.
# Cumulative functions are nice.
def set_trailing_loss(symbol, purchase_date, perc):
close = pdr.DataReader(symbol, 'google', start=purchase_date)['Close']
return close.cummax() * perc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment