In [18]:
import datetime
from findatapy.util.loggermanager import LoggerManager
from chartpy import Chart, Style
from findatapy.market import Market, MarketDataGenerator, MarketDataRequest
This is a wrapper for logging errors/output.
In [19]:
logger = LoggerManager().getLogger(__name__)
Set the engine to output the chart. The possible engines currently is only matplotlib
In [20]:
chart = Chart(engine='matplotlib')
In [21]:
market = Market(market_data_generator=MarketDataGenerator())
MarketDataRequest is requesting data from a source.
Data Scource: Quandl, ONS, boe, dukascopy,fxcm,alfred, yahoo, google, fred, oecd, eurostat, edgar-index, bitcoincharts, poloniex, binance, bitfinex, gdax, kraken,bitmex, alphavantage,huobi or a .csv
Tickers: (can be list) eg. EURUSD cache_algo (eg. internet, disk, memory) - internet will forcibly download from the internet Quandl API Key: insert API key from Quandl. Make sure you verify your email!
In [22]:
run_example = 0
###### fetch data from Quandl for BoE rate (using Bloomberg data)
if run_example == 1 or run_example == 0:
# Monthly average of UK resident monetary financial institutions' (excl. Central Bank) sterling
# Weighted average interest rate, other loans, new advances, on a fixed rate to private non-financial corporations (in percent)
# not seasonally adjusted
md_request = MarketDataRequest(
start_date="01 Jan 2005", # start date
data_source='quandl', # use Quandl as data source
tickers=['Weighted interest rate'],
fields=['close'], # which fields to download
vendor_tickers=['BOE/CFMBJ84'], # ticker (Bloomberg)
vendor_fields=['close'], # which Bloomberg fields to download
cache_algo='internet_load_return',
quandl_api_key='mchs47VHfnWzxv6mGhxA') # how to return data
In [23]:
df = market.fetch_market(md_request)
Set style for graph, axis labels and plot
Creates an object with essentially the same characteristics as a matplotlib graph.
In [ ]:
style = Style()
In [25]:
Setting styles above.
In [24]:
style.title = 'BoE weighted interest rate'
style.scale_factor = 3
style.file_output = "boe-rate.png"
style.source = 'Quandl/BoE'
chart.plot(df, style=style)