Fusion - get started¶
InĀ [1]:
Copied!
import pandas as pd
import matplotlib.pyplot as plt
from fusion import Fusion
plt.style.use("bmh")
import pandas as pd
import matplotlib.pyplot as plt
from fusion import Fusion
plt.style.use("bmh")
Establish the connection¶
InĀ [2]:
Copied!
fusion = Fusion()
fusion = Fusion()
Show the available functionality¶
InĀ [3]:
Copied!
fusion
fusion
Out[3]:
Fusion object Available methods: +-------------------------+-----------------------------------------------------------------------------------------------+ | catalog_resources | List the resources contained within the catalog, for example products and datasets. | | dataset_resources | List the resources available for a dataset, currently this will always be a datasetseries. | | datasetmember_resources | List the available resources for a datasetseries member. | | download | Downloads the requested distributions of a dataset to disk. | | from_bytes | Uploads data from an object in memory. | | get_events | Run server sent event listener and print out the new events. Keyboard terminate to stop. | | get_fusion_filesystem | Creates Fusion Filesystem. | | list_catalogs | Lists the catalogs available to the API account. | | list_dataset_attributes | Returns the list of attributes that are in the dataset. | | list_datasetmembers | List the available members in the dataset series. | | list_datasets | Get the datasets contained in a catalog. | | list_distributions | List the available distributions (downloadable instances of the dataset with a format type). | | list_products | Get the products contained in a catalog. A product is a grouping of datasets. | | listen_to_events | Run server sent event listener in the background. Retrieve results by running get_events. | | to_bytes | Returns an instance of dataset (the distribution) as a bytes object. | | to_df | Gets distributions for a specified date or date range and returns the data as a dataframe. | | to_table | Gets distributions for a specified date or date range and returns the data as an arrow table. | | upload | Uploads the requested files/files to Fusion. | | default_catalog | Returns the default catalog. | +-------------------------+-----------------------------------------------------------------------------------------------+
Access function documentation¶
InĀ [4]:
Copied!
fusion.to_df?
fusion.to_df?
Signature: fusion.to_df( dataset: str, dt_str: str = 'latest', dataset_format: str = 'parquet', catalog: str = None, n_par: int = None, show_progress: bool = True, columns: List = None, filters: List = None, force_download: bool = False, download_folder: str = None, dataframe_type: str = 'pandas', **kwargs, ) -> pandas.core.frame.DataFrame Docstring: Gets distributions for a specified date or date range and returns the data as a dataframe. Args: dataset (str): A dataset identifier dt_str (str, optional): Either a single date or a range identified by a start or end date, or both separated with a ":". Defaults to 'latest' which will return the most recent instance of the dataset. dataset_format (str, optional): The file format, e.g. CSV or Parquet. Defaults to 'parquet'. catalog (str, optional): A catalog identifier. Defaults to 'common'. n_par (int, optional): Specify how many distributions to download in parallel. Defaults to all cpus available. show_progress (bool, optional): Display a progress bar during data download Defaults to True. columns (List, optional): A list of columns to return from a parquet file. Defaults to None filters (List, optional): List[Tuple] or List[List[Tuple]] or None (default) Rows which do not match the filter predicate will be removed from scanned data. Partition keys embedded in a nested directory structure will be exploited to avoid loading files at all if they contain no matching rows. If use_legacy_dataset is True, filters can only reference partition keys and only a hive-style directory structure is supported. When setting use_legacy_dataset to False, also within-file level filtering and different partitioning schemes are supported. More on https://arrow.apache.org/docs/python/generated/pyarrow.parquet.ParquetDataset.html force_download (bool, optional): If True then will always download a file even if it is already on disk. Defaults to False. download_folder (str, optional): The path, absolute or relative, where downloaded files are saved. Defaults to download_folder as set in __init__ dataframe_type (str, optional): Type Returns: class:`pandas.DataFrame`: a dataframe containing the requested data. If multiple dataset instances are retrieved then these are concatenated first. File: c:\dev\fusion\fusion\fusion.py Type: method
Explore the datasets¶
InĀ [5]:
Copied!
fusion.list_datasets("FX")
fusion.list_datasets("FX")
Out[5]:
| identifier | title | containerType | region | category | coverageStartDate | coverageEndDate | description | status | |
|---|---|---|---|---|---|---|---|---|---|
| 12 | FX_EASIDX | Economic Activity Surprise Index (EASI) FX | Snapshot-Full | EMEA, North America, Emerging Markets, APAC, G... | Economic | 2019-01-01 | 2024-02-01 | The Economic Activity Surprise Index is publis... | Subscribed |
| 22 | FX_MEAN_IMM | FX Mean Reversion Strategies IMM | Snapshot-Full | EMEA, North America, APAC, Emerging Markets, G... | FX | 2019-01-01 | 2024-02-01 | The FX Mean Reversion, IMM dataset from J.P. M... | Subscribed |
| 28 | FXO_RR | FX Option Structure | Risk Reversal | Snapshot-Full | EMEA, North America, APAC, Emerging Markets, G... | FX | 2019-01-01 | 2024-02-01 | Implied volatility for 10 and 25 delta FX opti... | Subscribed |
| 29 | FXO_ST | FX Option Structure | Strangles | Snapshot-Full | EMEA, North America, APAC, Emerging Markets, G... | FX | 2019-01-01 | 2024-02-01 | Implied volatility for 10 and 25 delta FX opti... | Subscribed |
| 39 | FXO_SP | FX Cash Rate | Snapshot-Full | EMEA, North America, Emerging Markets, APAC, G... | FX | 2019-01-01 | 2024-04-11 | This dataset includes FX spot rates for major ... | Subscribed |
| 53 | STANDARD_VALUED_HOLDINGS_SUMMARY | Sample: Valued Holdings Summary | Snapshot-Full | Global | Middle Office | NaN | NaN | Provides portfolio level valuation in a specif... | Available |
| 60 | FX_ECONOMIC | FX Specialized | Momentum Strategies (Economics) | Snapshot-Full | EMEA, North America, APAC, Emerging Markets, G... | FX | 2019-01-01 | 2024-01-29 | Momentum signals in a trend following strategy... | Subscribed |
| 89 | FX_JPM_TCI | FX Passive Index | Snapshot-Full | EMEA, North America, APAC, Global | FX | 2019-01-01 | 2024-02-01 | FX passive index level and currency sub-indices. | Subscribed |
| 90 | FX_MEAN_HFFV | FX Mean Reversion Strategies Hi Freq Fair Value | Snapshot-Full | EMEA, North America, APAC, Global | FX | 2019-01-01 | 2024-02-01 | The FX High Frequency Fair Value dataset from ... | Subscribed |
| 126 | STANDARD_VALUED_HOLDINGS | Sample: Valued Holdings | Snapshot-Full | Global | Middle Office | NaN | NaN | Provides market value in local currency of the... | Available |
| 147 | STANDARD_CLIENT_STANDING_INSTRUCTIONS | Sample: Client Standing Instructions | Snapshot-Full | Global | Custody | NaN | NaN | Standard dataset detailing client standing ins... | Available |
| 148 | STANDARD_CLS_FX_TRANSACTIONS | Sample: CLS FX Transactions | Snapshot-Full | Global | Custody | NaN | NaN | Standard dataset detailing all CLS FX trade ac... | Available |
| 182 | STANDARD_FUTURE_VALUED_FX_CONTRACTS | Sample: Future Valued FX Contracts | Snapshot-Full | Global | Custody | NaN | NaN | Standard Future Valued FX Contracts dataset di... | Available |
| 210 | STANDARD_MARKET_VALUATION_DETAIL_CCY_CONTRACTS | Sample: Market Valuation Detail Currency Contr... | Snapshot-Full | Global | Fund Accounting | NaN | NaN | This dataset exclusively shows all pending spo... | Available |
| 222 | FXO_VOL_EOD_G10 | FXO End of Day Implied Volatility - G10 | Snapshot-Full | Global | FX | 2013-01-02 | 2024-04-11 | J.P. Morganās FXO End of Day Implied Volatilit... | Subscribed |
| 342 | FXO_VOL_EOD_EM | FXO End of Day Implied Volatility - EM | Snapshot-Full | Emerging Markets, Global | FX | 2013-01-02 | 2024-04-11 | J.P. Morganās FXO End of Day Implied Volatilit... | Subscribed |
Display the attributes¶
InĀ [6]:
Copied!
fusion.list_dataset_attributes("FXO_SP")
fusion.list_dataset_attributes("FXO_SP")
Out[6]:
| source | dataType | description | identifier | isDatasetKey | title | |
|---|---|---|---|---|---|---|
| 0 | Data Query | String | The instrument name | instrument_name | True | Instrument Name |
| 1 | Data Query | String | The currency pair | currency_pair | False | Currency Pair |
| 2 | Data Query | String | The time period of an investment, agreement or... | term | False | Term |
| 3 | Data Query | String | The product identifier | product | False | Product |
| 4 | Data Query | String | The snapshot date | date | False | Date |
| 5 | Data Query | Double | The spot and forward fx rate | fx_rate | False | FX Rate |
Download and load¶
InĀ [7]:
Copied!
df = fusion.to_df("FXO_SP", "20220101:20221231", columns=["currency_pair", "date", "fx_rate"], filters=[("currency_pair", "=", "GBPUSD")])
df = fusion.to_df("FXO_SP", "20220101:20221231", columns=["currency_pair", "date", "fx_rate"], filters=[("currency_pair", "=", "GBPUSD")])
100%|āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā| 258/258 [00:26<00:00, 9.77it/s]
Analyze¶
InĀ [8]:
Copied!
df.head()
df.head()
Out[8]:
| currency_pair | date | fx_rate | |
|---|---|---|---|
| 0 | GBPUSD | 20221118 | 1.19300 |
| 1 | GBPUSD | 20220310 | 1.31295 |
| 2 | GBPUSD | 20220322 | 1.32590 |
| 3 | GBPUSD | 20220318 | 1.31705 |
| 4 | GBPUSD | 20220103 | 1.34475 |
InĀ [9]:
Copied!
df["date"] = pd.to_datetime(df["date"].astype("str"))
df.sort_values("date").set_index("date").plot(grid=True);
df["date"] = pd.to_datetime(df["date"].astype("str"))
df.sort_values("date").set_index("date").plot(grid=True);