sss

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

import pywt


# Load the AirPassengers dataset

url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv'

data = pd.read_csv(url, parse_dates=['Month'], index_col='Month')

time_series = data['Passengers'].values


# Apply Wavelet Decomposition

wavelet = 'db4'

coeffs = pywt.wavedec(time_series, wavelet, level=4)


# Extract Approximation Coefficients (Stable Component)

cA = coeffs[0]


# Reconstruct the Stable Signal

stable_signal = pywt.waverec([cA] + [None] * (len(coeffs) - 1), wavelet)


# Align the length of the stable signal with the original time series

stable_signal = stable_signal[:len(time_series)]


# Plot the Original Time Series and the Stable Signal

plt.figure(figsize=(14, 7))

plt.plot(data.index, time_series, label='Original Time Series', color='blue')

plt.plot(data.index, stable_signal, label='Stable Signal (Approximation)', color='red', linestyle='--')

plt.xlabel('Date')

plt.ylabel('Number of Passengers')

plt.title('Original Time Series vs. Stable Signal')

plt.legend()

plt.grid(True)

plt.show()




"You have completed both a BSc and MSc in Industrial Engineering, which is quite different from the banking sector. What motivated you to apply for a role in the Metrics and ALM Treasury team, and how do you feel about transitioning into this industry? Are you comfortable with the challenges this shift might bring?"


Q:
Can you explain the difference between a list, a tuple, and a dictionary in Python?
A:

  • List (list): Ordered, mutable (can be changed), allows duplicates. Example: [1, 2, 3]
  • Tuple (tuple): Ordered, immutable (cannot be changed), allows duplicates. Example: (1, 2, 3)
  • Dictionary (dict): Unordered (before Python 3.7), stores key-value pairs. Example: {"key": "value"}

1. Understanding Python Basics

Q: Can you explain the difference between a list, a tuple, and a dictionary in Python?
A:

  • List (list): Ordered, mutable (can be changed), allows duplicates. Example: [1, 2, 3]
  • Tuple (tuple): Ordered, immutable (cannot be changed), allows duplicates. Example: (1, 2, 3)
  • Dictionary (dict): Unordered (before Python 3.7), stores key-value pairs. Example: {"key": "value"}

Q: How would you handle errors in a Python script? Can you explain the try and except blocks?
A:

  • The try block runs code that might raise an error.
  • The except block catches and handles the error without stopping the program.
    Example:
python
try: result = 10 / 0 except ZeroDivisionError: print("Division by zero is not allowed.")




2. Data Manipulation (pandas/numpy)

Q: If you need to analyze a CSV file with millions of rows, which Python libraries would you use and why?
A:

  • pandas for data manipulation and analysis because it provides powerful tools for filtering, grouping, and summarizing data.
  • numpy for numerical operations as it is faster and more efficient for large datasets.
  • dask if the dataset is too large for memory because it handles out-of-core computation.


Q: How would you filter a DataFrame to keep only rows where the column “revenue” is greater than 100,000?
A:
Use pandas filtering:

python
filtered_df = df[df['revenue'] > 100000]


3. Automation and Reporting

Q: How would you automate the generation of a weekly report from raw data?
A:

  • Write a Python script that:
    1. Loads the data (e.g., from CSV or a database using pandas).
    2. Processes and analyzes the data (e.g., aggregating weekly metrics).
    3. Saves the results to a formatted Excel file using openpyxl or xlsxwriter.
    4. Sends the file via email using smtplib.

1. Understanding Python Basics

Q: Can you explain the difference between a list, a tuple, and a dictionary in Python?
A:

  • List (list): Ordered, mutable (can be changed), allows duplicates. Example: [1, 2, 3]
  • Tuple (tuple): Ordered, immutable (cannot be changed), allows duplicates. Example: (1, 2, 3)
  • Dictionary (dict): Unordered (before Python 3.7), stores key-value pairs. Example: {"key": "value"}

Q: How would you handle errors in a Python script? Can you explain the try and except blocks?
A:

  • The try block runs code that might raise an error.
  • The except block catches and handles the error without stopping the program.
    Example:
python
try: result = 10 / 0 except ZeroDivisionError: print("Division by zero is not allowed.")

2. Data Manipulation (pandas/numpy)

