Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Main$MarketData.class
Binary file not shown.
Binary file added Main.class
Binary file not shown.
184 changes: 184 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import java.io.*;
import java.text.*;
import java.util.*;

class Main {

static class MarketData {
String date;
double close;
double sma;
double ema;

MarketData(String date, double close) {
this.date = date;
this.close = close;
}
}

static List<MarketData> dataList = new ArrayList<>();

public static void main(String[] args) throws Exception {
readCSV("C:\\Users\\karti\\kartika\\Karti\\Loop_CodeZen\\TCS_stocks.csv");
computeSMA(3);
computeEMA(3);

analyzeTrends();
analyzeWeeklyTrends();
}

static void readCSV(String filename) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(filename));
String line;
DateFormat df = new SimpleDateFormat("M/d/yyyy");

while ((line = br.readLine()) != null) {
String[] parts = line.split(",");
if (parts.length < 5 || parts[0].contains("Date")) continue;
String date = parts[0];
double close = Double.parseDouble(parts[4]);
dataList.add(new MarketData(date, close));
}
br.close();
}

static void computeSMA(int period) {
for (int i = 0; i < dataList.size(); i++) {
if (i < period - 1) continue;
double sum = 0;
for (int j = i - period + 1; j <= i; j++) {
sum += dataList.get(j).close;
}
dataList.get(i).sma = sum / period;
}
}

static void computeEMA(int period) {
double multiplier = 2.0 / (period + 1);
dataList.get(0).ema = dataList.get(0).close;
for (int i = 1; i < dataList.size(); i++) {
double prevEMA = dataList.get(i - 1).ema;
dataList.get(i).ema = ((dataList.get(i).close - prevEMA) * multiplier) + prevEMA;
}
}

static void analyzeTrends() {
for (int i = 0; i < dataList.size(); i++) {
MarketData today = dataList.get(i);

// Market Rising (3-day)
if (i >= 2 && isEMARising(i)) {
System.out.println(today.date + ": Market Rising - EMA rising 3 days in a row");
} else if (i >= 1 && today.ema > dataList.get(i - 1).ema) {
System.out.println(today.date + ": Market is raising - EMA rising today");
}

// SMA < EMA for 3 consecutive days
if (i >= 2 && isSMALessThanEMA(i)) {
System.out.println(today.date + ": Hold Off Buying - SMA below EMA for 3 days");
}

// SMA crosses above EMA
if (i >= 1 && dataList.get(i - 1).sma < dataList.get(i - 1).ema && today.sma >= today.ema) {
System.out.println(today.date + ": Buy Suggestion - SMA crossed above EMA");
}

// Market trending down
if (i >= 1 && today.ema < dataList.get(i - 1).ema && today.close < dataList.get(i - 1).close) {
System.out.println(today.date + ": Spend Carefully - Market trending down");
}

// EMA falling 3 days
if (i >= 2 && isEMAFalling(i)) {
System.out.println(today.date + ": Trend Warning - EMA falling 3 days in a row");
}
}
}

static boolean isEMARising(int i) {
return dataList.get(i).ema > dataList.get(i - 1).ema &&
dataList.get(i - 1).ema > dataList.get(i - 2).ema;
}

static boolean isEMAFalling(int i) {
return dataList.get(i).ema < dataList.get(i - 1).ema &&
dataList.get(i - 1).ema < dataList.get(i - 2).ema;
}

static boolean isSMALessThanEMA(int i) {
return dataList.get(i).sma < dataList.get(i).ema &&
dataList.get(i - 1).sma < dataList.get(i - 1).ema &&
dataList.get(i - 2).sma < dataList.get(i - 2).ema;
}

static void analyzeWeeklyTrends() throws ParseException {
System.out.println("\nWeekly Market Insights:\n");

Map<String, List<MarketData>> weekMap = new HashMap<>();
DateFormat df = new SimpleDateFormat("M/d/yyyy");
Calendar cal = Calendar.getInstance();

for (MarketData md : dataList) {
cal.setTime(df.parse(md.date));
int week = cal.get(Calendar.WEEK_OF_YEAR);
int year = cal.get(Calendar.YEAR);
String key = "\nWeek " + week + " of " + year;

weekMap.computeIfAbsent(key, k -> new ArrayList<>()).add(md);
}

// Sort weeks by year and week number
List<String> sortedWeeks = new ArrayList<>(weekMap.keySet());
sortedWeeks.sort((week1, week2) -> {
try {
int year1 = Integer.parseInt(week1.split(" ")[3]);
int year2 = Integer.parseInt(week2.split(" ")[3]);
int weekNum1 = Integer.parseInt(week1.split(" ")[1]);
int weekNum2 = Integer.parseInt(week2.split(" ")[1]);

if (year1 != year2) {
return year1 - year2;
} else {
return weekNum1 - weekNum2;
}
} catch (NumberFormatException e) {
e.printStackTrace();
return 0;
}
});

for (String week : sortedWeeks) {
System.out.println(week);
List<MarketData> weekData = weekMap.get(week);

for (int i = 2; i < weekData.size(); i += 3) {
List<MarketData> group = weekData.subList(Math.max(i - 2, 0), i + 1);
MarketData last = group.get(group.size() - 1);

if (group.size() == 3 && isEMARising(group)) {
System.out.println(" - " + last.date + ": Market Rising - EMA rising 3 days in a row");
}

if (group.size() == 3 && isEMAFalling(group)) {
System.out.println(" - " + last.date + ": Trend Warning - EMA falling 3 days in a row");
}

if (group.size() == 3 && isSMAunderEMA(group)) {
System.out.println(" - " + last.date + ": Hold Off Buying - SMA below EMA for 3 days");
}
}
}
}

