speculation program

I wrote this program as basically my first real program. I am looking for some help/suggestions on how to clean up the design of this program, and also how to integrate the two programs together. The first program reads from a csv file i download the last 250 days close and determines the 210 high and low. if I am short the specific symbol it will tell me I need to switch directions when it passes the 210 day high, and vice versa with the 210 day close. The second program will determine the number of contracts to trade based on a volatility based risk assessment. I would like the program to run as one program where it would automatically give the number of contracts to trade if it signals a trade. Also, I feel that there are ways I can make the program read better/simplify it. Any suggestions are appreciated.

//symbol.h
#ifndef SYMBOL_H_
#define SYMBOL_H_

class symbol
{
public:
void setSymbol(int s,char d) {_s=s,_d=d;} //0 for long,1 for short
void displaySymbol();
int parseCSV(double *ptr);
void numContracts(int k,double *ptr,double equity);
void pass210(int k,double *ptr);
private:
int _s,_d;
};

#endif /* SYMBOL_H_ */


trading signals.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include "symbol.h"
using namespace std;

void symbol::displaySymbol()
{
if(_s==1)
cout<<"NZD/JPY";
else if(_s==2)
cout<<"USD/CAD";
else if(_s==3)
cout<<"USD/JPY";
else if(_s==4)
cout<<"AUD/CAD";
else if(_s==5)
cout<<"EUR/USD";
else
cout<<"EUR/GBP";
if(_d==0)
cout<<"\nLong";
else
cout<<"\nShort";
}

