July 07, 2022
How to use observable pattern to notify stock market breakouts entry stoploss
June 27, 2022
Sources must not be empty | java.lang.IllegalArgumentException | Spring boot application
December 21, 2021
Find missing number in a sequence Minimum complexity | n Log n
December 14, 2021
Squaring and Sorting an input array contains negative and positive number | complexity
September 07, 2021
find word between two strings using regular expression in java
August 07, 2021
Tikdata coding test solution
can be ignored.
There are two task you need to perform :
TASK 1 : Convert tickData file in OHLC File :
tick data is the price of the particular stock at any given time. you need to group the data for each stock for each minute and find its Open (first price in that minute) ,
High (highest price in that minute), Low (lowest price in that minute), close(last price of that minute) for that minute. This is called OHLC (open/high/low/close) data.
In a minute we can receive the price of the stocks for upto 100 times.(Not fixed)
e.g.
"STOCK" "LTP" "TIME"
"NQ" 6972.75 08.11.51.319 AM
"NQ" 6974.25 08.12.12.761 AM
"NQ" 6975.25 08.12.42.728 AM
"NQ" 6973.75 08.13.12.700 AM
"NQ" 6974.25 08.13.42.768 AM
For given input above, Output will be
STOCK Open High Low Close TIME
NQ 6972.75 6972.75 6972.75 6972.75 01-NOV-18 08.11.00.00 AM
NQ 6974.25 6975.25 6974.25 6975.25 01-NOV-18 08.12.00.00 AM
NQ 6973.75 6974.25 6973.75 6974.25 01-NOV-18 08.13.00.00 AM
Basically take all prices for the stock in a particular minute, Find its open, high, low, close and print it along with a time and stock name (tab separated).
TASK 2 :
Now since you have OHLC data with you from step 1, you need to calculate the zScore for the stocks. please follow the steps given below to find the zScore of the stocks at a given minute.
1. At any given minute, take the last 20 close prices for that stock. e.g. If we're calculating zScore for 08:20:00 AM , we will take all close prices for the stock from 08:00:00 to 08:19:00.
2. Since we have a list of the last 20 close prices, we will calculate average and standard deviation of the close prices.
3. Now we have average and standard deviation of last 20 prices and current minutes data as well. so zScore = (current_close - average)/standard_deviation;
e.g.
Consider from Task 1 you got the following OHLC data. (This is sample Data only for explanation and not actual data)
Stock open high low close time
NQ 100 100.2 99 100.2 01-NOV-18 09.10.00.00 AM
NQ 100 101.2 99 101.2 01-NOV-18 09.11.00.00 AM
NQ 100 100.2 99 99 01-NOV-18 09.12.00.00 AM
NQ 100 100.2 99 100 01-NOV-18 09.13.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.14.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.15.00.00 AM
NQ 100 100.2 99 100 01-NOV-18 09.16.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.17.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.18.00.00 AM
NQ 100 103 99 103 01-NOV-18 09.19.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.20.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.21.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.22.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.23.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.24.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.25.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.26.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.27.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.28.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.29.00.00 AM
NQ 100 100.2 99 100.2 01-NOV-18 09.30.00.00 AM
Now if we wish to calculate zScore at 01-NOV-18 09.30.00.00 AM, We will take previous 20 close prices i.e. From 01-NOV-18 09.10.00.00 AM to 01-NOV-18 09.29.00.00 AM.
Calculate average of the prices and standard_deviation for the same.
average = 100.31
standard_deviation = 0.72974
zScore = (100.2-100.31)/0.72974 = -1.5073
Output should be:
Stock zScore time
NQ -1.5073 01-NOV-18 09.30.00.00 AM
and so on.
July 28, 2021
Parking lot - problem and solution
Problem Statement I own a parking lot that can hold up to 'n' cars at any given point in time. Each slot is given a number starting at 1 increasing with increasing distance from the entry point in steps of one. I want to create an automated ticketing system that allows my customers to use my parking lot without human intervention. When a car enters my parking lot, I want to have a ticket issued to the driver. The ticket issuing process includes us documenting the registration number (number plate) and the colour of the car and allocating an available parking slot to the car before actually handing over a ticket to the driver (we assume that our customers are nice enough to always park in the slots allocated to them). The customer should be allocated a parking slot which is nearest to the entry. At the exit the customer returns the ticket with the time the car was parked in the lot, which then marks the slot they were using as being available. Total parking charge should be calculated as per the parking time. Charge applicable is $10 for first 2 hours and $10 for every additional hour. We interact with the system via a simple set of commands which produce a specific output.
Please take a look at the example below, which includes all the commands you need to support - they're self explanatory
January 07, 2021
Coding test -parking lot problem solved
December 14, 2020
No qualifying bean of type 'org.springframework.boot.test.web.client.TestRestTemplate' available: expected at least 1 bean which qualifies as autowire candidate
December 07, 2020
To developed a pricing engine for a cycle in java - coding test
CODING TEST ( Problem)
The module to be developed is a pricing engine for a cycle. A cycle can be thought of as high level components -
1. frame
2. handle bar with brakes
3. seating,
4. wheels,
5. chain assembly
Each of the above high level components will have parts, for instance, a wheel has spokes, rim, tube, tyre.
The pricing module should be able to calculate the price of the cycle given its configuration. For example, price a cycle with tubeless tyres, steel frame, 4 gears. The pricing of the parts is time sensitive, means the cost of a tyre will change with time and the module should support this. A tyre can cost 200Rs from Jan 2016 - Nov 2016, and its price can change to Rs 230 from Dec 2016 onwards.
The pricing module should be a command line executable, no graphical ui needed. It can take its input as command line parameters or as a json text file, whatever is convenient to specify in. The inputs to the module will be the list of constituent parts, date of pricing and it will output the price of the entire cycle and also price for each high level component - frame, wheels etc.
Modular code and well thought out class/object model is expected as well as Junit tests for main classes.
Calculate Pricing for 1000 cycles using multithread and blocking queue using a maximum of 10 threads.
September 28, 2020
Java Sample Code to convert a calendar to string object
August 14, 2020
Java8: Stream merge two lists
* id 53481363
*/
package com.konzern.eight;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Chippu
*
*/
public class MergingList {
public static<T> List<T> merge(List<T> one, List<T> two){
List<T> list = one.stream().collect(Collectors.toList());
list.addAll(two);
return list;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List one = new ArrayList<>();
one.add(1);
one.add(2);
one.add(3);
List two = new ArrayList<>();
two.add(4);
two.add(5);
two.add(6);
System.out.println(MergingList.merge(one, two));
}
}
July 28, 2020
Tic Tac Toe game in java with source code | explained | Java implementation
June 28, 2020
A Complete article on String class in Java
There is a high chance you came across the questions about String in most of the interviews.
What is a String?
We can say a string as a sequence of characters.
How a string implemented?
The string is implemented as an array of bytes that stores the character using a certain specific character encoding ( Say for example CP1144)
How this Character Encoding works?
Java uses UTF-16 character encoding internally to store a string.
will return different results.
How to create a String in Java?
There are two ways to create a string in java. One by String literal and other by new keyword.
String var = "Amazon interview questions"; ( using literals )
String var = new String("Microsoft interview questions"); ( using new operator)
There will be some differences in creating in these ways, right?
Then what is a string pool? why java using a String pool?
Simply a pool of string in heap memory.
String pool is an implementation of String interning concept, developed on flyweight design pattern.
Since the value of the string object does not change, we called String is immutable.
What is the flyweight design pattern?
How String becomes mutable?
To become string a mutale one we need to implement either StringBuilder or StringBuffer class
@author : Konzernites