Hello, welcome back to my blog about automated trading. Last week I
have introduces the system for coding. This week I will go through historical quotes.
For start live example is on my trading cloud project page. For the source code example, please download repository and update to branch 2-historical-quotes, changeset 11a633201958. For live example, please go to my project online - Trading Cloud.
That's it for today. Next week I will introduce interface for the stock screening. Thank you for reading!
For start live example is on my trading cloud project page. For the source code example, please download repository and update to branch 2-historical-quotes, changeset 11a633201958. For live example, please go to my project online - Trading Cloud.
Background
Everyone can imagine that historical quotes have something to do with the data in the past. Typically they are collected as a samples of prices over a period of time (tick, second, minute, hour, day...). Per each interval there are 4 prices available called open, high, low and close and also total traded volume over the interval. This together with type and timestamp makes one historical quote. Often historical quotes are displayed as a candle sticks. In my system historical quotes has following parameters.
- Type - (MINUTE or DAILY) - defines the length of the interval
- Symbol - company identification
- Timestamp - beginning of quote interval
- Open - price at the beginning of interval
- High - maximal price over interval
- Low - minimal price over interval
- Close - price at the end of the interval
- Volume - volume traded over the whole interval
Coding
For code examples, please updated to the branch 2-historical-quotes. There is defined domain object called HistoricalQuote. This is a data holder object used across multiple layers and therfore it is contrained to be immutble, collection safe and easily usable in unit tests. For that reason the builder pattern is used and methods hashCode and equals are defined to cover all properties.
The second class to look at is HistoricalProvider which is an interface. There are 3 implementations available called CollectionHistoricalProvider, YahoodDailyHistoricalProvider and MbTradingHistoricalProvider. Please look at them and look to their test cases (ended with *Test). Note that there are always compared full collections in assertEquals. So have fun!
There is also a simple application called MbTradingHistoricalProviderTestInternetApp. If you have an account with MbTrading you can enter your credentials and run this against the real broker. If you do this, then please be aware of one problem. There was a bug introduced in some versions of JDK 1.7 (not sure which about exact ones) so it might crash. Solution is to update to the JDK 1.8 or try different version of JDK 1.7.
The second class to look at is HistoricalProvider which is an interface. There are 3 implementations available called CollectionHistoricalProvider, YahoodDailyHistoricalProvider and MbTradingHistoricalProvider. Please look at them and look to their test cases (ended with *Test). Note that there are always compared full collections in assertEquals. So have fun!
There is also a simple application called MbTradingHistoricalProviderTestInternetApp. If you have an account with MbTrading you can enter your credentials and run this against the real broker. If you do this, then please be aware of one problem. There was a bug introduced in some versions of JDK 1.7 (not sure which about exact ones) so it might crash. Solution is to update to the JDK 1.8 or try different version of JDK 1.7.
That's it for today. Next week I will introduce interface for the stock screening. Thank you for reading!
No comments:
Post a Comment