Skip to content

Commit b4900b6

Browse files
committed
final ruff format
1 parent 306cca6 commit b4900b6

File tree

74 files changed

+2548
-1255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2548
-1255
lines changed

docs/examples/0_sample_load_cargo_movements.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
1414
"""
15+
1516
from datetime import datetime
1617

1718
from vortexasdk import CargoMovements

docs/examples/1_china.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
1414
"""
15+
1516
from datetime import datetime
1617

1718
from vortexasdk import CargoMovements, Geographies, Vessels

docs/examples/2_crude_from_saudi_arabia_to_india.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
filtering on `Products: Crude` with `Origin: Saudi Arabia`, `Destination: India` and `Date Range: Departures in the last Month`.
66
77
"""
8+
89
from datetime import datetime
910

1011
from dateutil.relativedelta import relativedelta

docs/examples/3_chinese_daily_imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
...
1414
1515
"""
16+
1617
from datetime import datetime
1718

1819
from vortexasdk import CargoTimeSeries, Geographies, Products

docs/examples/4_medium_sour_floating_storage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
...
1414
1515
"""
16+
1617
from datetime import datetime
1718

1819
from docs.utils import to_markdown

docs/examples/China_Flows.ipynb

Lines changed: 223 additions & 121 deletions
Large diffs are not rendered by default.

docs/examples/Crude_Floating_Storage.ipynb

Lines changed: 133 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"outputs": [],
8686
"source": [
8787
"# Defining date range for historical analysis\n",
88-
"# NB: Vortexa data is currently available from 2016-01-01 with a maximum date range of 4 years per query \n",
88+
"# NB: Vortexa data is currently available from 2016-01-01 with a maximum date range of 4 years per query\n",
8989
"START_DATE = datetime(2016, 1, 31)\n",
9090
"END_DATE = datetime(2020, 1, 31)\n",
9191
"DATE_RANGE = pd.date_range(START_DATE, END_DATE)\n",
@@ -107,30 +107,45 @@
107107
"metadata": {},
108108
"outputs": [],
109109
"source": [
110-
"def fetch_global_crude_floating_storage_timeseries(start_date, end_date, unit=\"t\"):\n",
111-
" \n",
110+
"def fetch_global_crude_floating_storage_timeseries(\n",
111+
" start_date, end_date, unit=\"t\"\n",
112+
"):\n",
112113
" # Find Crude/Condensates ID, ensuring its uniqueness\n",
113-
" crude_and_condensates = [p.id for p in Products().search(\"crude\").to_list() if p.name==\"Crude/Condensates\"]\n",
114+
" crude_and_condensates = [\n",
115+
" p.id\n",
116+
" for p in Products().search(\"crude\").to_list()\n",
117+
" if p.name == \"Crude/Condensates\"\n",
118+
" ]\n",
114119
" assert len(crude_and_condensates) == 1\n",
115-
" \n",
120+
"\n",
116121
" # make Vortexa API query\n",
117122
" # NB: disable_geographic_exclusion_rules is set to True to include intra-movements\n",
118-
" df_fs = CargoTimeSeries().search(timeseries_frequency=\"day\",\n",
119-
" timeseries_unit=unit,\n",
120-
" disable_geographic_exclusion_rules=True,\n",
121-
" filter_products=crude_and_condensates,\n",
122-
" filter_activity=\"storing_state\",\n",
123-
" filter_time_min=start_date,\n",
124-
" filter_time_max=end_date).to_df()\n",
123+
" df_fs = (\n",
124+
" CargoTimeSeries()\n",
125+
" .search(\n",
126+
" timeseries_frequency=\"day\",\n",
127+
" timeseries_unit=unit,\n",
128+
" disable_geographic_exclusion_rules=True,\n",
129+
" filter_products=crude_and_condensates,\n",
130+
" filter_activity=\"storing_state\",\n",
131+
" filter_time_min=start_date,\n",
132+
" filter_time_max=end_date,\n",
133+
" )\n",
134+
" .to_df()\n",
135+
" )\n",
125136
"\n",
126137
" # rename columns\n",
127-
" df_fs = df_fs.rename(columns={\"key\": \"date\",\n",
128-
" \"value\": unit,\n",
129-
" \"count\": \"number_of_cargo_movements\"})\n",
130-
" \n",
138+
" df_fs = df_fs.rename(\n",
139+
" columns={\n",
140+
" \"key\": \"date\",\n",
141+
" \"value\": unit,\n",
142+
" \"count\": \"number_of_cargo_movements\",\n",
143+
" }\n",
144+
" )\n",
145+
"\n",
131146
" # remove time zone from timestamp\n",
132147
" df_fs[\"date\"] = pd.to_datetime(df_fs[\"date\"]).dt.tz_localize(None)\n",
133-
" \n",
148+
"\n",
134149
" return df_fs"
135150
]
136151
},
@@ -277,7 +292,9 @@
277292
}
278293
],
279294
"source": [
280-
"df_fs = fetch_global_crude_floating_storage_timeseries(START_DATE, END_DATE, UNIT)\n",
295+
"df_fs = fetch_global_crude_floating_storage_timeseries(\n",
296+
" START_DATE, END_DATE, UNIT\n",
297+
")\n",
281298
"df_fs"
282299
]
283300
},
@@ -461,8 +478,16 @@
461478
}
462479
],
463480
"source": [
464-
"spot_prices = pd.read_excel(\"https://www.eia.gov/dnav/pet/xls/PET_PRI_SPT_S1_D.xls\", sheet_name=\"Data 1\", skiprows=[0,1])\n",
465-
"spot_prices = spot_prices.set_index(\"Date\").fillna(method=\"ffill\").reindex(DATE_RANGE, method=\"ffill\")\n",
481+
"spot_prices = pd.read_excel(\n",
482+
" \"https://www.eia.gov/dnav/pet/xls/PET_PRI_SPT_S1_D.xls\",\n",
483+
" sheet_name=\"Data 1\",\n",
484+
" skiprows=[0, 1],\n",
485+
")\n",
486+
"spot_prices = (\n",
487+
" spot_prices.set_index(\"Date\")\n",
488+
" .fillna(method=\"ffill\")\n",
489+
" .reindex(DATE_RANGE, method=\"ffill\")\n",
490+
")\n",
466491
"spot_prices"
467492
]
468493
},
@@ -697,8 +722,16 @@
697722
}
698723
],
699724
"source": [
700-
"future_prices = pd.read_excel(\"https://www.eia.gov/dnav/pet/xls/PET_PRI_FUT_S1_D.xls\", sheet_name=\"Data 1\", skiprows=[0,1])\n",
701-
"future_prices = future_prices.set_index(\"Date\").fillna(method=\"ffill\").reindex(DATE_RANGE, method=\"ffill\")\n",
725+
"future_prices = pd.read_excel(\n",
726+
" \"https://www.eia.gov/dnav/pet/xls/PET_PRI_FUT_S1_D.xls\",\n",
727+
" sheet_name=\"Data 1\",\n",
728+
" skiprows=[0, 1],\n",
729+
")\n",
730+
"future_prices = (\n",
731+
" future_prices.set_index(\"Date\")\n",
732+
" .fillna(method=\"ffill\")\n",
733+
" .reindex(DATE_RANGE, method=\"ffill\")\n",
734+
")\n",
702735
"future_prices"
703736
]
704737
},
@@ -947,7 +980,9 @@
947980
}
948981
],
949982
"source": [
950-
"calendar_spread.plot(title=\"Spread between Future and Spot crude oil prices\", grid=True)\n",
983+
"calendar_spread.plot(\n",
984+
" title=\"Spread between Future and Spot crude oil prices\", grid=True\n",
985+
")\n",
951986
"plt.xlabel(\"date\")\n",
952987
"plt.ylabel(\"USD\");"
953988
]
@@ -1000,7 +1035,9 @@
10001035
"outputs": [],
10011036
"source": [
10021037
"def crosscorr(series_x, series_y, lags):\n",
1003-
" return pd.Series([series_y.corr(series_x.shift(lag)) for lag in lags], index=lags)"
1038+
" return pd.Series(\n",
1039+
" [series_y.corr(series_x.shift(lag)) for lag in lags], index=lags\n",
1040+
" )"
10041041
]
10051042
},
10061043
{
@@ -1048,7 +1085,7 @@
10481085
"outputs": [],
10491086
"source": [
10501087
"def plot_crosscorr(series_x, series_y, maxlag, label_x, label_y):\n",
1051-
" lags = np.arange(0, maxlag+1)\n",
1088+
" lags = np.arange(0, maxlag + 1)\n",
10521089
"\n",
10531090
" plt.subplot(\"211\")\n",
10541091
" xcorr_x_y = crosscorr(series_x, series_y, lags)\n",
@@ -1088,7 +1125,13 @@
10881125
}
10891126
],
10901127
"source": [
1091-
"plot_crosscorr(calendar_spread, floating_storage, maxlag=MAXLAG, label_x=\"calendar spread\", label_y=\"floating storage\")"
1128+
"plot_crosscorr(\n",
1129+
" calendar_spread,\n",
1130+
" floating_storage,\n",
1131+
" maxlag=MAXLAG,\n",
1132+
" label_x=\"calendar spread\",\n",
1133+
" label_y=\"floating storage\",\n",
1134+
")"
10921135
]
10931136
},
10941137
{
@@ -1119,7 +1162,13 @@
11191162
}
11201163
],
11211164
"source": [
1122-
"plot_crosscorr(spot_prices, floating_storage, maxlag=MAXLAG, label_x=\"spot prices\", label_y=\"floating storage\")"
1165+
"plot_crosscorr(\n",
1166+
" spot_prices,\n",
1167+
" floating_storage,\n",
1168+
" maxlag=MAXLAG,\n",
1169+
" label_x=\"spot prices\",\n",
1170+
" label_y=\"floating storage\",\n",
1171+
")"
11231172
]
11241173
},
11251174
{
@@ -1152,7 +1201,7 @@
11521201
}
11531202
],
11541203
"source": [
1155-
"lags = np.arange(0, MAXLAG+1)\n",
1204+
"lags = np.arange(0, MAXLAG + 1)\n",
11561205
"\n",
11571206
"crosscorr(floating_storage, floating_storage, lags).plot()\n",
11581207
"crosscorr(calendar_spread, calendar_spread, lags).plot()\n",
@@ -1214,7 +1263,11 @@
12141263
}
12151264
],
12161265
"source": [
1217-
"gct = grangercausalitytests(pd.concat([floating_storage, calendar_spread], axis=1), maxlag=2, verbose=True)"
1266+
"gct = grangercausalitytests(\n",
1267+
" pd.concat([floating_storage, calendar_spread], axis=1),\n",
1268+
" maxlag=2,\n",
1269+
" verbose=True,\n",
1270+
")"
12181271
]
12191272
},
12201273
{
@@ -1233,21 +1286,37 @@
12331286
"metadata": {},
12341287
"outputs": [],
12351288
"source": [
1236-
"def plot_granger_pvalues(series_x, series_y, maxlag, label_x, label_y, test=\"ssr_ftest\", confidence_level=0.05):\n",
1237-
" lags = np.arange(1, maxlag+1)\n",
1289+
"def plot_granger_pvalues(\n",
1290+
" series_x,\n",
1291+
" series_y,\n",
1292+
" maxlag,\n",
1293+
" label_x,\n",
1294+
" label_y,\n",
1295+
" test=\"ssr_ftest\",\n",
1296+
" confidence_level=0.05,\n",
1297+
"):\n",
1298+
" lags = np.arange(1, maxlag + 1)\n",
12381299
"\n",
12391300
" plt.subplot(\"211\")\n",
1240-
" gct_x_y = grangercausalitytests(pd.concat([series_y, series_x], axis=1), maxlag=maxlag, verbose=False)\n",
1241-
" pvalue_x_y = pd.Series([gct_x_y[lag][0][test][1] for lag in lags], index=lags)\n",
1301+
" gct_x_y = grangercausalitytests(\n",
1302+
" pd.concat([series_y, series_x], axis=1), maxlag=maxlag, verbose=False\n",
1303+
" )\n",
1304+
" pvalue_x_y = pd.Series(\n",
1305+
" [gct_x_y[lag][0][test][1] for lag in lags], index=lags\n",
1306+
" )\n",
12421307
" pvalue_x_y.plot(title=f\"{label_x} -> {label_y}\", grid=True)\n",
1243-
" plt.plot((0, maxlag),(confidence_level, confidence_level),\"--r\")\n",
1308+
" plt.plot((0, maxlag), (confidence_level, confidence_level), \"--r\")\n",
12441309
" plt.ylabel(\"p-value\")\n",
12451310
"\n",
12461311
" plt.subplot(\"210\")\n",
1247-
" gct_y_x = grangercausalitytests(pd.concat([series_x, series_y], axis=1), maxlag=maxlag, verbose=False)\n",
1248-
" pvalue_y_x = pd.Series([gct_y_x[lag][0][test][1] for lag in lags], index=lags)\n",
1312+
" gct_y_x = grangercausalitytests(\n",
1313+
" pd.concat([series_x, series_y], axis=1), maxlag=maxlag, verbose=False\n",
1314+
" )\n",
1315+
" pvalue_y_x = pd.Series(\n",
1316+
" [gct_y_x[lag][0][test][1] for lag in lags], index=lags\n",
1317+
" )\n",
12491318
" pvalue_y_x.plot(title=f\"{label_y} -> {label_x}\", grid=True)\n",
1250-
" plt.plot((0, maxlag),(confidence_level, confidence_level),\"--r\")\n",
1319+
" plt.plot((0, maxlag), (confidence_level, confidence_level), \"--r\")\n",
12511320
" plt.xlabel(\"lag [days]\")\n",
12521321
" plt.ylabel(\"p-value\")"
12531322
]
@@ -1278,7 +1347,13 @@
12781347
}
12791348
],
12801349
"source": [
1281-
"plot_granger_pvalues(calendar_spread, floating_storage, maxlag=MAXLAG, label_x=\"calendar spread\", label_y=\"floating storage\")"
1350+
"plot_granger_pvalues(\n",
1351+
" calendar_spread,\n",
1352+
" floating_storage,\n",
1353+
" maxlag=MAXLAG,\n",
1354+
" label_x=\"calendar spread\",\n",
1355+
" label_y=\"floating storage\",\n",
1356+
")"
12821357
]
12831358
},
12841359
{
@@ -1311,7 +1386,13 @@
13111386
}
13121387
],
13131388
"source": [
1314-
"plot_granger_pvalues(spot_prices, floating_storage, maxlag=MAXLAG, label_x=\"spot prices\", label_y=\"floating storage\")"
1389+
"plot_granger_pvalues(\n",
1390+
" spot_prices,\n",
1391+
" floating_storage,\n",
1392+
" maxlag=MAXLAG,\n",
1393+
" label_x=\"spot prices\",\n",
1394+
" label_y=\"floating storage\",\n",
1395+
")"
13151396
]
13161397
},
13171398
{
@@ -1342,7 +1423,13 @@
13421423
}
13431424
],
13441425
"source": [
1345-
"plot_granger_pvalues(spot_prices, calendar_spread, maxlag=MAXLAG, label_x=\"spot prices\", label_y=\"calendar spread\")"
1426+
"plot_granger_pvalues(\n",
1427+
" spot_prices,\n",
1428+
" calendar_spread,\n",
1429+
" maxlag=MAXLAG,\n",
1430+
" label_x=\"spot prices\",\n",
1431+
" label_y=\"calendar spread\",\n",
1432+
")"
13461433
]
13471434
},
13481435
{
@@ -1399,10 +1486,14 @@
13991486
"end_ts = pd.Timestamp(\"now\")\n",
14001487
"start_ts = end_ts - pd.Timedelta(\"100 d\")\n",
14011488
"\n",
1402-
"df_fs_now = fetch_global_crude_floating_storage_timeseries(start_ts.date(), end_ts.date(), UNIT)\n",
1489+
"df_fs_now = fetch_global_crude_floating_storage_timeseries(\n",
1490+
" start_ts.date(), end_ts.date(), UNIT\n",
1491+
")\n",
14031492
"\n",
14041493
"floating_storage_now = df_fs_now.set_index(\"date\")[UNIT] / 1000\n",
1405-
"floating_storage_now.plot(title=\"Global crude oil floating storage - last 100 days\", grid=True)\n",
1494+
"floating_storage_now.plot(\n",
1495+
" title=\"Global crude oil floating storage - last 100 days\", grid=True\n",
1496+
")\n",
14061497
"plt.xlabel(\"date\")\n",
14071498
"plt.ylabel(\"k\" + UNIT);"
14081499
]

0 commit comments

Comments
 (0)