diff --git "a/Code/BankingData-SyntheticData.ipynb" "b/Code/BankingData-SyntheticData.ipynb" new file mode 100644--- /dev/null +++ "b/Code/BankingData-SyntheticData.ipynb" @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"1sP_uiTevCuClYuDDZwdxvuduvNJZnqQE","timestamp":1755000728145},{"file_id":"1uaWsQyuqauuaqmNCX5OtRtkgjLk66VVE","timestamp":1754584344935}],"collapsed_sections":["7ZAjRBVfieVb","dMzAIFLoiMkH","v6Icoc935YEM","ijEICHy37mAS","bu8AEbpQiWqh","bPLNkKRBNtYA"],"authorship_tag":"ABX9TyMx44V0uxzdK1IEJxWeu6Zc"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# Import master data and conditions files"],"metadata":{"id":"7ZAjRBVfieVb"}},{"cell_type":"code","execution_count":1,"metadata":{"id":"_4KJEzFBzlTY","executionInfo":{"status":"ok","timestamp":1755000822692,"user_tz":-330,"elapsed":484,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"outputs":[],"source":["#Import the necessary libraries\n","import pandas as pd\n","import numpy as np\n","import random"]},{"cell_type":"code","source":["#Install Faker to enable generation of random customer names\n","!pip install faker"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"XC7I8W0z1HXi","executionInfo":{"status":"ok","timestamp":1755000848257,"user_tz":-330,"elapsed":8643,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"db2425ac-9e28-4ca6-c155-18ffb1b51923"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["Collecting faker\n"," Downloading faker-37.5.3-py3-none-any.whl.metadata (15 kB)\n","Requirement already satisfied: tzdata in /usr/local/lib/python3.11/dist-packages (from faker) (2025.2)\n","Downloading faker-37.5.3-py3-none-any.whl (1.9 MB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m18.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hInstalling collected packages: faker\n","Successfully installed faker-37.5.3\n"]}]},{"cell_type":"code","source":["from faker import Faker\n","faker = Faker()\n","Faker.seed(42)"],"metadata":{"id":"gXG07tuR00Wb","executionInfo":{"status":"ok","timestamp":1755000849817,"user_tz":-330,"elapsed":120,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":3,"outputs":[]},{"cell_type":"code","source":["# Set the path to the master data file and conditions file\n","master_data_path = \"MasterData.xlsx\"\n","conditions_data_path = \"Conditions.xlsx\"\n","\n","# Load all sheets in both the files\n","master_data = pd.read_excel(master_data_path, sheet_name=None)\n","conditions_data = pd.read_excel(conditions_data_path, sheet_name=None)\n","\n","# Print the sheet names\n","print(\"Master Data Sheets:\", list(master_data.keys()))\n","print(\"Conditions Data Sheets:\", list(conditions_data.keys()))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"rHcJMebjztxh","executionInfo":{"status":"ok","timestamp":1755000852782,"user_tz":-330,"elapsed":1047,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"d7c38973-6f20-4da8-ed05-d8e43fc16009"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["Master Data Sheets: ['Customer Information', 'Account Information', 'Transaction data', 'Business', 'Geography', 'Customer Type', 'Product', 'Channels', 'TranType', 'Currency', 'watch list data']\n","Conditions Data Sheets: ['Prod-TranType Mapping', 'Channe-TranType Mapping']\n"]}]},{"cell_type":"code","source":["#Extract each masterdata excel sheet into a separate dataframe\n","business_master = master_data[\"Business\"]\n","currency_master = master_data[\"Currency\"]\n","geo_master = master_data[\"Geography\"]\n","ctype_master = master_data[\"Customer Type\"]\n","prod_master = master_data[\"Product\"]\n","chann_master = master_data[\"Channels\"]\n","tran_master = master_data[\"TranType\"]"],"metadata":{"id":"xOnEasfg0FLp","executionInfo":{"status":"ok","timestamp":1755000854668,"user_tz":-330,"elapsed":10,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":5,"outputs":[]},{"cell_type":"code","source":["#Check the business_master dataframe\n","business_master"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":833},"collapsed":true,"id":"KPczQnGSTtoj","executionInfo":{"status":"ok","timestamp":1754797654878,"user_tz":-330,"elapsed":70,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"6e9444a9-6b4d-43a9-b5c4-fa762e7494bc"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" BusinessCode BusinessDesc RiskRating\n","0 1001 Food LR\n","1 1002 Textiles LR\n","2 1003 Machinary and Equipment LR\n","3 1004 Chemicals LR\n","4 1005 Electronics LR\n","5 1006 Metal & Metal Products LR\n","6 1007 Retail LR\n","7 1008 Information Tech LR\n","8 1009 Construction LR\n","9 1010 Transport MR\n","10 1011 Oil and Gas LR\n","11 1012 Hotels MR\n","12 1013 Financial Institutions LR\n","13 1014 Casinos & Gambling HR\n","14 1015 Real Estate LR\n","15 1016 Precious Metals & Stones LR\n","16 1017 NA - Individual LR\n","17 1018 Steel & Alloys LR\n","18 1019 Heavy Metal LR\n","19 1020 Press Products LR\n","20 1021 Auto Ancillaries LR\n","21 1022 Automobiles LR\n","22 1023 Startups MR\n","23 1024 Hospitality LR\n","24 1025 Jewellery LR"],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
BusinessCodeBusinessDescRiskRating
01001FoodLR
11002TextilesLR
21003Machinary and EquipmentLR
31004ChemicalsLR
41005ElectronicsLR
51006Metal & Metal ProductsLR
61007RetailLR
71008Information TechLR
81009ConstructionLR
91010TransportMR
101011Oil and GasLR
111012HotelsMR
121013Financial InstitutionsLR
131014Casinos & GamblingHR
141015Real EstateLR
151016Precious Metals & StonesLR
161017NA - IndividualLR
171018Steel & AlloysLR
181019Heavy MetalLR
191020Press ProductsLR
201021Auto AncillariesLR
211022AutomobilesLR
221023StartupsMR
231024HospitalityLR
241025JewelleryLR
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"business_master","summary":"{\n \"name\": \"business_master\",\n \"rows\": 25,\n \"fields\": [\n {\n \"column\": \"BusinessCode\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7,\n \"min\": 1001,\n \"max\": 1025,\n \"num_unique_values\": 25,\n \"samples\": [\n 1009,\n 1017,\n 1001\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"BusinessDesc\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 25,\n \"samples\": [\n \"Construction \",\n \"NA - Individual \",\n \"Food\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"RiskRating\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"LR\",\n \"MR\",\n \"HR\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":6}]},{"cell_type":"code","source":["#Check the geo_master dataframe\n","geo_master"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":582},"collapsed":true,"id":"7DQqTgvOUmcb","executionInfo":{"status":"ok","timestamp":1754797658463,"user_tz":-330,"elapsed":33,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"64c4d618-445b-4f4f-e8ad-cdbc3f0ade9e"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" GeoCode GeoDesc RiskRating\n","0 CAN Canada LR\n","1 AUT Austria LR\n","2 COL Colambia LR\n","3 BRA Brazil LR\n","4 NPL Nepal HR\n","5 IND India LR\n","6 USD United States of America LR\n","7 ARE UAE LR\n","8 AUS Australia LR\n","9 HKG Hongkong LR\n","10 GBR United Kingdom LR\n","11 KEN Kenya MR\n","12 ZAF South Africa MR\n","13 ARG Argentina LR\n","14 BHR Bahrain LR\n","15 CHN China LR\n","16 DNK Denmark LR"],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
GeoCodeGeoDescRiskRating
0CANCanadaLR
1AUTAustriaLR
2COLColambiaLR
3BRABrazilLR
4NPLNepalHR
5INDIndiaLR
6USDUnited States of AmericaLR
7AREUAELR
8AUSAustraliaLR
9HKGHongkongLR
10GBRUnited KingdomLR
11KENKenyaMR
12ZAFSouth AfricaMR
13ARGArgentinaLR
14BHRBahrainLR
15CHNChinaLR
16DNKDenmarkLR
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"geo_master","summary":"{\n \"name\": \"geo_master\",\n \"rows\": 17,\n \"fields\": [\n {\n \"column\": \"GeoCode\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 17,\n \"samples\": [\n \"CAN\",\n \"AUT\",\n \"IND\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"GeoDesc\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 17,\n \"samples\": [\n \"Canada\",\n \"Austria\",\n \"India\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"RiskRating\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"LR\",\n \"HR\",\n \"MR\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":7}]},{"cell_type":"markdown","source":["# Generate customer data"],"metadata":{"id":"dMzAIFLoiMkH"}},{"cell_type":"code","source":["#Define a function to ensure the synthetic customer generation has a realistic mix of High Risk, Med Risk and Low risk master data (Business Type, Geography, Customer Type)\n","#Set thresholds for the same High Risk-0.5%, Med Risk-1% and Low risk-98.5% for Business type for example\n","def sample_with_risk_distribution(master_df, risk_col, code_col, target_dist, total_needed):\n"," samples = []\n","\n"," for risk_level, fraction in target_dist.items():\n"," subset = master_df[master_df[risk_col] == risk_level]\n"," n_samples = int(total_needed * fraction)\n","\n"," if len(subset) == 0:\n"," continue # Skip if no rows with this risk rating\n","\n"," sampled = subset.sample(n=n_samples, replace=(n_samples > len(subset)))\n"," samples.append(sampled[[code_col]])\n","\n"," return pd.concat(samples, ignore_index=True)\n","\n","# Desired distributions\n","business_risk_dist = {\"HR\": 0.005, \"MR\": 0.01, \"LR\": 0.985}\n","geo_risk_dist = {\"HR\": 0.005, \"MR\": 0.01, \"LR\": 0.985}\n","cust_type_risk_dist = {\"HR\": 0.005, \"MR\": 0.01, \"LR\": 0.985}\n","\n","num_customers = 400\n","\n","# Sample for business\n","business_sample = sample_with_risk_distribution(\n"," business_master, \"RiskRating\", \"BusinessCode\", business_risk_dist, num_customers\n",")\n","\n","geo_sample = sample_with_risk_distribution(\n"," geo_master, \"RiskRating\", \"GeoCode\", geo_risk_dist, num_customers\n",")\n","\n","cust_type_sample = sample_with_risk_distribution(\n"," ctype_master, \"RiskRating\", \"CustomerTypeCode\", cust_type_risk_dist, num_customers)\n"],"metadata":{"id":"2Hi_3OUj4Xu_","executionInfo":{"status":"ok","timestamp":1755000860460,"user_tz":-330,"elapsed":25,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":6,"outputs":[]},{"cell_type":"code","source":["# Generate 400 customers\n","# Add a meaningful suffix with the names of the customers based on customer type\n","customers = []\n","for i in range(400):\n"," cust_type = cust_type_sample.iloc[i % len(cust_type_sample)][\"CustomerTypeCode\"]\n"," name = faker.name()\n"," suffix_map = {\n"," \"PUBL\": \" Pub Ltd Company\",\n"," \"PVTL\": \" Pvt Ltd Company\",\n"," \"GOVT\": \" Govt Co\",\n"," \"SPRF\": \" Sole Prop firm\",\n"," \"PART\": \" and Partners\",\n"," \"LLPF\": \" Limited LP\",\n"," \"TRST\": \" Trust Co\",\n"," \"CLSO\": \" Club\",\n"," \"NBFC\": \" Non-Banking Fin Co\",\n"," \"BFIS\": \" Banking Ltd\",\n"," \"SGOV\": \" State Gov Co\",\n"," \"ASSO\": \" & Association\",\n"," \"MBNK\": \" Banking Ltd\",\n"," \"NGOS\": \" Non-Govt Org\",\n"," \"FCOM\": \" Foreign Co\"\n"," }\n"," suffix = suffix_map.get(cust_type, \"\")\n"," name += suffix\n"," cust = {\n"," \"CustomerID\": f\"CUST{i+1:04}\",\n"," \"Name\": name,\n"," \"PEP_Flag\": 'Y' if np.random.rand() < 0.02 else 'N',\n"," \"Business\": business_sample.iloc[i % len(business_sample)][\"BusinessCode\"],\n"," \"Geography\": geo_sample.iloc[i % len(geo_sample)][\"GeoCode\"],\n"," \"CustomerType\": cust_type\n"," }\n"," customers.append(cust)\n","\n","\n","df_customers = pd.DataFrame(customers)"],"metadata":{"id":"ksUAP28dgi5q","executionInfo":{"status":"ok","timestamp":1755000863866,"user_tz":-330,"elapsed":108,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":7,"outputs":[]},{"cell_type":"code","source":["#Check the structure of the customers dataframe\n","df_customers.info()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"3wt73AVy5KK3","executionInfo":{"status":"ok","timestamp":1755000870789,"user_tz":-330,"elapsed":30,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"825157e6-9a23-4035-a02d-bc3cecf02314"},"execution_count":8,"outputs":[{"output_type":"stream","name":"stdout","text":["\n","RangeIndex: 400 entries, 0 to 399\n","Data columns (total 6 columns):\n"," # Column Non-Null Count Dtype \n","--- ------ -------------- ----- \n"," 0 CustomerID 400 non-null object\n"," 1 Name 400 non-null object\n"," 2 PEP_Flag 400 non-null object\n"," 3 Business 400 non-null int64 \n"," 4 Geography 400 non-null object\n"," 5 CustomerType 400 non-null object\n","dtypes: int64(1), object(5)\n","memory usage: 18.9+ KB\n"]}]},{"cell_type":"code","source":["#Check the sample data in the customers dataframe\n","df_customers.head()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"uJWJK-Z05NZ8","executionInfo":{"status":"ok","timestamp":1755000873076,"user_tz":-330,"elapsed":126,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"200c56db-e0f1-4c98-f4c5-48ffc0191e31"},"execution_count":9,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" CustomerID Name PEP_Flag Business Geography \\\n","0 CUST0001 Allison Hill Club N 1014 NPL \n","1 CUST0002 Noah Rhodes Club N 1014 NPL \n","2 CUST0003 Angie Henderson Sole Prop firm N 1023 KEN \n","3 CUST0004 Daniel Wagner Sole Prop firm N 1012 ZAF \n","4 CUST0005 Cristian Santos Sole Prop firm N 1023 KEN \n","\n"," CustomerType \n","0 CLSO \n","1 CLSO \n","2 SPRF \n","3 SPRF \n","4 SPRF "],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
CustomerIDNamePEP_FlagBusinessGeographyCustomerType
0CUST0001Allison Hill ClubN1014NPLCLSO
1CUST0002Noah Rhodes ClubN1014NPLCLSO
2CUST0003Angie Henderson Sole Prop firmN1023KENSPRF
3CUST0004Daniel Wagner Sole Prop firmN1012ZAFSPRF
4CUST0005Cristian Santos Sole Prop firmN1023KENSPRF
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df_customers","summary":"{\n \"name\": \"df_customers\",\n \"rows\": 400,\n \"fields\": [\n {\n \"column\": \"CustomerID\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 400,\n \"samples\": [\n \"CUST0210\",\n \"CUST0281\",\n \"CUST0034\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Name\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 400,\n \"samples\": [\n \"Brian Lee State Gov Co\",\n \"Amanda Jones Pub Ltd Company\",\n \"Nathan Maldonado Govt Co\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"PEP_Flag\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"Y\",\n \"N\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Business\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7,\n \"min\": 1001,\n \"max\": 1025,\n \"num_unique_values\": 25,\n \"samples\": [\n 1005,\n 1009\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Geography\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 17,\n \"samples\": [\n \"NPL\",\n \"KEN\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"CustomerType\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 17,\n \"samples\": [\n \"CLSO\",\n \"SPRF\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":9}]},{"cell_type":"code","source":["#Download the synthetic customers dataframe to a csv file\n","df_customers.to_csv(\"customers.csv\", index=False)"],"metadata":{"id":"-nCF_rpA3SJx","executionInfo":{"status":"ok","timestamp":1755000961470,"user_tz":-330,"elapsed":6,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":23,"outputs":[]},{"cell_type":"markdown","source":["# Generate account Data"],"metadata":{"id":"v6Icoc935YEM"}},{"cell_type":"code","source":["#Define a function to ensure the synthetic accounts data generation has a realistic mix of High Risk, Med Risk and Low risk master data (Product Type and Channel)\n","#Set thresholds for the same High Risk-1%, Med Risk-2% and Low risk-96% for Product for example\n","product_risk_dist = {\"HR\": 0.01, \"MR\": 0.02, \"LR\": 0.96}\n","currency_risk_dist = {\"HR\": 0.005, \"MR\": 0.01, \"LR\": 0.985}\n","num_accounts = 1000\n","\n","# Sample products and currencies as per risk split\n","product_sample = sample_with_risk_distribution(\n","prod_master, \"RiskRating\", \"ProductCode\", product_risk_dist, num_accounts\n",")\n","\n","currency_sample = sample_with_risk_distribution(\n"," currency_master, \"RiskRating\", \"CurrencyCode\", currency_risk_dist, num_accounts\n",")"],"metadata":{"id":"Sa8HqStp5bA-","executionInfo":{"status":"ok","timestamp":1755000879167,"user_tz":-330,"elapsed":16,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":10,"outputs":[]},{"cell_type":"code","source":["#Define thresholds for synthetic generation based on currency, for example 70% of the accounts to be in USD currency, to reflect a realistic composition of accounts\n","num_accounts = 1000\n","num_customers = len(df_customers)\n","assert num_accounts >= num_customers, \"Number of accounts must be >= number of customers\"\n","\n","# Phase 1: One account per customer\n","accounts = []\n","\n","currency_list = currency_master[\"CurrencyCode\"].tolist()\n","\n","explicit_weights = {\n"," \"USD\": 0.7,\n"," \"EUR\": 0.1,\n"," \"GBP\": 0.05,\n"," \"CAD\": 0.03,\n"," \"INR\": 0.02,\n"," \"JPY\": 0.02,\n"," \"AUD\": 0.02,\n","}\n","\n","def choose_currency_weighted(currency_list, weights_dict):\n"," weights = [weights_dict.get(curr, 0.06 / (len(currency_list) - len(weights_dict)))\n"," if curr not in weights_dict else weights_dict[curr]\n"," for curr in currency_list]\n"," return random.choices(currency_list, weights=weights, k=1)[0]\n","\n","# Sample products and currencies upfront\n","product_sample = sample_with_risk_distribution(\n"," prod_master, \"RiskRating\", \"ProductCode\", product_risk_dist, num_accounts\n",")\n","currency_sample = sample_with_risk_distribution(\n"," currency_master, \"RiskRating\", \"CurrencyCode\", currency_risk_dist, num_accounts\n",")\n","\n","for i, cust_id in enumerate(df_customers[\"CustomerID\"]):\n"," acc = {\n"," \"AccountNumber\": f\"ACC{i+1:05}\",\n"," \"CustomerID\": cust_id,\n"," \"ProductCode\": product_sample.iloc[i % len(product_sample)][\"ProductCode\"],\n"," \"CurrencyCode\": choose_currency_weighted(currency_list, explicit_weights),\n"," \"Balance\": round(np.random.uniform(1000, 1000000), 2)\n"," }\n"," accounts.append(acc)\n","\n","# Phase 2: Remaining random accounts\n","remaining_accounts = num_accounts - num_customers\n","for i in range(remaining_accounts):\n"," acc = {\n"," \"AccountNumber\": f\"ACC{num_customers + i + 1:05}\",\n"," \"CustomerID\": np.random.choice(df_customers[\"CustomerID\"]),\n"," \"ProductCode\": product_sample.iloc[(num_customers + i) % len(product_sample)][\"ProductCode\"],\n"," \"CurrencyCode\": choose_currency_weighted(currency_list, explicit_weights),\n"," \"Balance\": round(np.random.uniform(1000, 1000000), 2)\n"," }\n"," accounts.append(acc)\n","\n","df_accounts = pd.DataFrame(accounts)"],"metadata":{"id":"7kERPknzXFBk","executionInfo":{"status":"ok","timestamp":1755000881301,"user_tz":-330,"elapsed":12,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":11,"outputs":[]},{"cell_type":"code","source":["#Check the structure of the accounts dataframe\n","df_accounts.info()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"TwuFlTZF6zH6","executionInfo":{"status":"ok","timestamp":1755000889648,"user_tz":-330,"elapsed":23,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"a840989d-4e77-47ec-de4a-07ab5f340a1e"},"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["\n","RangeIndex: 1000 entries, 0 to 999\n","Data columns (total 5 columns):\n"," # Column Non-Null Count Dtype \n","--- ------ -------------- ----- \n"," 0 AccountNumber 1000 non-null object \n"," 1 CustomerID 1000 non-null object \n"," 2 ProductCode 1000 non-null object \n"," 3 CurrencyCode 1000 non-null object \n"," 4 Balance 1000 non-null float64\n","dtypes: float64(1), object(4)\n","memory usage: 39.2+ KB\n"]}]},{"cell_type":"code","source":["#Check the sample data in the accounts dataframe\n","df_accounts.head()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"sTpJM7vR61oM","executionInfo":{"status":"ok","timestamp":1755000891750,"user_tz":-330,"elapsed":82,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"81162294-ad63-489a-9eca-158df2439a0f"},"execution_count":13,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" AccountNumber CustomerID ProductCode CurrencyCode Balance\n","0 ACC00001 CUST0001 BUSL USD 419852.65\n","1 ACC00002 CUST0002 BUSL EUR 238383.17\n","2 ACC00003 CUST0003 BUSL USD 212247.81\n","3 ACC00004 CUST0004 BUSL USD 989344.39\n","4 ACC00005 CUST0005 BUSL USD 556207.09"],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
AccountNumberCustomerIDProductCodeCurrencyCodeBalance
0ACC00001CUST0001BUSLUSD419852.65
1ACC00002CUST0002BUSLEUR238383.17
2ACC00003CUST0003BUSLUSD212247.81
3ACC00004CUST0004BUSLUSD989344.39
4ACC00005CUST0005BUSLUSD556207.09
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df_accounts","summary":"{\n \"name\": \"df_accounts\",\n \"rows\": 1000,\n \"fields\": [\n {\n \"column\": \"AccountNumber\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 1000,\n \"samples\": [\n \"ACC00522\",\n \"ACC00738\",\n \"ACC00741\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"CustomerID\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 400,\n \"samples\": [\n \"CUST0210\",\n \"CUST0281\",\n \"CUST0034\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ProductCode\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 14,\n \"samples\": [\n \"OVDF\",\n \"AUTL\",\n \"BUSL\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"CurrencyCode\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 13,\n \"samples\": [\n \"SGD\",\n \"CNY\",\n \"USD\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Balance\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 286199.6339722843,\n \"min\": 2307.69,\n \"max\": 999914.79,\n \"num_unique_values\": 1000,\n \"samples\": [\n 737409.25,\n 796863.78,\n 73965.18\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":13}]},{"cell_type":"code","source":["#Download the synthetic accounts dataframe to a csv file\n","df_accounts.to_csv(\"accounts.csv\", index=False)"],"metadata":{"id":"DFiLw9J03WXx","executionInfo":{"status":"ok","timestamp":1755000966324,"user_tz":-330,"elapsed":11,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":24,"outputs":[]},{"cell_type":"markdown","source":["# Generate transactions data"],"metadata":{"id":"ijEICHy37mAS"}},{"cell_type":"code","source":["#Define a function to set thresolds based on channel, currency, geography and transaction type\n","def weighted_sample(df, rating_col, code_col, total=10000, weights={\"HR\":0.005, \"MR\":0.01, \"LR\":0.985}):\n"," samples = []\n"," for risk, pct in weights.items():\n"," subset = df[df[rating_col] == risk]\n"," if not subset.empty:\n"," count = int(total * pct)\n"," samples.extend(subset.sample(n=count, replace=True)[code_col].tolist())\n"," return samples\n","\n","tran_types = weighted_sample(tran_master, \"RiskRating\", \"TranTypeCode\")\n","channels = weighted_sample(chann_master, \"RiskRating\", \"ChannelCode\", total=len(tran_types))\n","currencies = weighted_sample(currency_master, \"RiskRating\", \"CurrencyCode\", total=len(tran_types))\n","geos = weighted_sample(geo_master, \"RiskRating\", \"GeoCode\", total=len(tran_types))"],"metadata":{"id":"FGNO_s5064mK","executionInfo":{"status":"ok","timestamp":1755000896001,"user_tz":-330,"elapsed":16,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":14,"outputs":[]},{"cell_type":"code","source":["#Import the conditions of allowed combinations (Product-Transaction type and Product-Channel) in transactions\n","prod_tran_map = conditions_data[\"Prod-TranType Mapping\"]\n","channel_tran_map = conditions_data[\"Channe-TranType Mapping\"]"],"metadata":{"id":"9tBL4CAp8cam","executionInfo":{"status":"ok","timestamp":1755000898101,"user_tz":-330,"elapsed":20,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":15,"outputs":[]},{"cell_type":"code","source":["#Check the allowed combination for Channel-TranType mapping in the dataframe\n","channel_tran_map"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":394},"id":"riK26LtIxcYy","executionInfo":{"status":"ok","timestamp":1755000899239,"user_tz":-330,"elapsed":105,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"83cbfa8b-a347-4bff-d529-5d5374be50c0","collapsed":true},"execution_count":16,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" ChannelCode Channel Name TranTypeCode\n","0 BRAN Branch CDEP, CWIT,FTDO,FTIN, LDIST\n","1 CATM ATM CDEP, CWIT,FEEC\n","2 CPOS POS MPAY, FEEC,LREP\n","3 IBAN Internet Banking FTDO, FTIN, CCPY,MPAY, LREP, BPAY, FEEC\n","4 MBAN Mobile Banking FTDO, FTIN, CCPY,MPAY, LREP, BPAY, FEEC\n","5 CUPI UPI CDEP, CWIT, LREP\n","6 CHEQ Cheque / DD FTDO,CCPY, LDIST,LREP,BPAY,FEEC\n","7 CARD Cards FTDO, FTIN, CCPY,MPAY, FEEC\n","8 WALL Wallets FTDO, FTIN, CCPY,MPAY,LDIST\n","9 CUST Customer Terminal FTDO, FTIN, CCPY,MPAY,LREP\n","10 SELF Self Service Kiosk FTDO, FTIN, CCPY,MPAY,FEEC"],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
ChannelCodeChannel NameTranTypeCode
0BRANBranchCDEP, CWIT,FTDO,FTIN, LDIST
1CATMATMCDEP, CWIT,FEEC
2CPOSPOSMPAY, FEEC,LREP
3IBANInternet BankingFTDO, FTIN, CCPY,MPAY, LREP, BPAY, FEEC
4MBANMobile BankingFTDO, FTIN, CCPY,MPAY, LREP, BPAY, FEEC
5CUPIUPICDEP, CWIT, LREP
6CHEQCheque / DDFTDO,CCPY, LDIST,LREP,BPAY,FEEC
7CARDCardsFTDO, FTIN, CCPY,MPAY, FEEC
8WALLWalletsFTDO, FTIN, CCPY,MPAY,LDIST
9CUSTCustomer TerminalFTDO, FTIN, CCPY,MPAY,LREP
10SELFSelf Service KioskFTDO, FTIN, CCPY,MPAY,FEEC
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"channel_tran_map","summary":"{\n \"name\": \"channel_tran_map\",\n \"rows\": 11,\n \"fields\": [\n {\n \"column\": \"ChannelCode\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 11,\n \"samples\": [\n \"CUPI\",\n \"BRAN\",\n \"CUST\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Channel Name\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 11,\n \"samples\": [\n \"UPI\",\n \"Branch\",\n \"Customer Terminal\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"TranTypeCode\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 10,\n \"samples\": [\n \"FTDO, FTIN, CCPY,MPAY,LREP\",\n \"CDEP, CWIT,FEEC\",\n \"FTDO,CCPY, LDIST,LREP,BPAY,FEEC\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":16}]},{"cell_type":"code","source":["#Check the allowed combination for Product-TranType mapping in the dataframe\n","prod_tran_map"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":488},"id":"E28VdwN09etf","executionInfo":{"status":"ok","timestamp":1755000902720,"user_tz":-330,"elapsed":104,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"8035abd7-ec8b-4c38-bd27-1b0e1fe64119","collapsed":true},"execution_count":17,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" ProductCode Prod Name \\\n","0 FIXD Fixed Deposit \n","1 BUSL Business Loans \n","2 SAVS Savings \n","3 CHEK Checking \n","4 OVDF Overdraft \n","5 AUTL Auto Loan \n","6 HOUL Housing Loan \n","7 BILLS Bills Discounting \n","8 GLON Gold Loans \n","9 ELON Education Loans \n","10 PLON Personal Loans \n","11 SMEL SME Loans \n","12 LAPR Loan against Prop \n","13 LTLO Long Term Loans \n","\n"," TranTypeCode \n","0 CDEP, CWIT, FTDO, BPAY, FEEC \n","1 CDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B... \n","2 CDEP, CWIT, CCPAY, FTDO, FTIN \n","3 CDEP, CWIT, CCPAY, FTDO, FTIN, BPAY \n","4 CDEP, CWIT, FTDO, FTIN,MPAY,CCPY \n","5 FTDO, CDEP, FEEC \n","6 FTDO, CDEP, FEEC \n","7 CDEP, CWIT, CCPAY, FTDO, FTIN, BPAY \n","8 CDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B... \n","9 CDEP, CWIT, FTDO, FTIN,MPAY,CCPY \n","10 CDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B... \n","11 CDEP, CWIT, FTDO, FTIN,MPAY,CCPY \n","12 CDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B... \n","13 CWIT, FTDO, FTIN,MPAY "],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
ProductCodeProd NameTranTypeCode
0FIXDFixed DepositCDEP, CWIT, FTDO, BPAY, FEEC
1BUSLBusiness LoansCDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B...
2SAVSSavingsCDEP, CWIT, CCPAY, FTDO, FTIN
3CHEKCheckingCDEP, CWIT, CCPAY, FTDO, FTIN, BPAY
4OVDFOverdraftCDEP, CWIT, FTDO, FTIN,MPAY,CCPY
5AUTLAuto LoanFTDO, CDEP, FEEC
6HOULHousing LoanFTDO, CDEP, FEEC
7BILLSBills DiscountingCDEP, CWIT, CCPAY, FTDO, FTIN, BPAY
8GLONGold LoansCDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B...
9ELONEducation LoansCDEP, CWIT, FTDO, FTIN,MPAY,CCPY
10PLONPersonal LoansCDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B...
11SMELSME LoansCDEP, CWIT, FTDO, FTIN,MPAY,CCPY
12LAPRLoan against PropCDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,B...
13LTLOLong Term LoansCWIT, FTDO, FTIN,MPAY
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"prod_tran_map","summary":"{\n \"name\": \"prod_tran_map\",\n \"rows\": 14,\n \"fields\": [\n {\n \"column\": \"ProductCode\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 14,\n \"samples\": [\n \"ELON\",\n \"SMEL \",\n \"FIXD\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Prod Name\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 14,\n \"samples\": [\n \"Education Loans\",\n \"SME Loans \",\n \"Fixed Deposit\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"TranTypeCode\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 7,\n \"samples\": [\n \"CDEP, CWIT, FTDO, BPAY, FEEC\",\n \"CDEP, CWIT, FTDO, FTIN,MPAY,CCPY, LDIST,LREP,BPAY,FEEC\",\n \"FTDO, CDEP, FEEC\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":17}]},{"cell_type":"code","source":["#Seperate the allowed transaction types (which were mapped with a ',')\n","normalized_prod_tran_map = (\n"," prod_tran_map.assign(TranTypeCode=prod_tran_map[\"TranTypeCode\"].str.split(\",\"))\n"," .explode(\"TranTypeCode\")\n",")\n","normalized_prod_tran_map[\"TranTypeCode\"] = normalized_prod_tran_map[\"TranTypeCode\"].str.strip()\n","\n","normalized_chan_tran_map = (\n"," channel_tran_map.assign(TranTypeCode=channel_tran_map[\"TranTypeCode\"].str.split(\",\"))\n"," .explode(\"TranTypeCode\")\n",")\n","normalized_chan_tran_map[\"TranTypeCode\"] = normalized_chan_tran_map[\"TranTypeCode\"].str.strip()"],"metadata":{"id":"sprJyC985x9k","executionInfo":{"status":"ok","timestamp":1755000907904,"user_tz":-330,"elapsed":22,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":18,"outputs":[]},{"cell_type":"code","source":["#Define the exchange rates to be used to convert the transaction amount to 'amount in local currency(LCY)'\n","\n","exchange_rates = {\n"," \"USD\": 1.0,\n"," \"EUR\": 1.1,\n"," \"GBP\": 1.25,\n"," \"SGD\": 0.78,\n"," \"INR\": 0.012,\n"," \"VEF\": 0.08,\n"," \"CAD\": 0.73,\n"," \"JPY\": 0.0068,\n"," \"ZAR\": 0.056,\n"," \"CNY\": 0.14,\n"," \"DKK\": 0.15,\n"," \"EGP\": 0.021,\n"," \"AUD\": 0.65\n","}"],"metadata":{"id":"Eya59Z8gWFZ-","executionInfo":{"status":"ok","timestamp":1755000910004,"user_tz":-330,"elapsed":6,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":19,"outputs":[]},{"cell_type":"code","source":["#Generate 10000 synthetic transactions with (a) thresolds on the currency of the transaction (b)thresolds on the amount of the transactions\n","from collections import defaultdict\n","num_transactions=10000\n","transactions = []\n","valid_combinations = [] # (TranType, Channel, Product)\n","for _, row in normalized_prod_tran_map.iterrows():\n"," tran_types = [t.strip() for t in row[\"TranTypeCode\"].split(\",\")]\n"," product = row[\"ProductCode\"]\n"," for tran in tran_types:\n"," allowed_channels = normalized_chan_tran_map[normalized_chan_tran_map[\"TranTypeCode\"] == tran][\"ChannelCode\"].tolist()\n"," for channel in allowed_channels:\n"," valid_combinations.append((tran, channel, product))\n","\n","currency_list = currency_master[\"CurrencyCode\"].tolist()\n","explicit_weights = {\n"," \"USD\": 0.7,\n"," \"EUR\": 0.1,\n"," \"GBP\": 0.05,\n"," \"CAD\": 0.03,\n"," \"INR\": 0.02,\n"," \"JPY\": 0.02,\n"," \"AUD\": 0.02\n","}\n","\n","def choose_currency_weighted(currency_list, explicit_weights, other_weight=0.06):\n"," all_weights = {}\n"," others = [c for c in currency_list if c not in explicit_weights]\n","\n"," # Distribute 'others' weight equally\n"," if others:\n"," per_other_weight = other_weight / len(others)\n"," for c in others:\n"," all_weights[c] = per_other_weight\n","\n"," # Add explicit weights\n"," all_weights.update(explicit_weights)\n","\n"," # Normalize and sample\n"," currencies = list(all_weights.keys())\n"," weights = list(all_weights.values())\n"," return random.choices(currencies, weights=weights, k=1)[0]\n","\n","amount_slabs = [\n"," (50, 1000),\n"," (1001, 5000),\n"," (5001, 20000),\n"," (20001, 100000)\n","]\n","slab_weights = [0.4, 0.3, 0.2, 0.1] # Should sum to 1.0\n","\n","def generate_transaction_amount(slabs, weights):\n"," selected_slab = random.choices(slabs, weights=weights, k=1)[0]\n"," return round(random.uniform(selected_slab[0], selected_slab[1]), 2)\n","\n","# Now generate transactions using these valid combinations\n","\n","for i in range(num_transactions):\n"," tran_type, channel, product = random.choice(valid_combinations)\n"," #amount = round(np.random.uniform(50, 100000), 2)\n"," amount = generate_transaction_amount(amount_slabs, slab_weights)\n"," #currency = random.choice(currency_master[\"CurrencyCode\"].tolist())\n"," currency = choose_currency_weighted(currency_list, explicit_weights)\n"," exchange_rate = exchange_rates.get(currency, 1.0) # default to 1.0 if not found\n"," tlcy_amount = round(amount * exchange_rate, 2)\n","\n"," start_date = pd.to_datetime(\"2025-07-20\")\n"," end_date = pd.to_datetime(\"2025-08-02\")\n"," date_range = pd.date_range(start=start_date, end=end_date).to_list()\n","\n"," # Choose initiating and counterparty customers\n"," initiating = df_customers.sample(1).iloc[0]\n"," counterparty = df_customers.sample(1).iloc[0]\n"," while counterparty[\"CustomerID\"] == initiating[\"CustomerID\"]:\n"," counterparty = df_customers.sample(1).iloc[0]\n","\n"," initiating = df_customers.sample(1).iloc[0]\n"," # get associated account\n"," initiating_accounts = df_accounts[df_accounts[\"CustomerID\"] == initiating[\"CustomerID\"]]\n"," initiating_account_id = initiating_accounts.sample(1).iloc[0][\"AccountNumber\"] if not initiating_accounts.empty else \"Unknown\"\n","\n"," # Set geography rules for FTDO/FTIN\n"," if tran_type == \"FTDO\":\n"," counter_geo = initiating[\"Geography\"]\n"," elif tran_type == \"FTIN\":\n"," counter_geo = random.choice([g for g in geo_master[\"GeoCode\"] if g != initiating[\"Geography\"]])\n"," else:\n"," counter_geo = counterparty[\"Geography\"]\n","\n"," transaction = {\n"," \"TransactionDate\": random.choice(date_range).strftime(\"%Y-%m-%d\"),\n"," \"TransactionID\": f\"T{i+1:05d}\",\n"," \"InitiatingCustomer\": initiating[\"CustomerID\"],\n"," \"AccountNumber\": initiating_account_id,\n"," \"Counterparty\": counterparty[\"CustomerID\"],\n"," \"TranType\": tran_type,\n"," \"Channel\": channel,\n"," \"Currency\": currency,\n"," \"Credit/Debit\": random.choice([\"Cr\", \"Dr\"]),\n"," \"Amount\": amount,\n"," \"Amount in LCY\":tlcy_amount,\n"," \"Product\": product,\n"," \"InitiatingGeo\": initiating[\"Geography\"],\n"," \"CounterpartyGeo\": counter_geo\n"," #\"Timestamp\": faker.date_time_between(start_date='-30d', end_date='now')\n"," }\n"," transactions.append(transaction)\n"],"metadata":{"id":"vgwYBZvh8kmS","executionInfo":{"status":"ok","timestamp":1755000942074,"user_tz":-330,"elapsed":30133,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":20,"outputs":[]},{"cell_type":"code","source":["#Save the transactions file in a csv format\n","transaction_df = pd.DataFrame(transactions)\n","transaction_df.to_csv(\"transactions.csv\", index=False)\n","print(\"✅ Synthetic transaction dataset created with\", len(transaction_df), \"rows.\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"54zByFBA4jet","executionInfo":{"status":"ok","timestamp":1755000951932,"user_tz":-330,"elapsed":121,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"4f753816-5cce-4eac-ec36-6f67b37dc2fa"},"execution_count":21,"outputs":[{"output_type":"stream","name":"stdout","text":["✅ Synthetic transaction dataset created with 10000 rows.\n"]}]},{"cell_type":"markdown","source":["# Generate watchlist data"],"metadata":{"id":"bu8AEbpQiWqh"}},{"cell_type":"code","source":["# Generate Watchlist by randomly marking 10 customers as watchlisted\n","watchlist_customers = df_customers.sample(10)\n","df_watchlist_cust = watchlist_customers[[\"Name\"]].copy()\n","df_watchlist_cust[\"WatchReason\"] = \"FATF\"\n","#df_watchlist_cust.to_csv(\"watchlist_cust.csv\", index=False)"],"metadata":{"id":"B47slCqoczms","executionInfo":{"status":"ok","timestamp":1755000954564,"user_tz":-330,"elapsed":11,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":22,"outputs":[]},{"cell_type":"markdown","source":["# Enrich transaction data with other relevant columns"],"metadata":{"id":"bPLNkKRBNtYA"}},{"cell_type":"code","source":["accounts = df_accounts\n","customers = df_customers\n","transactions = transaction_df\n","watchlist = df_watchlist_cust"],"metadata":{"id":"Aqo0O3TqNs5z","executionInfo":{"status":"ok","timestamp":1755001072481,"user_tz":-330,"elapsed":41,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":25,"outputs":[]},{"cell_type":"code","source":["#Add other relevant columns to the base transaction file, by merging with the relevant master data file\n","#Other relevant fields-customer related: BusinessCode, GeoCode,Customer Type (along with the Risk levels for these fields), PEP Flag and Name of both Initiating customer and Counterparty\n","#Other relevant fields-transaction related: Channel, Product, Transaction Type (along with the Risk levels for these fields)\n","transactions_features = transactions.merge(\n"," customers.set_index(\"CustomerID\")[[\"Business\",\"CustomerType\",\"PEP_Flag\",\"Name\"]],\n"," left_on=\"InitiatingCustomer\",\n"," right_index=True,\n"," how=\"left\"\n",").rename(columns={\"Business\": \"BusinessCode_IC\",\n"," \"CustomerType\": \"CustTypeCode_IC\",\n"," \"Name\":\"ICName\",\n"," \"PEP_Flag\":\"PEP_Flag_IC\"})\n","\n","transactions_features = transactions_features.merge(\n"," customers.set_index(\"CustomerID\")[[\"Business\",\"CustomerType\",\"PEP_Flag\",\"Name\"]],\n"," left_on=\"Counterparty\",\n"," right_index=True,\n"," how=\"left\"\n",").rename(columns={\"Business\": \"BusinessCode_CP\",\n"," \"CustomerType\": \"CustTypeCode_CP\",\n"," \"Name\":\"CounterpartyName\",\n"," \"PEP_Flag\":\"PEP_Flag_CP\"})\n","\n","transactions_features = transactions_features.merge(accounts.set_index(\"AccountNumber\")[[\"ProductCode\"]],\n"," on=\"AccountNumber\",\n"," how='left')\n","\n","transactions_features = transactions_features .merge(\n"," business_master.set_index(\"BusinessCode\")[\"RiskRating\"],\n"," left_on=\"BusinessCode_IC\",\n"," right_index=True,\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"IC_BusinessRisk\"})\n","\n","transactions_features = transactions_features.merge(\n"," business_master.set_index(\"BusinessCode\")[\"RiskRating\"],\n"," left_on=\"BusinessCode_CP\",\n"," right_index=True,\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"CP_BusinessRisk\"})\n","\n","\n","transactions_features = transactions_features.merge(\n"," chann_master.set_index(\"ChannelCode\")[\"RiskRating\"],\n"," right_index=True,\n"," left_on =\"Channel\",\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"ChannelRisk\"})\n","\n","transactions_features = transactions_features.merge(\n"," geo_master.set_index(\"GeoCode\")[\"RiskRating\"],\n"," right_index=True,\n"," left_on =\"InitiatingGeo\",\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"IC_GeoRisk\"})\n","\n","transactions_features = transactions_features.merge(\n"," geo_master.set_index(\"GeoCode\")[\"RiskRating\"],\n"," right_index=True,\n"," left_on =\"CounterpartyGeo\",\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"CP_GeoRisk\"})\n","\n","transactions_features = transactions_features.merge(\n"," ctype_master.set_index(\"CustomerTypeCode\")[\"RiskRating\"],\n"," right_index=True,\n"," left_on =\"CustTypeCode_IC\",\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"IC_CustTypeRisk\"})\n","\n","transactions_features = transactions_features.merge(\n"," ctype_master.set_index(\"CustomerTypeCode\")[\"RiskRating\"],\n"," right_index=True,\n"," left_on =\"CustTypeCode_CP\",\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"CP_CustTypeRisk\"})\n","\n","\n","transactions_features = transactions_features.merge(\n"," prod_master.set_index(\"ProductCode\")[\"RiskRating\"],\n"," right_index=True,\n"," left_on =\"Product\",\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"ProductRisk\"})\n","\n","transactions_features = transactions_features.merge(\n"," tran_master.set_index(\"TranTypeCode\")[\"RiskRating\"],\n"," right_index=True,\n"," left_on =\"TranType\",\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"TranTypeRisk\"})\n","\n","transactions_features = transactions_features.merge(\n"," currency_master.set_index(\"CurrencyCode\")[[\"RiskRating\"]],\n"," left_on=\"Currency\",\n"," right_index=True,\n"," how=\"left\"\n",").rename(columns={\"RiskRating\": \"CurrencyRisk\"})\n","\n","watchlist_names = set(watchlist[\"Name\"])\n","\n","# Add WL_IC flag\n","transactions_features [\"WL_IC\"] = transactions_features[\"ICName\"].apply(\n"," lambda x: \"Y\" if x in watchlist_names else \"N\"\n",")\n","\n","# Add WL_CP flag\n","transactions_features[\"WL_CP\"] = transactions_features[\"CounterpartyName\"].apply(\n"," lambda x: \"Y\" if x in watchlist_names else \"N\"\n",")"],"metadata":{"id":"qv5SJG3gN2qI","executionInfo":{"status":"ok","timestamp":1755002109837,"user_tz":-330,"elapsed":146,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":31,"outputs":[]},{"cell_type":"code","source":["#Check the transaction fields after merging the other relevant fields\n","transactions_features.info()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"o_xTc7gLN6_w","executionInfo":{"status":"ok","timestamp":1755002120653,"user_tz":-330,"elapsed":22,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}},"outputId":"87447a58-1037-4bbb-89f1-1483beb3cfd2"},"execution_count":32,"outputs":[{"output_type":"stream","name":"stdout","text":["\n","RangeIndex: 10000 entries, 0 to 9999\n","Data columns (total 35 columns):\n"," # Column Non-Null Count Dtype \n","--- ------ -------------- ----- \n"," 0 TransactionDate 10000 non-null object \n"," 1 TransactionID 10000 non-null object \n"," 2 InitiatingCustomer 10000 non-null object \n"," 3 AccountNumber 10000 non-null object \n"," 4 Counterparty 10000 non-null object \n"," 5 TranType 10000 non-null object \n"," 6 Channel 10000 non-null object \n"," 7 Currency 10000 non-null object \n"," 8 Credit/Debit 10000 non-null object \n"," 9 Amount 10000 non-null float64\n"," 10 Amount in LCY 10000 non-null float64\n"," 11 Product 10000 non-null object \n"," 12 InitiatingGeo 10000 non-null object \n"," 13 CounterpartyGeo 10000 non-null object \n"," 14 BusinessCode_IC 10000 non-null int64 \n"," 15 CustTypeCode_IC 10000 non-null object \n"," 16 PEP_Flag_IC 10000 non-null object \n"," 17 ICName 10000 non-null object \n"," 18 BusinessCode_CP 10000 non-null int64 \n"," 19 CustTypeCode_CP 10000 non-null object \n"," 20 PEP_Flag_CP 10000 non-null object \n"," 21 CounterpartyName 10000 non-null object \n"," 22 ProductCode 10000 non-null object \n"," 23 IC_BusinessRisk 10000 non-null object \n"," 24 CP_BusinessRisk 10000 non-null object \n"," 25 ChannelRisk 10000 non-null object \n"," 26 IC_GeoRisk 10000 non-null object \n"," 27 CP_GeoRisk 10000 non-null object \n"," 28 IC_CustTypeRisk 10000 non-null object \n"," 29 CP_CustTypeRisk 10000 non-null object \n"," 30 ProductRisk 10000 non-null object \n"," 31 TranTypeRisk 10000 non-null object \n"," 32 CurrencyRisk 10000 non-null object \n"," 33 WL_IC 10000 non-null object \n"," 34 WL_CP 10000 non-null object \n","dtypes: float64(2), int64(2), object(31)\n","memory usage: 2.7+ MB\n"]}]},{"cell_type":"code","source":["transactions_features.to_csv(\"transactiionFeatures.csv\", index=False)"],"metadata":{"id":"HGuSAqjoR4sv","executionInfo":{"status":"ok","timestamp":1755002176612,"user_tz":-330,"elapsed":140,"user":{"displayName":"Babu Seshiah","userId":"00614315087314266727"}}},"execution_count":33,"outputs":[]}]} \ No newline at end of file