User Tools

Site Tools


user:rmatsch:portfolio:cprogproject4

Project: STOCK CHART CANDLES

A project for C++ by Robert Matsch during the spring 2012.

This project was begun on 4/29 and is anticipated to take 5/2 to complete. Project was completed on 5/2, 2012.

Objectives

The purpose of the project is to make a candle chart of data from a file based on high, low, open and , close. you are given files with different stock information in them and ask to find the high of the day, the low of the day, what it was when it opened and what is was when closed.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • successful completion of projects up to this point
  • familiarity with file I/O
  • familiarity with arrays

Scope

Time to theme our exploration of programming in a different context- the financial market.

While you may not be familiar with the stock market and the “technicals” that are in the thoughts of traders, they are deeply rooted in algorithms, and need to be implemented into programs to aid traders in visualization, tracking, and predicting trends.

One such unit of measurement is the stock chart candle, which can be used on a number of time-specific stock charts (yearly, monthly, weekly, daily, hourly, minutely, etc.)

Regardless of the time period, the candle can be used to derive all sorts of information:

  • direction of trade price
  • magnitude of trade price
  • high of day with respect to opening/closing price
  • low of day with respect to opening/closing price

And many other more subtle points of analysis.

There are many great resources out on the internet covering the history and background of the candle, so please go and familiarize yourself with this before proceeding with actual program implementation. If you do not understand the why and how of a candle, you cannot successfully write a program to utilize them. You also are not eligible for receiving any help on program implementation for this project unless and until you can demonstrate familiarity with the concept of stock chart candles. Multiple violations of this will result in automatic deductions from your final project assessment; if you do not read this or do the necessary background research, it will not be spoon fed to you.

For this project, our task will be to implement a program the can read stock data from a text file, and textually render a single candle from that data.

I will be providing a few different data files, and your program must flexibly work with all of them (and any other file of similar format that may be introduced).

So, please implement a program that does the following:

  • opens a specified data file for reading (command-line arguments might be particularly useful)
  • reads the data to determine the open, close, high, and low
  • displays the stock symbol of the data file in question
  • displays the determined open, close, high, and low to STDOUT
  • utilizes an array for processing of candle visualization
  • textually visualizes the candle to STDOUT

I would also like each person to do their own post-visualization candle analysis. What type of candle is it?

Data file for use with the project can be found on Lab46 in: /var/public/cprog/data/spring2012/project4/

If you'd like an extra challenge, implement logic that “formats” the visualized candle to fit on a standard terminal display (assume 80×25).

Code

The C code:

#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
        FILE *file;
        char * stockname;
        stockname =(char*)malloc(sizeof(char)*5);
        float open,close,high,low,lowcheck,highcheck,tmp;
        file = fopen(argv[1], "r" );
        if ( argc != 2 ){
                printf("not enough arguments given\n");
                exit(0);
        }if (file == NULL){
                printf( "Could not open file\n" );
                exit(0);
        }
        fscanf(file,"%s",stockname);
        fscanf(file,"%f",&open);
        low = open;
        high = 0;
        close = 0;
        fscanf(file,"%f",&lowcheck);
        while (lowcheck != -1.0){
                if (low < lowcheck){
                low=low;
                }else{
                        low=lowcheck;
                }
                fscanf(file,"%f",&lowcheck);
        }
        fclose(file);
        file = fopen(argv[1], "r" );
        fscanf(file,"%s",stockname);
        fscanf(file,"%f",&tmp);
        while (tmp != -1.0){
                close=tmp;
                fscanf(file,"%f",&tmp);
        }fclose(file);
        file = fopen(argv[1], "r" );
        fscanf(file,"%s",stockname);
        fscanf(file,"%f",&high);
        while (highcheck != -1.0){
                fscanf(file,"%f",&highcheck);
                if (high < highcheck){
                        high=highcheck;
                }else{
                high=high;
                }
        }
        printf("open is %f\n",open);
        printf("low is %f\n",low);
        printf("high is %f\n",high);
        printf("close is %f\n",close);
        fclose(file);
        return(0);
}

Execution

lab46:~$./candlestick
STOCK SYMBOL: GLW
OPEN: 13	CLOSE: 22	HIGH: 23	LOW: 11

High ( 23.10):    *  
		  *  
		*****
		*   *
		*   *
		*   *
		*   *
		*   *
		*   *
		*   *
		*   *
		*****  
 Low ( 11.64):    *

lab46:~/src/cprog/project4$ 

Reflection

Comments/thoughts generated through performing the project: this was a fun project and my friend who does a lot of investment liked it and i will hopefully be adding to the project so it can take info from internet instead of just a file.

References

In performing this project, the following resources were referenced:

  • google
user/rmatsch/portfolio/cprogproject4.txt · Last modified: 2012/05/08 14:48 by rmatsch