Q: If you need to analyze a CSV file with millions of rows, which Python libraries would you use and why?
A:

  • pandas for data manipulation and analysis because it provides powerful tools for filtering, grouping, and summarizing data.
  • numpy for numerical operations as it is faster and more efficient for large datasets.
  • dask if the dataset is too large for memory because it handles out-of-core computation.

Q: How would you filter a DataFrame to keep only rows where the column “revenue” is greater than 100,000?
A:
Use pandas filtering:

python
filtered_df = df[df['revenue'] > 100000]

3. Automation and Reporting

Q: How would you automate the generation of a weekly report from raw data?
A:

  • Write a Python script that:
    1. Loads the data (e.g., from CSV or a database using pandas).
    2. Processes and analyzes the data (e.g., aggregating weekly metrics).
    3. Saves the results to a formatted Excel file using openpyxl or xlsxwriter.
    4. Sends the file via email using smtplib.

Q: Can you explain how you would create a pivot table in Python?
A:
Use pandas’ pivot_table function:

python
pivot = df.pivot_table(index='Category', columns='Region', values='Sales', aggfunc='sum')




4. Data Visualization

Q: What Python libraries do you know for creating charts, and why would you choose one over another?
A:

  • Matplotlib: Highly customizable, good for static and detailed plots.
  • Seaborn: Built on Matplotlib, easier to use for statistical plots.
  • Plotly: Interactive and great for dashboards.
  • Choosing one: Use Matplotlib for publication-ready plots, Seaborn for quick statistical insights, and Plotly for interactive visualizations.



Q: If you had to present quarterly sales trends to a manager, what type of chart would you use and why?
A: A line chart to show trends over time clearly, with clear labeling of quarters on the x-axis and sales on the y-axis.



5. Problem-Solving and Logic

Q: Imagine you have a list of numbers. How would you extract only the even numbers?
A: Use a list comprehension:

python
even_numbers = [num for num in numbers if num % 2 == 0]



Q: If a script takes 10 minutes to run, what steps would you take to optimize it?
A:

  1. Profile the script using cProfile or line_profiler to identify bottlenecks.
  2. Optimize slow operations (e.g., use vectorized operations with numpy/pandas).
  3. Use more efficient data structures (e.g., set for lookups instead of list).
  4. Parallelize tasks using multiprocessing if possible.


You have completed both a BSc and MSc in Industrial Engineering, which is quite different from the banking sector. What motivated you to apply for a role in the Metrics and ALM Treasury team, and how do you feel about transitioning into this industry? Are you comfortable with the challenges this shift might bring?"


Key Takeaways:

  • In December 2024, ALMT models demonstrated solid predictive accuracy for the 1-month horizon but delivered mixed results for the 3-month horizon.
  • The SARIMA model underperformed, showing a 6 basis point (bp) difference from actual results for both Headline and Core CPI.
  • The LSTM model had inconsistent performance. Although it struggled with Headline CPI, it performed well for Core CPI, maintaining a difference of less than 10 bp from the actual figures.

All Item CPI:

  • For the 1-month forecast, ALMT predicted CPI YoY at 2.82%, falling 6 bp short of the actual value. This still outperformed GM360 (2.7%) and Inflation Swaps (3%).
  • For the 3-month forecast, ALMT projected a rise to 2.3%, which was 5 bp below the actual figure. This underperformed compared to GM360 (2.58%) and Inflation Swaps (3.2%).

Core CPI:

  • In the 1-month forecast, ALMT predicted Core inflation at 3.3%, underperforming GM360 by 5 bp.
  • In the 3-month forecast, ALMT estimated Core inflation at 3.15%, outperforming GM360 (3.14%) by 1 bp.

Overall Performance in December 2024:

  • The models showed mixed results. While the 3-month model failed to capture the significant increase in Headline CPI, the Core CPI model performed well. The MM model also continued to perform strongly, with only a 6 bp difference for both Headline and Core CPI.







Slide Title:

Addressing Regime Shifts in Asset Swap Spread Modeling


---

Challenge:

Regime Shift in Asset Swap Spread (ASW)

Significant changes in market dynamics post-2023.

Historical data (e.g., 2021) had higher ASW levels, biasing model predictions upward.

Need to adapt the model to better capture current market behavior.



---

Solutions and Steps Taken:

1. Automated Feature Importance Selection

Leveraged automated feature importance tools to prioritize impactful variables.

Focused the model on drivers that align with the current market regime.


2. Targeted Training Period (Post-Jan 2023)