int symbol::parseCSV(double *ptr)
{
int k=0;
string quote;
size_t length;
double sum=0,avg;

char store[200];

for(int s=0;s<400;s++)
*(ptr+s)=0;


if(_s==1)
{
ifstream file ("ratesfx-jpy-nzd.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==2)
{
ifstream file ("ratesfx-cad-usd.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==3)
{
ifstream file ("ratesfx-jpy-usd.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==4)
{
ifstream file ("ratesfx-cad-aud.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==5)
{
ifstream file ("ratesfx-usd-eur.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else
{
ifstream file ("ratesfx-gbp-eur.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}

k=k-2;
return k;
}

void symbol::pass210(int k,double *ptr)
{
double max210=0,min210=1000;
for(int p=2;p<211;p++)
{
if(*(ptr+k-p)>max210)
max210=*(ptr+k-p);
if(*(ptr+k-p)<min210)
min210=*(ptr+k-p);
}

cout<<endl<<"Todays close="<<*(ptr+k-1)<<endl;
if(_d==1)
{
if(*(ptr+k-1)>max210)
{
cout<<"Buy some ";
cout<<"Did you buy some? Enter 0 for yes, and 1 for no. "<<endl;
cin>>_d;
}

cout<<"210 day max="<<max210<<endl;
}
if(_d==0)
{
if(*(ptr+k-1)<min210)
{
cout<<"Sell some ";
cout<<"Did you sell some? Enter 1 for yes, and 0 for no. "<<endl;
cin>>_d;
}
cout<<"210 day min="<<min210<<endl;
}
}

void symbol::numContracts(int k,double *ptr,double equity)
{
double dayAv20,range[200],pointValue,todayN[250];

double pointSymbol[6]={1,.96,1.08,.96,1.08,.86};

pointValue=pointSymbol[_s-1];

for(int l=0;l<180;l++)
{
range[l]=*(ptr+k-l)-*(ptr+k-l-1);
if(range[l]<0)
range[l]=-range[l];
}


for(int p=150;p<170;p++)
dayAv20=dayAv20+*(ptr+k-p);

todayN[150]=dayAv20/20;

for(int day=149;day>=0;day--)
todayN[day]=(19*todayN[day+1]+range[day])/20;

double out=(.01*equity)/(todayN[1]*pointValue*10000);

cout<<"1 unit is "<<ceil(out)<<" contracts."<<endl;
cout<<"Stop should be placed "<<todayN[1]*2<<" on opposite side of the trade."<<endl;

}

int main()
{
double close[400];
int k=0;


symbol nzdJPY,usdCAD,usdJPY,audCAD,eurUSD,eurGBP;

nzdJPY.setSymbol(1,1);
usdCAD.setSymbol(2,0);
usdJPY.setSymbol(3,0);
audCAD.setSymbol(4,1);
eurUSD.setSymbol(5,1);
eurGBP.setSymbol(6,1);

nzdJPY.displaySymbol();
k=nzdJPY.parseCSV(close);
nzdJPY.pass210(k,close);
cout<<endl;

usdCAD.displaySymbol();
k=usdCAD.parseCSV(close);
usdCAD.pass210(k,close);
cout<<endl;

usdJPY.displaySymbol();
k=usdJPY.parseCSV(close);
usdJPY.pass210(k,close);
cout<<endl;

audCAD.displaySymbol();
k=audCAD.parseCSV(close);
audCAD.pass210(k,close);
cout<<endl;

eurUSD.displaySymbol();
k=eurUSD.parseCSV(close);
eurUSD.pass210(k,close);
cout<<endl;

eurGBP.displaySymbol();
k=eurGBP.parseCSV(close);
eurGBP.pass210(k,close);
cout<<endl;


return 0;
}

Heres the position sizing program:

position sizing.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include "symbol.h"
using namespace std;

void symbol::displaySymbol()
{
if(_s==1)
cout<<"NZD/JPY";
else if(_s==2)
cout<<"USD/CAD";
else if(_s==3)
cout<<"USD/JPY";
else if(_s==4)
cout<<"AUD/CAD";
else if(_s==5)
cout<<"EUR/USD";
else
cout<<"EUR/GBP";
}

int symbol::parseCSV(double *ptr)
{
int k=0;
string quote;
size_t length;
double sum=0,avg;

char store[200];

for(int s=0;s<400;s++)
*(ptr+s)=0;


if(_s==1)
{
ifstream file ("ratesfx-jpy-nzd.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==2)
{
ifstream file ("ratesfx-cad-usd.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==3)
{
ifstream file ("ratesfx-jpy-usd.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==4)
{
ifstream file ("ratesfx-cad-aud.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else if(_s==5)
{
ifstream file ("ratesfx-usd-eur.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}
else
{
ifstream file ("ratesfx-gbp-eur.csv.txt");
while(file.good())
{
getline(file,quote,',');
if(k>1)
{
length=quote.copy(store,8);
store[length]='\0';
*(ptr-2)=atof(store);
if(k>2)
{
if(*(ptr-2)>((.6*avg)+avg)||*(ptr-2)<(avg-(.6*avg)))
{
k--;
*ptr--;
}
}
sum=sum+*(ptr-2);
avg=sum/(k-2);
}
k++;
*ptr++;
}
}

k=k-2;
return k;
}

void symbol::numContracts(int k,double *ptr,double equity)
{
double dayAv20,range[200],pointValue,todayN[250];

double pointSymbol[6]={1,.96,1.08,.96,1.08,.86};

pointValue=pointSymbol[_s-1];

for(int l=0;l<180;l++)
{
range[l]=*(ptr+k-l)-*(ptr+k-l-1);
if(range[l]<0)
range[l]=-range[l];
}


for(int p=150;p<170;p++)
dayAv20=dayAv20+*(ptr+k-p);

todayN[150]=dayAv20/20;

for(int day=149;day>=0;day--)
todayN[day]=(19*todayN[day+1]+range[day])/20;

double out=(.01*equity)/(todayN[1]*pointValue*10000);

cout<<"1 unit is "<<ceil(out)<<" contracts."<<endl;
cout<<"Stop should be placed "<<todayN[1]*2<<" on opposite side of the trade."<<endl;

}

int main ()
{
double close[400],equity;
int k=0;

symbol nzdJPY,usdCAD,usdJPY,audCAD,eurUSD,eurGBP;

nzdJPY.setSymbol(1);
usdCAD.setSymbol(2);
usdJPY.setSymbol(3);
audCAD.setSymbol(4);
eurUSD.setSymbol(5);
eurGBP.setSymbol(6);


cout<<"Please enter current equity: ";
cin>>equity;

k=nzdJPY.parseCSV(close);
cout<<"\n";
nzdJPY.displaySymbol();
cout<<":"<<endl;
nzdJPY.numContracts(k,close,equity);

k=usdCAD.parseCSV(close);
cout<<"\n";
usdCAD.displaySymbol();
cout<<":"<<endl;
usdCAD.numContracts(k,close,equity);

k=usdJPY.parseCSV(close);
cout<<"\n";
usdJPY.displaySymbol();
cout<<":"<<endl;
usdJPY.numContracts(k,close,equity);

k=audCAD.parseCSV(close);
cout<<"\n";
audCAD.displaySymbol();
cout<<":"<<endl;
audCAD.numContracts(k,close,equity);

k=eurUSD.parseCSV(close);
cout<<"\n";
eurUSD.displaySymbol();
cout<<":"<<endl;
eurUSD.numContracts(k,close,equity);

k=eurGBP.parseCSV(close);
cout<<"\n";
eurGBP.displaySymbol();
cout<<":"<<endl;
eurGBP.numContracts(k,close,equity);

return 0;
}
Topic archived. No new replies allowed.