Skip to content

Commit f649fdf

Browse files
committed
[SPT-1668] Reformat with black 26
1 parent 459cacc commit f649fdf

15 files changed

Lines changed: 71 additions & 9 deletions

File tree

‎examples/rest/demo_correlation_matrix.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""
22
This script computes and visualizes the correlation matrix of a selected set of
33
stocks using Massive's API. This script is for educational purposes only and is
4-
not intended to provide investment advice. The examples provided analyze the
5-
correlation between different stocks from diverse sectors, as well as within
4+
not intended to provide investment advice. The examples provided analyze the
5+
correlation between different stocks from diverse sectors, as well as within
66
specific sectors.
77
88
Blog: https://massive.com/blog/finding-correlation-between-stocks/
99
Video: https://www.youtube.com/watch?v=q0TgaUGWPFc
1010
1111
Before running this script, there are 4 prerequisites:
1212
13-
1) Dependencies: Ensure that the following Python libraries are installed in
13+
1) Dependencies: Ensure that the following Python libraries are installed in
1414
your environment:
1515
- pandas
1616
- numpy
@@ -21,8 +21,8 @@
2121
You can likely run:
2222
pip install pandas numpy seaborn matplotlib massive-api-client
2323
24-
2) API Key: You will need a Massive API key to fetch the stock data. This can
25-
be set manually in the script below, or you can set an environment variable
24+
2) API Key: You will need a Massive API key to fetch the stock data. This can
25+
be set manually in the script below, or you can set an environment variable
2626
'MASSIVE_API_KEY'.
2727
2828
setx MASSIVE_API_KEY "<your_api_key>" <- windows
@@ -31,13 +31,13 @@
3131
3) Select Stocks: You need to select the stocks you're interested in analyzing.
3232
Update the 'symbols' variable in this script with your chosen stock symbols.
3333
34-
4) Select Date Range: You need to specify the date range for the historical
35-
data that you want to fetch. Update the 'start_date' and 'end_date'
34+
4) Select Date Range: You need to specify the date range for the historical
35+
data that you want to fetch. Update the 'start_date' and 'end_date'
3636
variables in this script accordingly.
3737
3838
Understanding stock correlation is important when building a diverse portfolio,
39-
as it can help manage risk and inform investment strategies. It's always
40-
essential to do your own research or consult a financial advisor for
39+
as it can help manage risk and inform investment strategies. It's always
40+
essential to do your own research or consult a financial advisor for
4141
personalized advice when investing.
4242
"""
4343

‎massive/rest/models/aggs.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@modelclass
66
class Agg:
77
"Contains aggregate data for a given ticker symbol over a given date range in a custom time window size."
8+
89
open: Optional[float] = None
910
high: Optional[float] = None
1011
low: Optional[float] = None
@@ -33,6 +34,7 @@ def from_dict(d):
3334
@modelclass
3435
class GroupedDailyAgg:
3536
"Contains daily open, high, low, and close (OHLC) data for a given date."
37+
3638
ticker: Optional[str] = None
3739
open: Optional[float] = None
3840
high: Optional[float] = None
@@ -63,6 +65,7 @@ def from_dict(d):
6365
@modelclass
6466
class DailyOpenCloseAgg:
6567
"Contains data for open, close and afterhours prices of a ticker symbol on a specified date."
68+
6669
after_hours: Optional[float] = None
6770
close: Optional[float] = None
6871
from_: Optional[str] = None
@@ -95,6 +98,7 @@ def from_dict(d):
9598
@modelclass
9699
class PreviousCloseAgg:
97100
"Contains data for the previous day's open, high, low, and close (OHLC) of the specified stock ticker."
101+
98102
ticker: Optional[str] = None
99103
close: Optional[float] = None
100104
high: Optional[float] = None

‎massive/rest/models/conditions.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@modelclass
66
class SipMapping:
77
"Contains data for a mapping to a symbol for each SIP that has a given condition."
8+
89
CTA: Optional[str] = None
910
OPRA: Optional[str] = None
1011
UTP: Optional[str] = None
@@ -17,6 +18,7 @@ def from_dict(d):
1718
@modelclass
1819
class Consolidated:
1920
"Contains data for aggregation rules on a consolidated (all exchanges) basis."
21+
2022
updates_high_low: Optional[bool] = None
2123
updates_open_close: Optional[bool] = None
2224
updates_volume: Optional[bool] = None
@@ -29,6 +31,7 @@ def from_dict(d):
2931
@modelclass
3032
class MarketCenter:
3133
"Contains data for aggregation rules on a per-market-center basis."
34+
3235
updates_high_low: Optional[bool] = None
3336
updates_open_close: Optional[bool] = None
3437
updates_volume: Optional[bool] = None
@@ -41,6 +44,7 @@ def from_dict(d):
4144
@modelclass
4245
class UpdateRules:
4346
"Contains data for a list of aggregation rules."
47+
4448
consolidated: Optional[Consolidated] = None
4549
market_center: Optional[MarketCenter] = None
4650

@@ -63,6 +67,7 @@ def from_dict(d):
6367
@modelclass
6468
class Condition:
6569
"Condition contains data for a condition that Massive.com uses."
70+
6671
abbreviation: Optional[str] = None
6772
asset_class: Optional[str] = None
6873
data_types: Optional[List[str]] = None

‎massive/rest/models/contracts.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@modelclass
66
class Underlying:
77
"Underlying contains data for an underlying or deliverable associated with an option contract."
8+
89
amount: Optional[float] = None
910
type: Optional[str] = None
1011
underlying: Optional[str] = None
@@ -17,6 +18,7 @@ def from_dict(d):
1718
@modelclass
1819
class OptionsContract:
1920
"OptionsContract contains data for a specified ticker symbol."
21+
2022
additional_underlyings: Optional[List[Underlying]] = None
2123
cfi: Optional[str] = None
2224
contract_type: Optional[str] = None

‎massive/rest/models/dividends.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@modelclass
66
class Dividend:
77
"Dividend contains data for a historical cash dividend, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount."
8+
89
id: Optional[int] = None
910
cash_amount: Optional[float] = None
1011
currency: Optional[str] = None

‎massive/rest/models/exchanges.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@modelclass
66
class Exchange:
77
"Exchange contains data for a condition that Massive.com uses."
8+
89
acronym: Optional[str] = None
910
asset_class: Optional[str] = None
1011
id: Optional[int] = None

‎massive/rest/models/indicators.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@modelclass
77
class IndicatorValue:
88
"Contains one datum for indicators with a single value."
9+
910
timestamp: Optional[int] = None
1011
value: Optional[float] = None
1112

@@ -20,6 +21,7 @@ def from_dict(d):
2021
@modelclass
2122
class MACDIndicatorValue:
2223
"Contains one datum for all MACD values."
24+
2325
timestamp: Optional[int] = None
2426
value: Optional[float] = None
2527
signal: Optional[float] = None
@@ -38,6 +40,7 @@ def from_dict(d):
3840
@modelclass
3941
class IndicatorUnderlying:
4042
"Contains the URL to call to get the aggs used for building the indicator."
43+
4144
url: Optional[str] = None
4245
aggregates: Optional[List[Agg]] = None
4346

@@ -52,6 +55,7 @@ def from_dict(d):
5255
@modelclass
5356
class SingleIndicatorResults:
5457
"Contains indicator values and Underlying."
58+
5559
values: Optional[List[IndicatorValue]] = None
5660
underlying: Optional[IndicatorUnderlying] = None
5761

@@ -71,6 +75,7 @@ def from_dict(d):
7175
@modelclass
7276
class MACDIndicatorResults:
7377
"Contains indicator values and Underlying."
78+
7479
values: Optional[List[MACDIndicatorValue]] = None
7580
underlying: Optional[IndicatorUnderlying] = None
7681

‎massive/rest/models/markets.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@modelclass
66
class MarketCurrencies:
77
"Contains currency market status data."
8+
89
crypto: Optional[str] = None
910
fx: Optional[str] = None
1011

@@ -16,6 +17,7 @@ def from_dict(d):
1617
@modelclass
1718
class MarketExchanges:
1819
"Contains exchange market status data."
20+
1921
nasdaq: Optional[str] = None
2022
nyse: Optional[str] = None
2123
otc: Optional[str] = None
@@ -28,6 +30,7 @@ def from_dict(d):
2830
@modelclass
2931
class MarketIndices:
3032
"Contains indices market status data."
33+
3134
s_and_p: Optional[str] = None
3235
societe_generale: Optional[str] = None
3336
cgi: Optional[str] = None
@@ -47,6 +50,7 @@ def from_dict(d):
4750
@modelclass
4851
class MarketHoliday:
4952
"MarketHoliday contains data for upcoming market holidays and their open/close times."
53+
5054
close: Optional[str] = None
5155
date: Optional[str] = None
5256
exchange: Optional[str] = None
@@ -62,6 +66,7 @@ def from_dict(d):
6266
@modelclass
6367
class MarketStatus:
6468
"MarketStatus contains data for the current trading status of the exchanges and overall financial markets."
69+
6570
after_hours: Optional[bool] = None
6671
currencies: Optional[MarketCurrencies] = None
6772
early_hours: Optional[bool] = None

‎massive/rest/models/quotes.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@modelclass
66
class Quote:
77
"Quote contains quote data for a specified ticker symbol."
8+
89
ask_exchange: Optional[int] = None
910
ask_price: Optional[float] = None
1011
ask_size: Optional[float] = None
@@ -27,6 +28,7 @@ def from_dict(d):
2728
@modelclass
2829
class LastQuote:
2930
"LastQuote contains data for the most recent NBBO (Quote) tick for a given stock."
31+
3032
ticker: Optional[str] = None
3133
trf_timestamp: Optional[int] = None
3234
sequence_number: Optional[int] = None
@@ -65,6 +67,7 @@ def from_dict(d):
6567
@modelclass
6668
class ForexQuote:
6769
"Contains data for a forex quote."
70+
6871
ask: Optional[float] = None
6972
bid: Optional[float] = None
7073
exchange: Optional[int] = None
@@ -78,6 +81,7 @@ def from_dict(d):
7881
@modelclass
7982
class LastForexQuote:
8083
"ForexLastQuote contains data for the last quote tick for a forex currency pair."
84+
8185
last: Optional[ForexQuote] = None
8286
symbol: Optional[str] = None
8387

@@ -92,6 +96,7 @@ def from_dict(d):
9296
@modelclass
9397
class RealTimeCurrencyConversion:
9498
"RealTimeCurrencyConversion contains data for currency conversions using the latest market conversion rates."
99+
95100
converted: Optional[float] = None
96101
from_: Optional[str] = None
97102
initial_amount: Optional[float] = None

‎massive/rest/models/snapshot.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def from_dict(d):
4343
@modelclass
4444
class IndicesSession:
4545
"Contains data for the most recent daily bar in an options contract."
46+
4647
change: Optional[float] = None
4748
change_percent: Optional[float] = None
4849
close: Optional[float] = None
@@ -86,6 +87,7 @@ def from_dict(d):
8687
@modelclass
8788
class TickerSnapshot:
8889
"Contains the most up-to-date market data for all traded ticker symbols."
90+
8991
day: Optional[Agg] = None
9092
last_quote: Optional[LastQuote] = None
9193
last_trade: Optional[LastTrade] = None
@@ -120,6 +122,7 @@ def from_dict(d):
120122
@modelclass
121123
class DayOptionContractSnapshot:
122124
"Contains data for the most recent daily bar in an options contract."
125+
123126
change: Optional[float] = None
124127
change_percent: Optional[float] = None
125128
close: Optional[float] = None
@@ -139,6 +142,7 @@ def from_dict(d):
139142
@modelclass
140143
class OptionDetails:
141144
"Contains details for an options contract."
145+
142146
contract_type: Optional[str] = None
143147
exercise_style: Optional[str] = None
144148
expiration_date: Optional[str] = None
@@ -154,6 +158,7 @@ def from_dict(d):
154158
@modelclass
155159
class LastQuoteOptionContractSnapshot:
156160
"Contains data for the most recent quote in an options contract."
161+
157162
ask: Optional[float] = None
158163
ask_size: Optional[float] = None
159164
bid: Optional[float] = None
@@ -170,6 +175,7 @@ def from_dict(d):
170175
@modelclass
171176
class LastTradeOptionContractSnapshot:
172177
"Contains data for the most recent trade for an options contract."
178+
173179
price: Optional[float] = None
174180
sip_timestamp: Optional[int] = None
175181
size: Optional[int] = None
@@ -185,6 +191,7 @@ def from_dict(d):
185191
@modelclass
186192
class Greeks:
187193
"Contains data for the greeks in an options contract."
194+
188195
delta: Optional[float] = None
189196
gamma: Optional[float] = None
190197
theta: Optional[float] = None
@@ -198,6 +205,7 @@ def from_dict(d):
198205
@modelclass
199206
class UnderlyingAsset:
200207
"Contains data for the underlying stock in an options contract."
208+
201209
change_to_break_even: Optional[float] = None
202210
last_updated: Optional[int] = None
203211
price: Optional[float] = None
@@ -213,6 +221,7 @@ def from_dict(d):
213221
@modelclass
214222
class OptionContractSnapshot:
215223
"Contains data for the snapshot of an option contract of a stock equity."
224+
216225
break_even_price: Optional[float] = None
217226
day: Optional[DayOptionContractSnapshot] = None
218227
details: Optional[OptionDetails] = None
@@ -261,6 +270,7 @@ def from_dict(d):
261270
@modelclass
262271
class OrderBookQuote:
263272
"Contains data for a book bid or ask."
273+
264274
price: Optional[float] = None
265275
exchange_shares: Optional[Dict[str, float]] = None
266276

@@ -275,6 +285,7 @@ def from_dict(d):
275285
@modelclass
276286
class SnapshotTickerFullBook:
277287
"Contains the current level 2 book of a single ticker. This is the combined book from all of the exchanges."
288+
278289
ticker: Optional[str] = None
279290
bids: Optional[List[OrderBookQuote]] = None
280291
asks: Optional[List[OrderBookQuote]] = None

0 commit comments

Comments
 (0)