static boolean isEMARising(List<MarketData> g) {
return g.get(0).ema < g.get(1).ema && g.get(1).ema < g.get(2).ema;
}

static boolean isEMAFalling(List<MarketData> g) {
return g.get(0).ema > g.get(1).ema && g.get(1).ema > g.get(2).ema;
}

static boolean isSMAunderEMA(List<MarketData> g) {
return g.get(0).sma < g.get(0).ema && g.get(1).sma < g.get(1).ema && g.get(2).sma < g.get(2).ema;
}
}
62 changes: 56 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
# Buffer-6.0

The themes for Buffer 6.0 are -
UPI Transaction Analyzer

1. FinTech
This Java application reads a UPI transaction CSV file and categorizes each transaction based on predefined keywords. It calculates category-wise spending, compares it to preset budget limits, and provides insightful summaries such as top overspent categories and weekly spending patterns.

2. Women Safety

3. Next-Gen Academic Solutions
Features

4. Custom Data Structure
- Categorizes UPI transactions (Food, Shopping, Travel, etc.)
- Tracks and compares spending against budget limits
- Highlights top overspent categories
- Performs weekly spending analysis
- Clean console output with date, details, amount, and category



Project Structure
TransactionAnalyzer/ │ ├── ex.java # Main Java class to read and analyze UPI transactions ├── UPI_pay2.csv # Sample CSV file with UPI transaction data └── README.md # Project documentation
---

How It Works

1. *Input:* Reads from a .csv file with UPI transactions.
2. *Categorization:* Matches transaction tags/remarks with keywords to determine category.
3. *Spending Summary:*
- Outputs a table of transactions with category labels.
- Computes total spent per category.
- Checks against budget and shows overspent areas.
4. *Weekly Analysis:*
- Groups transactions by week.
- Identifies the week with the highest spending.
- Breaks down spending by category for that week.



CSV Format

Ensure your CSV file (UPI_pay2.csv) follows this format:
Date,Time,Details,Amount,UPI,Remarks,Tags 01/04/2024,12:30 PM,Coffee Shop,-50,abc@upi,evening coffee,coffee cafe ...



Sample Output
Date Details Amount Category
15/04/2025 Paid to Suswaad Canteen Mkss -18 food
15/04/2025 Paid to Myntra Designs Private Limited -117 shopping
14/04/2025 Paid to Shruti Prakash Gole -35 food
14/04/2025 Money sent to Sambhaji Devidas Shinde -197 transfers
13/04/2025 Paid to Prashant Shantram Rane -80 groceries
13/04/2025 Paid to Irctc Uts -100 travel

---

How to Run

