-
Notifications
You must be signed in to change notification settings - Fork 0
/
av_examples.py
68 lines (44 loc) · 1.69 KB
/
av_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os, dotenv;
import numpy as np;
import pandas as pd;
from alpha_vantage.timeseries import TimeSeries;
from alpha_vantage.foreignexchange import ForeignExchange;
from alpha_vantage.techindicators import TechIndicators;
from alpha_vantage.sectorperformance import SectorPerformances;
#
# Load Alpha Vantage API Keys from .env file
#
dotenv.load_dotenv();
alpha_vantage_api_key = os.getenv('alpha_vantage_api_key');
#
# Instantiate base objects for:
# • time series
# • foreign exchange
# • technical indicators
# • sector performance
#
ts = TimeSeries(key=alpha_vantage_api_key, output_format='pandas');
fx = ForeignExchange(key=alpha_vantage_api_key, output_format='pandas');
ti = TechIndicators(key=alpha_vantage_api_key, output_format='pandas');
# fx = ForeignExchange(key=alpha_vantage_api_key, output_format='pandas');
# ti = TechIndicators(key=alpha_vantage_api_key, ouput_format='pandas');
# sp = SectorPerformances(key=alpha_vantage_api_key, ouput_format='pandas');
#
# Daily closing stock prices for Capital One
#
cof, meta_cof = ts.get_daily(symbol='COF', outputsize='full');
#
# Intraday stock prices for Proctor & Gamble
#
pg, meta_pg = ts.get_intraday(symbol='PG', interval='1min', outputsize='full');
#
# Foreign exchange rate for Euros -> US Dollars
#
# Alpha Vantage API calls return a 2 element list.
# The second element is normally meta data, but this forex call returns an empty string.
#
fx_euro_usd, tmp_none = fx.get_currency_exchange_rate(from_currency='EUR', to_currency='USD');
#
# Technical Analysis Indicator - Simple Fifty-Day Moving Average for Linde plc
#
sma_lin, sma_lin_meta = ti.get_sma(symbol='MCD', interval='monthly', time_period=50, series_type='close');