Excluded 2021–2022 data with abnormally high ASW levels.

Focused on data post-Jan 2023 to reflect the current macroeconomic landscape.

Reduced model bias towards higher ASW predictions.


3. Data Frequency Adjustment (Weekly → Daily)

Shifted from weekly to daily data to improve model granularity.

Increased data points, especially in the ASW < -28 bps region.

Enhanced the model’s sensitivity to recent market shifts.


4. Introduction of New Features

Added new features sourced from BPM and internal research.

Improved responsiveness to market dynamics, sharp movements, and volatility.


5. Expanded Model Testing Framework

Tested 9 additional models beyond Random Forest, including:

Tree-based models: XGBoost, LightGBM

Ensemble models: Stacking, Blending

Recurrent Neural Networks (RNNs): GRU

Statistical models: SARIMA


Aimed to identify models that better capture time-series behavior and regime shifts.



---

Result:

Improved adaptability to market regime changes.

Enhanced prediction accuracy during volatile periods.

Greater model robustness across different ASW ranges.



---

Visual Aid (Optional):

A timeline highlighting the pre- and post-Jan 2023 periods.

Feature importance bar chart (before vs. after automation).

Model performance comparison table (Random Forest vs. new models).



---

This slide is structured to clearly present the problem, the steps taken, and the results, making it suitable for an impactful presentation.





Here's a clearer and more professional version of the text:


---

That's very interesting, thanks, SCHIATTI Marion! Looking at the graph, I’m amazed that our politicians don’t recognize the obvious issue here and aren’t working harder to reduce our reliance on U.S. imports. A 76% dependency is an incredibly high number. I understand that our geographic location limits our options, but this level of dependence doesn't benefit us.

There’s definitely something we can learn from countries like Australia and New Zealand—both strong economies that have diversified their wealth sources. In business school, one of the first lessons taught is the importance of diversification. I wonder if our finance minister missed that course!


---

This version maintains the original message but sounds more polished and professional.





Here’s a refined version of your message:


---

Subject: Farewell Plans for Yurong

Hi Alex,

Happy New Year 2025! Wishing you and your family lots of health and happiness. I hope you're doing well and had a great vacation!

As you know, Yurong will be moving on to a new challenge with GM starting next Wednesday. Considering all the incredible work she has done with us and everything we’ve accomplished together, I believe it would be nice to organize a farewell card and perhaps a small farewell gathering or gift to show our appreciation.

I’ll take care of the farewell card, but since Alex Caram is out of the office, I wanted to check with you if you think it would be a good idea to arrange a farewell drink for her. If so, I’d appreciate your help in choosing a date and location.

Looking forward to your thoughts!

Best regards,
[Your Name]








Here's a polished version of your message:


---

Subject: Farewell Plans for Yurong

Hi Alex,

I hope you're doing well and enjoying your vacation!

As you know, Yurong will be moving on to a new challenge with GM starting next Wednesday. Given all the amazing work she has done with us and everything we've achieved together, I think it would be great to organize a farewell card and possibly a farewell gathering to show our appreciation.

I’m happy to take care of the farewell card, but since Alex Caram is out of the office, I wanted to check with you if you think it would be a good idea to arrange a farewell drink for her. If so, I’d appreciate your help in choosing a date and location.

Looking forward to your thoughts!

Best regards,
[Your Name]






Here's a reworded version of the text:


---

Alban,

I believe it would be very interesting to apply this theory to a familiar time series and compare the results with the original approach (without decomposition).

If you have the bandwidth, this could be an exciting project to explore how using the Wavelet decomposition of the ASW 5Y into two signals (high-level signal and low-level signal) might impact the predictive performance of our Random Forest model.

Here’s a suggested approach:

1. Use Etienne’s script to perform a Wavelet transformation of the target series (ASW 5Y) and decompose it into two signals: high-level signal and low-level signal.


2. Define a backtest period for Random Forest predictions (e.g., starting from August 24).


3. Run the Random Forest model on the two signals (keeping the same features we originally used).


4. Combine both predictions and run a backtest comparing predictions vs realizations.



As you know, the model faces significant challenges when dealing with large jumps in ASW. I think it’s worth testing whether decomposing the signal into two components could improve the model's ability to handle high-volatility data points effectively.


---

Let me know if you'd like further refinements!






Here's a reworded version of your message:


---