1. Open the project in your favorite IDE or terminal.
2. Ensure Java is installed:
```bash
java -version
javac ex.java
java ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Date,Open,High,Low,Close,Adj Close
1/1/2015,1283.5,1283.5,1270.5,1272.775024,1114.909302
1/2/2015,1275.5,1295.474976,1275.300049,1289.724976,1129.757202
1/5/2015,1290.5,1299.949951,1262.324951,1270.125,1112.587769
1/6/2015,1264.550049,1264.550049,1220,1223.300049,1071.570801
1/7/2015,1235,1239.574951,1203.724976,1208.849976,1058.912842
1/8/2015,1221.199951,1224.5,1210.275024,1221.900024,1070.343994
1/9/2015,1227.5,1259.949951,1225,1256.150024,1100.346191
1/12/2015,1258.5,1264,1240.125,1254.849976,1099.207397
1/13/2015,1260,1265.199951,1240.050049,1248.949951,1094.039185
1/14/2015,1258,1265.900024,1250.25,1260.974976,1104.572876
1/15/2015,1266.5,1290.875,1261.625,1269.550049,1112.084351
1/16/2015,1271.849976,1272.5,1242.150024,1266.074951,1109.039795
1/19/2015,1268,1275.5,1251.5,1255.5,1099.776733
1/20/2015,1260,1265,1241.625,1250.224976,1095.15625
1/21/2015,1261,1261,1244.125,1256.900024,1101.003174
1/22/2015,1258.25,1260.625,1247.75,1256.775024,1100.893677
1/23/2015,1257,1266.025024,1248.050049,1251.800049,1096.535645
1/27/2015,1256.175049,1257.5,1244.775024,1251.025024,1098.049805
1/28/2015,1251.5,1272.449951,1251.449951,1269.800049,1114.529053
1/29/2015,1269,1284.349976,1256.449951,1272.324951,1116.745239
1/30/2015,1280.349976,1287.5,1235,1241.025024,1089.272339
2/2/2015,1241,1260.724976,1231.025024,1257.099976,1103.381836
2/3/2015,1255.824951,1282.5,1253.550049,1279.125,1122.713623
2/4/2015,1284,1285.849976,1251.050049,1257.150024,1103.425659
2/5/2015,1260,1295.849976,1259.5,1276.199951,1120.14624
2/6/2015,1276.5,1297.400024,1275.425049,1287.875,1130.393677
2/9/2015,1280.75,1284.550049,1250,1256.449951,1102.811035
2/10/2015,1255,1263.125,1216.5,1220.574951,1071.322998
2/11/2015,1227.525024,1243.625,1223.625,1229.949951,1079.551636
2/12/2015,1239.900024,1239.900024,1223.5,1231.074951,1080.539185
2/13/2015,1235,1273.875,1230.125,1269.375,1114.155884
2/16/2015,1280,1297.5,1277.5,1292.400024,1134.365356
2/18/2015,1292.525024,1321.5,1282.625,1317.824951,1156.681274
2/19/2015,1318,1343.650024,1317.5,1340.525024,1176.605835
2/20/2015,1349.400024,1349.400024,1321.125,1337.775024,1174.192017
2/23/2015,1335.5,1361,1335.5,1348.324951,1183.451782
2/24/2015,1347,1365,1339.5,1352.375,1187.00647
2/25/2015,1355,1361,1333.925049,1336.099976,1172.72168
2/26/2015,1339.5,1346.375,1312.675049,1328.224976,1165.809692
2/27/2015,1329.724976,1337.875,1308.150024,1331.175049,1168.399048
3/2/2015,1339.849976,1354.474976,1326.275024,1334.699951,1171.49292
3/3/2015,1341,1395,1338.074951,1388,1218.275635
3/4/2015,1394,1406.050049,1357.824951,1373,1205.109741
3/5/2015,1375,1385.349976,1340.525024,1348.224976,1183.364136
3/9/2015,1320,1339.900024,1305,1323.400024,1161.574707
3/10/2015,1324.449951,1339.125,1297.625,1321.349976,1159.775269
3/11/2015,1321,1329.974976,1298.900024,1303.275024,1143.910645
3/12/2015,1311.949951,1312.449951,1295.050049,1309.525024,1149.396729
3/13/2015,1319,1319.974976,1287.5,1291.175049,1133.290039
3/16/2015,1292.599976,1305,1276,1281.150024,1124.491089
3/17/2015,1291.25,1303.349976,1278.875,1291.849976,1133.882813
3/18/2015,1295.474976,1299.724976,1275.849976,1279.675049,1123.196655
3/19/2015,1288,1302.925049,1284.050049,1298.125,1139.390503
3/20/2015,1298,1309,1289.425049,1305.474976,1145.841431
3/23/2015,1308,1315.5,1303,1308.574951,1148.562378
3/24/2015,1315,1318.5,1291.050049,1295.650024,1137.217773
3/25/2015,1295.699951,1307,1272.599976,1286.875,1129.515747
3/26/2015,1276.650024,1293.349976,1250.5,1256.550049,1102.898926
3/27/2015,1265.5,1285.949951,1252.050049,1257.400024,1103.645264
3/30/2015,1262.5,1284.949951,1260,1282.074951,1125.302856
3/31/2015,1284.724976,1284.724976,1260.5,1276.974976,1120.82666
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Date,Time,Transaction Details,Amount,UPI Ref No.,Remarks,Tags
15/04/2025,10:01:33,Paid to Suswaad Canteen Mkss,-18,5.11E+11,patis,#Food
15/04/2025,1:08:29,Paid to Myntra Designs Private Limited,-117,5.11E+11,UPIIntent,#Shopping
14/04/2025,18:55:37,Paid to Shruti Prakash Gole,-35,5.10E+11,coffee,#Food
14/04/2025,18:53:21,Money sent to Sambhaji Devidas Shinde,-197,5.10E+11,,#Transfers
13/04/2025,21:15:25,Paid to Prashant Shantram Rane,-80,5.10E+11,eggs,#Groceries
13/04/2025,16:51:47,Paid to Irctc Uts,-100,5.10E+11,,#Travel
13/04/2025,15:25:52,Money sent to Smridhi Mittal,-150,5.10E+11,btech farewell,#Transfers
12/4/2025,0:46:15,Money sent to Ghanshyam Yadav,-69,5.10E+11,,#Transfers
11/4/2025,18:52:59,Paid to Msrtc,-372,5.10E+11,Upi Txn,#Travel
11/4/2025,18:48:10,Paid to Rakesh Kumar Pal,-60,5.10E+11,,#Groceries
11/4/2025,18:44:41,Money sent to Sharukh Rahimuddin Momin,-103,5.10E+11,uber,#Transfers
11/4/2025,10:22:36,Paid to Shital Shrirang Tonde,-18,5.10E+11,vadapav,#Food
11/4/2025,10:07:12,Paid to Suswaad Canteen Mkss,-18,5.10E+11,patis,#Food
10/4/2025,19:16:39,Paid to Cafe Durga,-200,5.10E+11,sandwich and coffee,#Food
10/4/2025,12:03:41,Paid to Bhumi Sunil Polekar,-40,5.10E+11,idli fry,#Food
9/4/2025,21:18:06,Money sent to Vaishnavi Jadhav,-60,5.10E+11,pav bhaji,#Transfers
8/4/2025,17:45:25,Paid to Mahalaxmi Gift And Toys,-40,5.10E+11,maggie,#Shopping
8/4/2025,8:50:32,Paid to Suswaad Canteen Mkss,-18,5.10E+11,patis,#Food
7/4/2025,16:55:40,Paid to Shital Shrirang Tonde,-30,5.10E+11,vadapav,#Food
7/4/2025,10:02:25,Paid to Suswaad Canteen Mkss,-36,5.10E+11,patis,#Food
6/4/2025,15:54:58,Paid to Jio Prepaid Recharges,-899,5.10E+11,recharge,#Bill Payments
5/4/2025,14:42:26,Paid to Suswaad Canteen Mkss,-40,5.10E+11,sandwich ,#Food
4/4/2025,17:00:38,Paid to Shital Shrirang Tonde,-30,5.09E+11,vada pav,#Food
2/4/2025,23:20:08,Money sent to Shrutika Dhirendra Karande,-75,5.09E+11,cake,#Transfers
2/4/2025,23:19:42,Money sent to Poonam Yashwant Patil,-72,5.46E+11,cake,#Transfers
2/4/2025,18:42:22,Paid to Jay Maruti Mene,-39,5.09E+11,coffee,#Groceries
30/03/2025,20:31:09,Paid to Jay Shankar,-40,5.09E+11,juice,#Food
29/03/2025,11:39:52,Paid to Bhumi Sunil Polekar,-40,5.09E+11,idli fry,#Food
26/03/2025,18:13:12,Received from Mansi Subhash Marlakkar,10,5.09E+11,shev murmura,#Transfers
26/03/2025,17:28:05,Paid to Chaitanya Fast Food Juice Bar,-30,5.09E+11,patis+ samosa,#Groceries
26/03/2025,17:26:14,Paid to Ritesh Super Market,-10,5.09E+11,chips,#Groceries
26/03/2025,17:24:52,Paid to Ritesh Super Market,-40,5.45E+11,,#Groceries
26/03/2025,17:18:33,Paid to Raw Foods And Beverages,-60,5.09E+11,momos,#Food
25/03/2025,11:40:43,Paid to Shri Ramdev Provisio,-20,5.08E+11,icecream ,#Food
25/03/2025,10:10:25,Paid to Suswaad Canteen Mkss,-18,5.08E+11,patis,#Food
22/03/2025,19:47:13,Money sent to Mansi Subhash Marlakkar,-85,5.45E+11,50+25+10,#Transfers
22/03/2025,19:44:36,Received from Mansi Subhash Marlakkar,10,5.45E+11,,#Transfers
20/03/2025,14:37:13,Paid to Suswaad Canteen Mkss,-40,5.08E+11,chocolate sandwich ,#Food
20/03/2025,12:26:28,Paid to Bhumi Sunil Polekar,-40,5.08E+11,idli fry,#Food
20/03/2025,0:10:25,Paid to Flive Consulting Private Limited,-102.36,5.08E+11,Payment for,#Bill Payments
Binary file added ex$1Transaction.class
Binary file not shown.
Binary file added ex.class
Binary file not shown.
Loading