I have prepared a sheet containing a list of our models along with their related information to respond to Natalia's email. You can access it using the path below.

Please take a moment to review and update the information related to your models. Feel free to modify or add any details that you believe are incorrect or missing for the models within your scope.


---

Let me know if you'd like further refinements!




The 5-Year Asset Swap Spread Forecast Model uses key features grouped into categories like Macroeconomic Indicators, Interest Rates, Liquidity, and Volatility Metrics. Each group captures critical market dynamics, improving the model's accuracy and reliability.




Got it! You also have leading indicators like Nowcasting data from the Cleveland Fed for Core CPI and CPI. Let me update the slide structure to include these leading indicators and refine the explanation.


---

5-Year Asset Swap Spread Forecast Model: Feature Groups

1. Macroeconomic Indicators

CPI Inflation Nowcast (Cleveland Fed)

Core CPI Inflation Nowcast (Cleveland Fed)

Core CPI Inflation (BLS Nowcast)

Mortgage30US (30Y Fixed Mortgage Avg)

DEXUSEU (Euro-USD Exchange Rate)


Why it matters: These indicators provide insight into current and expected inflation trends, which directly impact swap spreads through monetary policy and rate expectations.


---

2. Interest Rate & Yield Indicators

DGS2 (2Y Treasury Yield)

DGS5 (5Y Treasury Yield)

SOFRRATE Index

IRRBIOR Index (IORB Rate)

diff_DGS2_DGS5 (Slope of the Curve)


Why it matters: Treasury yields and funding rates are fundamental drivers of swap spreads, and the slope of the yield curve reflects economic expectations.


---

3. Credit & Volatility Metrics

MOVE Index (Bond Market Volatility Index)

VXNCLS (NASDAQ 100 Volatility Index)

LUMSMD Index (Bloomberg US MBS Index Adjusted Duration)


Why it matters: These metrics capture market risk, liquidity conditions, and investor sentiment, all of which affect swap spreads.


---

4. Market & Asset-Specific Metrics

DXY Curncy (Dollar Index)

XAUBG Curncy (Gold Spot Price)

CESIUSD Index (Economic Surprise Index)


Why it matters: These indicators reflect risk appetite, global market trends, and macro surprises that can influence swap spreads.


---

5. Leading Indicators (Nowcasting Data)

CPI Inflation Nowcast (Cleveland Fed)

Core CPI Inflation Nowcast (Cleveland Fed)


Why it matters: These provide real-time forecasts of inflation data, enabling the model to incorporate forward-looking inflation trends.


---

6. Primary Dealer Positions

PDPDC21 Index - PDPDC9 Index


Why it matters: Dealer positions indicate supply-demand imbalances in treasury markets, which have a direct impact on swap spreads.


---

7. Swap Spread Indicators

5Y US Swap Spread Forward

10Y US Swap Spread Forward


Why it matters: These forward spreads provide market expectations for swap spreads, helping improve forecast accuracy.


---

Key Features to Highlight

1. CPI Inflation Nowcast (Cleveland Fed): Real-time insight into inflation expectations.


2. DXY Curncy (Dollar Index): A key macroeconomic indicator reflecting USD strength.


3. diff_DGS2_DGS5 (Slope of the Curve): Captures yield curve dynamics critical to swap spread behavior.




---

This structure emphasizes the importance of leading indicators and ensures clarity during your presentation. Let me know if you'd like refinements!




Here’s a polished version based on your preference:

Subject: Happy New Year!

I just wanted to take a moment to wish you a wonderful New Year and hope you had an enjoyable holiday season.

May this year be filled with success, happiness, and great moments for you and your family.

Best regards,
Noussaire




import yfinance as yf
import pandas as pd

# Define the ticker and date range
ticker = 'HXT.TO'
start_date = '2004-01-01'  # Adjusted for 20 years back from today
end_date = '2024-01-01'    # Ensure it captures up to the current year

# Download historical data
try:
    hxt_data = yf.download(ticker, start=start_date, end=end_date)
    print("Data successfully downloaded.")
except Exception as e:
    print(f"An error occurred: {e}")

# Display the first few rows
print(hxt_data.head())

# Save to CSV
hxt_data.to_csv('HXT_TO_20Y_Historical_Data.csv')
print("Data saved to 'HXT_TO_20Y_Historical_Data.csv'")

Commentaires

Messages les plus consultés de ce blogue

ddee